Merge pull request #14530 from GaetanoPiazzolla/JAVA-22203-fix-integration-test
JAVA-22203 | Fixed Race Condition with JMS test
This commit is contained in:
commit
746b11f454
|
@ -23,11 +23,9 @@ import org.springframework.jms.core.JmsTemplate;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
import com.baeldung.spring.jms.testing.EmbeddedActiveMqManualTest.TestConfiguration;
|
|
||||||
|
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@ContextConfiguration(classes = { TestConfiguration.class })
|
@ContextConfiguration(classes = { EmbeddedActiveMqIntegrationTest.TestConfiguration.class })
|
||||||
public class EmbeddedActiveMqManualTest {
|
public class EmbeddedActiveMqIntegrationTest {
|
||||||
|
|
||||||
@ClassRule
|
@ClassRule
|
||||||
public static EmbeddedActiveMQBroker embeddedBroker = new EmbeddedActiveMQBroker();
|
public static EmbeddedActiveMQBroker embeddedBroker = new EmbeddedActiveMQBroker();
|
||||||
|
@ -43,16 +41,20 @@ public class EmbeddedActiveMqManualTest {
|
||||||
String queueName = "queue-1";
|
String queueName = "queue-1";
|
||||||
String messageText = "Test message";
|
String messageText = "Test message";
|
||||||
|
|
||||||
|
assertEquals(0, embeddedBroker.getDestination(queueName).getDestinationStatistics().getDispatched().getCount());
|
||||||
|
assertEquals(0, embeddedBroker.getDestination(queueName).getDestinationStatistics().getMessages().getCount());
|
||||||
|
|
||||||
embeddedBroker.pushMessage(queueName, messageText);
|
embeddedBroker.pushMessage(queueName, messageText);
|
||||||
assertEquals(1, embeddedBroker.getMessageCount(queueName));
|
|
||||||
|
|
||||||
ArgumentCaptor<TextMessage> messageCaptor = ArgumentCaptor.forClass(TextMessage.class);
|
ArgumentCaptor<TextMessage> messageCaptor = ArgumentCaptor.forClass(TextMessage.class);
|
||||||
|
|
||||||
Mockito.verify(messageListener, Mockito.timeout(100))
|
Mockito.verify(messageListener, Mockito.timeout(100))
|
||||||
.sampleJmsListenerMethod(messageCaptor.capture());
|
.sampleJmsListenerMethod(messageCaptor.capture());
|
||||||
|
|
||||||
TextMessage receivedMessage = messageCaptor.getValue();
|
TextMessage receivedMessage = messageCaptor.getValue();
|
||||||
assertEquals(messageText, receivedMessage.getText());
|
assertEquals(messageText, receivedMessage.getText());
|
||||||
|
|
||||||
|
assertEquals(1, embeddedBroker.getDestination(queueName).getDestinationStatistics().getDispatched().getCount());
|
||||||
|
assertEquals(0, embeddedBroker.getDestination(queueName).getDestinationStatistics().getMessages().getCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -61,7 +63,6 @@ public class EmbeddedActiveMqManualTest {
|
||||||
String messageText = "Test message";
|
String messageText = "Test message";
|
||||||
|
|
||||||
messageSender.sendTextMessage(queueName, messageText);
|
messageSender.sendTextMessage(queueName, messageText);
|
||||||
|
|
||||||
assertEquals(1, embeddedBroker.getMessageCount(queueName));
|
assertEquals(1, embeddedBroker.getMessageCount(queueName));
|
||||||
TextMessage sentMessage = embeddedBroker.peekTextMessage(queueName);
|
TextMessage sentMessage = embeddedBroker.peekTextMessage(queueName);
|
||||||
assertEquals(messageText, sentMessage.getText());
|
assertEquals(messageText, sentMessage.getText());
|
Loading…
Reference in New Issue