Why does the following Spring JmsTemplate unit test block when attempting to read a Person object from ActiveMQ queue person.queue?
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {MessagingConfiguration.class})
public class PersonMessengerTest {
@Autowired
private PersonMessenger personMessenger;
@Test
public void sendAndReceivePerson() {
final Person person = new Person();
final UUID id = UUID.randomUUID();
person.setId(id);
person.setFirstName("Derek");
person.setLastName("Mahar");
personMessenger.sendPersion(person);
final Person receivedPersion = personMessenger.receivePersion();
assertEquals(id, receivedPersion.getId());
}
}
@Configuration
@Import({CommonConfiguration.class})
public class MessagingConfiguration {
public static final String PERSON_QUEUE = "person.queue";
@Autowired
private ApplicationEnvironment applicationEnvironment;
@Bean
public ConnectionFactory jmsConnectionFactory() {
final ActiveMQConnectionFactory activeMqConnectionFactory = new ActiveMQConnectionFactory(
this.applicationEnvironment.getJmsBrokerUrl());
activeMqConnectionFactory.setTrustAllPackages(true);
return activeMqConnectionFactory;
}
@Bean
public JmsOperations jmsTemplate(ConnectionFactory connectionFactory) {
final JmsTemplate jmsTemplate = new JmsTemplate(connectionFactory);
jmsTemplate.setDefaultDestinationName(PERSON_QUEUE);
return jmsTemplate;
}
@Bean
public PersonMessenger personMessenger(JmsOperations jmsOperations) {
return new PersonMessenger(jmsOperations);
}
@Bean(name = PERSON_QUEUE)
public Queue personQueue() {
return new ActiveMQQueue(PERSON_QUEUE);
}
}
@Configuration
@PropertySource("classpath:application.properties")
public class CommonConfiguration {
@Autowired
private Environment applicationEnvironment;
@Bean
public ApplicationEnvironment applicationEnvironment() {
return new ApplicationEnvironment(this.applicationEnvironment);
}
}
application.properties:
jms.brokerUrl=vm://test?async=false&broker.persistent=false&broker.useJmx=false
Notice that the test blocks while attempting to read the Person object from the queue:
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.opessoftware.example.spring.messenger.PersonMessengerTest
2017-02-15 15:30:33,736|WARN|main|o.a.activemq.broker.BrokerService|49670|
org.apache.activemq.broker.BrokerService.checkMemorySystemUsageLimits(BrokerService.java:2142)
Memory Usage for the Broker (1024mb) is more than the maximum available for the JVM: 955 mb - resetting to 70% of maximum available: 668 mb
2017-02-15 15:30:33,993|WARN|main|o.a.activemq.broker.BrokerService|49927|
org.apache.activemq.broker.BrokerService.checkMemorySystemUsageLimits(BrokerService.java:2142)
Memory Usage for the Broker (1024mb) is more than the maximum available for the JVM: 955 mb - resetting to 70% of maximum available: 668 mb
Aucun commentaire:
Enregistrer un commentaire