Fix Sonar issue (#1301)

This commit is contained in:
Stefan Behl
2022-12-13 09:49:36 +01:00
committed by GitHub
parent 3870f11d51
commit bbe7b590c0

View File

@@ -9,6 +9,7 @@
package org.eclipse.hawkbit.rabbitmq.test;
import java.time.Duration;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
import org.awaitility.Awaitility;
@@ -17,6 +18,8 @@ import org.eclipse.hawkbit.repository.jpa.RepositoryApplicationConfiguration;
import org.eclipse.hawkbit.repository.test.TestConfiguration;
import org.eclipse.hawkbit.repository.test.util.AbstractIntegrationTest;
import org.junit.jupiter.api.BeforeEach;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
@@ -38,6 +41,8 @@ import org.springframework.test.context.ContextConfiguration;
@DirtiesContext(classMode = ClassMode.AFTER_CLASS)
public abstract class AbstractAmqpIntegrationTest extends AbstractIntegrationTest {
private static final Logger LOG = LoggerFactory.getLogger(AbstractAmqpIntegrationTest.class);
private static final Duration TIMEOUT = Duration.ofSeconds(5);
@Autowired
@@ -72,8 +77,15 @@ public abstract class AbstractAmqpIntegrationTest extends AbstractIntegrationTes
}
protected int getQueueMessageCount(final String queueName) {
return Integer
.parseInt(rabbitAdmin.getQueueProperties(queueName).get(RabbitAdmin.QUEUE_MESSAGE_COUNT).toString());
final Properties queueProps = rabbitAdmin.getQueueProperties(queueName);
if (queueProps != null && queueProps.containsKey(RabbitAdmin.QUEUE_MESSAGE_COUNT)) {
return Integer.parseInt(queueProps.get(RabbitAdmin.QUEUE_MESSAGE_COUNT).toString());
}
final int fallbackCount = 0;
LOG.warn(
"Cannot determine the queue message count for queue '{}' (queue properties {}). Returning queue message count {}.",
queueName, queueProps, fallbackCount);
return fallbackCount;
}
protected RabbitAdmin getRabbitAdmin() {