Browse Source

Polishing (backported from master)

pull/27107/head
Juergen Hoeller 5 years ago
parent
commit
215514f27b
  1. 13
      spring-jms/src/main/java/org/springframework/jms/listener/DefaultMessageListenerContainer.java
  2. 15
      spring-jms/src/test/java/org/springframework/jms/config/JmsNamespaceHandlerTests.java
  3. 7
      spring-jms/src/test/java/org/springframework/jms/listener/SimpleMessageListenerContainerTests.java
  4. 6
      spring-messaging/src/test/java/org/springframework/messaging/simp/stomp/ReactorNettyTcpStompClientTests.java
  5. 15
      spring-messaging/src/test/java/org/springframework/messaging/simp/stomp/StompBrokerRelayMessageHandlerIntegrationTests.java

13
spring-jms/src/main/java/org/springframework/jms/listener/DefaultMessageListenerContainer.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2021 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -198,9 +198,9 @@ public class DefaultMessageListenerContainer extends AbstractPollingMessageListe
private int registeredWithDestination = 0; private int registeredWithDestination = 0;
private volatile boolean recovering = false; private volatile boolean recovering;
private volatile boolean interrupted = false; private volatile boolean interrupted;
@Nullable @Nullable
private Runnable stopCallback; private Runnable stopCallback;
@ -963,11 +963,8 @@ public class DefaultMessageListenerContainer extends AbstractPollingMessageListe
} }
} }
if (!applyBackOffTime(execution)) { if (!applyBackOffTime(execution)) {
StringBuilder msg = new StringBuilder(); logger.error("Stopping container for destination '" + getDestinationDescription() +
msg.append("Stopping container for destination '") "': back-off policy does not allow for further attempts.");
.append(getDestinationDescription())
.append("': back-off policy does not allow ").append("for further attempts.");
logger.error(msg.toString());
stop(); stop();
} }
} }

