This is an automated email from the ASF dual-hosted git repository. gtully pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/activemq.git
The following commit(s) were added to refs/heads/master by this push: new a436b21 AMQ-7508 - fix session reuse and remove incremental loggers, new test a436b21 is described below commit a436b2177ed46fe8402e43c7f48ae102bb983e9a Author: gtully <gary.tu...@gmail.com> AuthorDate: Fri Jul 3 16:46:48 2020 +0100 AMQ-7508 - fix session reuse and remove incremental loggers, new test --- .../org/apache/activemq/ra/ServerSessionImpl.java | 7 ++- .../apache/activemq/ra/ServerSessionImplTest.java | 61 ++++++++++++++++++++++ 2 files changed, 64 insertions(+), 4 deletions(-) diff --git a/activemq-ra/src/main/java/org/apache/activemq/ra/ServerSessionImpl.java b/activemq-ra/src/main/java/org/apache/activemq/ra/ServerSessionImpl.java index 37a3a48..8bd76bc 100644 --- a/activemq-ra/src/main/java/org/apache/activemq/ra/ServerSessionImpl.java +++ b/activemq-ra/src/main/java/org/apache/activemq/ra/ServerSessionImpl.java @@ -56,8 +56,7 @@ public class ServerSessionImpl implements ServerSession, InboundContext, Work, D } - private int serverSessionId = getNextLogId(); - private final Logger log = LoggerFactory.getLogger(ServerSessionImpl.class.getName() + ":" + serverSessionId); + private final Logger log = LoggerFactory.getLogger(ServerSessionImpl.class); private ActiveMQSession session; private WorkManager workManager; @@ -105,7 +104,7 @@ public class ServerSessionImpl implements ServerSession, InboundContext, Work, D } protected boolean isStale() { - return stale || !session.isRunning() || !session.isClosed(); + return stale || !session.isRunning(); } public MessageProducer getMessageProducer() throws JMSException { @@ -261,7 +260,7 @@ public class ServerSessionImpl implements ServerSession, InboundContext, Work, D */ @Override public String toString() { - return "ServerSessionImpl:" + serverSessionId + "{" + session +"}"; + return "ServerSessionImpl:{" + session +"}"; } public void close() { diff --git a/activemq-ra/src/test/java/org/apache/activemq/ra/ServerSessionImplTest.java b/activemq-ra/src/test/java/org/apache/activemq/ra/ServerSessionImplTest.java index 61467bc..0deefd6 100644 --- a/activemq-ra/src/test/java/org/apache/activemq/ra/ServerSessionImplTest.java +++ b/activemq-ra/src/test/java/org/apache/activemq/ra/ServerSessionImplTest.java @@ -57,6 +57,7 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @RunWith(JMock.class) @@ -433,4 +434,64 @@ public class ServerSessionImplTest { } } + + + @Test + public void testSessionReusedByPool() throws Exception { + + final MessageEndpointFactory messageEndpointFactory = context.mock(MessageEndpointFactory.class); + final MessageResourceAdapter resourceAdapter = context.mock(MessageResourceAdapter.class); + final ActiveMQEndpointActivationKey key = context.mock(ActiveMQEndpointActivationKey.class); + messageEndpoint = context.mock(MessageEndpointProxy.class); + workManager = context.mock(WorkManager.class); + final MessageActivationSpec messageActivationSpec = context.mock(MessageActivationSpec.class); + final BootstrapContext bootstrapContext = context.mock(BootstrapContext.class); + context.checking(new Expectations() { + { + allowing(bootstrapContext).getWorkManager(); + will(returnValue(workManager)); + allowing(resourceAdapter).getBootstrapContext(); + will(returnValue(bootstrapContext)); + allowing(messageEndpointFactory).isDeliveryTransacted(with(any(Method.class))); + will(returnValue(Boolean.FALSE)); + allowing(key).getMessageEndpointFactory(); + will(returnValue(messageEndpointFactory)); + allowing(key).getActivationSpec(); + will(returnValue(messageActivationSpec)); + allowing(messageActivationSpec).isUseJndi(); + will(returnValue(Boolean.FALSE)); + allowing(messageActivationSpec).getDestinationType(); + will(returnValue("javax.jms.Queue")); + allowing(messageActivationSpec).getDestination(); + will(returnValue("Queue")); + allowing(messageActivationSpec).getAcknowledgeModeForSession(); + will(returnValue(1)); + allowing(messageActivationSpec).getMaxSessionsIntValue(); + will(returnValue(10)); + allowing(messageActivationSpec).getEnableBatchBooleanValue(); + will(returnValue(Boolean.FALSE)); + allowing(messageActivationSpec).isUseRAManagedTransactionEnabled(); + will(returnValue(Boolean.TRUE)); + allowing(messageEndpointFactory).createEndpoint(with(any(XAResource.class))); + will(returnValue(messageEndpoint)); + + allowing(workManager).scheduleWork((Work) with(Matchers.instanceOf(Work.class)), with(any(long.class)), with(any(ExecutionContext.class)), + with(any(WorkListener.class))); + allowing(messageEndpoint).release(); + } + }); + + endpointWorker = new ActiveMQEndpointWorker(resourceAdapter, key); + endpointWorker.setConnection(con); + + pool = new ServerSessionPoolImpl(endpointWorker, 2); + endpointWorker.start(); + + // the test! + ServerSessionImpl first = (ServerSessionImpl) pool.getServerSession(); + pool.returnToPool(first); + + ServerSessionImpl reused = (ServerSessionImpl) pool.getServerSession(); + assertEquals("got reuse", first, reused); + } }