Skip to content

Commit

Permalink
Polish MessageListenerContainerObservationTests
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrannen committed Aug 14, 2023
1 parent 94fe1f4 commit 3228502
Showing 1 changed file with 9 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import java.util.stream.Stream;

import io.micrometer.observation.tck.TestObservationRegistry;
import jakarta.jms.Message;
import jakarta.jms.MessageListener;
import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
import org.apache.activemq.artemis.junit.EmbeddedActiveMQExtension;
Expand All @@ -35,6 +34,8 @@
import org.springframework.jms.core.JmsTemplate;

import static io.micrometer.observation.tck.TestObservationRegistryAssert.assertThat;
import static org.junit.jupiter.api.Named.named;
import static org.junit.jupiter.params.provider.Arguments.arguments;

/**
* Observation tests for {@link AbstractMessageListenerContainer} implementations.
Expand All @@ -47,29 +48,24 @@ class MessageListenerContainerObservationTests {

TestObservationRegistry registry = TestObservationRegistry.create();

private ActiveMQConnectionFactory connectionFactory;
ActiveMQConnectionFactory connectionFactory;

@BeforeEach
void setupServer() {
server.start();
connectionFactory = new ActiveMQConnectionFactory(server.getVmURL());
}

@ParameterizedTest(name = "{index} {0}")
@ParameterizedTest(name = "[{index}] {0}")
@MethodSource("listenerContainers")
void shouldRecordJmsProcessObservations(String implementationClass, AbstractMessageListenerContainer listenerContainer) throws Exception {
void shouldRecordJmsProcessObservations(AbstractMessageListenerContainer listenerContainer) throws Exception {
JmsTemplate jmsTemplate = new JmsTemplate(connectionFactory);
jmsTemplate.convertAndSend("spring.test.observation", "message content");
CountDownLatch latch = new CountDownLatch(1);
listenerContainer.setConnectionFactory(connectionFactory);
listenerContainer.setObservationRegistry(registry);
listenerContainer.setDestinationName("spring.test.observation");
listenerContainer.setMessageListener(new MessageListener() {
@Override
public void onMessage(Message message) {
latch.countDown();
}
});
listenerContainer.setMessageListener((MessageListener) message -> latch.countDown());
listenerContainer.afterPropertiesSet();
listenerContainer.start();
latch.await(2, TimeUnit.SECONDS);
Expand All @@ -82,8 +78,8 @@ public void onMessage(Message message) {

static Stream<Arguments> listenerContainers() {
return Stream.of(
Arguments.of(DefaultMessageListenerContainer.class.getSimpleName(), new DefaultMessageListenerContainer()),
Arguments.of(SimpleMessageListenerContainer.class.getSimpleName(), new SimpleMessageListenerContainer())
arguments(named(DefaultMessageListenerContainer.class.getSimpleName(), new DefaultMessageListenerContainer())),
arguments(named(SimpleMessageListenerContainer.class.getSimpleName(), new SimpleMessageListenerContainer()))
);
}

Expand All @@ -92,4 +88,5 @@ void shutdownServer() {
connectionFactory.close();
server.stop();
}

}

0 comments on commit 3228502

Please sign in to comment.