15
spring-jms/src/test/java/org/springframework/jms/config/JmsNamespaceHandlerTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2021 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -69,12 +69,12 @@ public class JmsNamespaceHandlerTests {
@BeforeEach @BeforeEach
public void setUp() throws Exception { public void setup() {
this.context = new ToolingTestApplicationContext("jmsNamespaceHandlerTests.xml", getClass()); this.context = new ToolingTestApplicationContext("jmsNamespaceHandlerTests.xml", getClass());
} }
@AfterEach @AfterEach
public void tearDown() throws Exception { public void shutdown() {
this.context.close(); this.context.close();
} }
@ -87,13 +87,12 @@ public class JmsNamespaceHandlerTests {
containers = context.getBeansOfType(GenericMessageEndpointManager.class); containers = context.getBeansOfType(GenericMessageEndpointManager.class);
assertThat(containers.size()).as("Context should contain 3 JCA endpoint containers").isEqualTo(3); assertThat(containers.size()).as("Context should contain 3 JCA endpoint containers").isEqualTo(3);
Map<String, JmsListenerContainerFactory> containerFactories = assertThat(context.getBeansOfType(JmsListenerContainerFactory.class))
context.getBeansOfType(JmsListenerContainerFactory.class); .as("Context should contain 3 JmsListenerContainerFactory instances").hasSize(3);
assertThat(containerFactories.size()).as("Context should contain 3 JmsListenerContainerFactory instances").isEqualTo(3);
} }
@Test @Test
public void testContainerConfiguration() throws Exception { public void testContainerConfiguration() {
Map<String, DefaultMessageListenerContainer> containers = context.getBeansOfType(DefaultMessageListenerContainer.class); Map<String, DefaultMessageListenerContainer> containers = context.getBeansOfType(DefaultMessageListenerContainer.class);
ConnectionFactory defaultConnectionFactory = context.getBean(DEFAULT_CONNECTION_FACTORY, ConnectionFactory.class); ConnectionFactory defaultConnectionFactory = context.getBean(DEFAULT_CONNECTION_FACTORY, ConnectionFactory.class);
ConnectionFactory explicitConnectionFactory = context.getBean(EXPLICIT_CONNECTION_FACTORY, ConnectionFactory.class); ConnectionFactory explicitConnectionFactory = context.getBean(EXPLICIT_CONNECTION_FACTORY, ConnectionFactory.class);
@ -115,7 +114,7 @@ public class JmsNamespaceHandlerTests {
} }
@Test @Test
public void testJcaContainerConfiguration() throws Exception { public void testJcaContainerConfiguration() {
Map<String, JmsMessageEndpointManager> containers = context.getBeansOfType(JmsMessageEndpointManager.class); Map<String, JmsMessageEndpointManager> containers = context.getBeansOfType(JmsMessageEndpointManager.class);
assertThat(containers.containsKey("listener3")).as("listener3 not found").isTrue(); assertThat(containers.containsKey("listener3")).as("listener3 not found").isTrue();

7
spring-jms/src/test/java/org/springframework/jms/listener/SimpleMessageListenerContainerTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2021 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -75,8 +75,7 @@ public class SimpleMessageListenerContainerTests {
@Test @Test
public void testSessionTransactedModeReallyDoesDefaultToFalse() { public void testSessionTransactedModeReallyDoesDefaultToFalse() {
assertThat(this.container.isPubSubNoLocal()).as("The [pubSubLocal] property of SimpleMessageListenerContainer " + assertThat(this.container.isPubSubNoLocal()).as("The [pubSubLocal] property of SimpleMessageListenerContainer " +
"must default to false. Change this test (and the " + "must default to false. Change this test (and the attendant javadoc) if you have changed the default.").isFalse();
"attendant Javadoc) if you have changed the default.").isFalse();
} }
@Test @Test
@ -121,6 +120,7 @@ public class SimpleMessageListenerContainerTests {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
context.getBeanFactory().registerSingleton("messageListenerContainer", this.container); context.getBeanFactory().registerSingleton("messageListenerContainer", this.container);
context.refresh(); context.refresh();
context.close();
verify(connection).setExceptionListener(this.container); verify(connection).setExceptionListener(this.container);
} }
@ -151,6 +151,7 @@ public class SimpleMessageListenerContainerTests {
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = new GenericApplicationContext();
context.getBeanFactory().registerSingleton("messageListenerContainer", this.container); context.getBeanFactory().registerSingleton("messageListenerContainer", this.container);
context.refresh(); context.refresh();
context.close();
verify(connection).setExceptionListener(this.container); verify(connection).setExceptionListener(this.container);
verify(connection).start(); verify(connection).start();

6
spring-messaging/src/test/java/org/springframework/messaging/simp/stomp/ReactorNettyTcpStompClientTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2021 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -58,7 +58,7 @@ public class ReactorNettyTcpStompClientTests {
@BeforeEach @BeforeEach
public void setUp(TestInfo testInfo) throws Exception { public void setup(TestInfo testInfo) throws Exception {
logger.debug("Setting up before '" + testInfo.getTestMethod().get().getName() + "'"); logger.debug("Setting up before '" + testInfo.getTestMethod().get().getName() + "'");
int port = SocketUtils.findAvailableTcpPort(61613); int port = SocketUtils.findAvailableTcpPort(61613);
@ -81,7 +81,7 @@ public class ReactorNettyTcpStompClientTests {
} }
@AfterEach @AfterEach
public void tearDown() throws Exception { public void shutdown() throws Exception {
try { try {
this.client.shutdown(); this.client.shutdown();
} }

15
spring-messaging/src/test/java/org/springframework/messaging/simp/stomp/StompBrokerRelayMessageHandlerIntegrationTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2020 the original author or authors. * Copyright 2002-2021 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -75,7 +75,7 @@ public class StompBrokerRelayMessageHandlerIntegrationTests {
@BeforeEach @BeforeEach
public void setUp(TestInfo testInfo) throws Exception { public void setup(TestInfo testInfo) throws Exception {
logger.debug("Setting up before '" + testInfo.getTestMethod().get().getName() + "'"); logger.debug("Setting up before '" + testInfo.getTestMethod().get().getName() + "'");
this.port = SocketUtils.findAvailableTcpPort(61613); this.port = SocketUtils.findAvailableTcpPort(61613);
@ -83,11 +83,11 @@ public class StompBrokerRelayMessageHandlerIntegrationTests {
this.responseHandler = new TestMessageHandler(); this.responseHandler = new TestMessageHandler();
this.responseChannel.subscribe(this.responseHandler); this.responseChannel.subscribe(this.responseHandler);
this.eventPublisher = new TestEventPublisher(); this.eventPublisher = new TestEventPublisher();
startActiveMqBroker(); startActiveMQBroker();
createAndStartRelay(); createAndStartRelay();
} }
private void startActiveMqBroker() throws Exception { private void startActiveMQBroker() throws Exception {
this.activeMQBroker = new BrokerService(); this.activeMQBroker = new BrokerService();
this.activeMQBroker.addConnector("stomp://localhost:" + this.port); this.activeMQBroker.addConnector("stomp://localhost:" + this.port);
this.activeMQBroker.setStartAsync(false); this.activeMQBroker.setStartAsync(false);
@ -217,7 +217,7 @@ public class StompBrokerRelayMessageHandlerIntegrationTests {
this.eventPublisher.expectBrokerAvailabilityEvent(false); this.eventPublisher.expectBrokerAvailabilityEvent(false);
startActiveMqBroker(); startActiveMQBroker();
this.eventPublisher.expectBrokerAvailabilityEvent(true); this.eventPublisher.expectBrokerAvailabilityEvent(true);
} }
@ -274,8 +274,7 @@ public class StompBrokerRelayMessageHandlerIntegrationTests {
} }
public void expectMessages(MessageExchange... messageExchanges) throws InterruptedException { public void expectMessages(MessageExchange... messageExchanges) throws InterruptedException {
List<MessageExchange> expectedMessages = List<MessageExchange> expectedMessages = new ArrayList<>(Arrays.asList(messageExchanges));
new ArrayList<>(Arrays.<MessageExchange>asList(messageExchanges));
while (expectedMessages.size() > 0) { while (expectedMessages.size() > 0) {
Message<?> message = this.queue.poll(10000, TimeUnit.MILLISECONDS); Message<?> message = this.queue.poll(10000, TimeUnit.MILLISECONDS);
assertThat(message).as("Timed out waiting for messages, expected [" + expectedMessages + "]").isNotNull(); assertThat(message).as("Timed out waiting for messages, expected [" + expectedMessages + "]").isNotNull();
@ -451,7 +450,7 @@ public class StompBrokerRelayMessageHandlerIntegrationTests {
@Override @Override
public final boolean match(Message<?> message) { public final boolean match(Message<?> message) {
StompHeaderAccessor headers = StompHeaderAccessor.wrap(message); StompHeaderAccessor headers = StompHeaderAccessor.wrap(message);
if (!this.command.equals(headers.getCommand()) || (this.sessionId != headers.getSessionId())) { if (!this.command.equals(headers.getCommand()) || !this.sessionId.equals(headers.getSessionId())) {
return false; return false;
} }
return matchInternal(headers, message.getPayload()); return matchInternal(headers, message.getPayload());

Loading…
Cancel
Save