Fix Sonar issue (#1301)
This commit is contained in:
@@ -9,6 +9,7 @@
|
|||||||
package org.eclipse.hawkbit.rabbitmq.test;
|
package org.eclipse.hawkbit.rabbitmq.test;
|
||||||
|
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
|
import java.util.Properties;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.awaitility.Awaitility;
|
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.TestConfiguration;
|
||||||
import org.eclipse.hawkbit.repository.test.util.AbstractIntegrationTest;
|
import org.eclipse.hawkbit.repository.test.util.AbstractIntegrationTest;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
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.Message;
|
||||||
import org.springframework.amqp.core.MessageProperties;
|
import org.springframework.amqp.core.MessageProperties;
|
||||||
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
||||||
@@ -38,6 +41,8 @@ import org.springframework.test.context.ContextConfiguration;
|
|||||||
@DirtiesContext(classMode = ClassMode.AFTER_CLASS)
|
@DirtiesContext(classMode = ClassMode.AFTER_CLASS)
|
||||||
public abstract class AbstractAmqpIntegrationTest extends AbstractIntegrationTest {
|
public abstract class AbstractAmqpIntegrationTest extends AbstractIntegrationTest {
|
||||||
|
|
||||||
|
private static final Logger LOG = LoggerFactory.getLogger(AbstractAmqpIntegrationTest.class);
|
||||||
|
|
||||||
private static final Duration TIMEOUT = Duration.ofSeconds(5);
|
private static final Duration TIMEOUT = Duration.ofSeconds(5);
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@@ -72,8 +77,15 @@ public abstract class AbstractAmqpIntegrationTest extends AbstractIntegrationTes
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected int getQueueMessageCount(final String queueName) {
|
protected int getQueueMessageCount(final String queueName) {
|
||||||
return Integer
|
final Properties queueProps = rabbitAdmin.getQueueProperties(queueName);
|
||||||
.parseInt(rabbitAdmin.getQueueProperties(queueName).get(RabbitAdmin.QUEUE_MESSAGE_COUNT).toString());
|
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() {
|
protected RabbitAdmin getRabbitAdmin() {
|
||||||
|
|||||||
Reference in New Issue
Block a user