From 1198e6a7a1e5f2aac1c486027f654c0f9c899b96 Mon Sep 17 00:00:00 2001 From: Keith Wall Date: Fri, 7 Sep 2012 15:51:58 +0000 Subject: QPID-4275: Java Performance Tests - race condition between closing test consumer and test connection Applied patch from Philip Harvey git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1382074 13f79535-47bb-0310-9956-ffa450edef68 --- .../qpid/disttest/client/ParticipantExecutor.java | 10 +++++++++- .../disttest/client/ParticipantExecutorTest.java | 20 ++++++++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) (limited to 'qpid/java') diff --git a/qpid/java/perftests/src/main/java/org/apache/qpid/disttest/client/ParticipantExecutor.java b/qpid/java/perftests/src/main/java/org/apache/qpid/disttest/client/ParticipantExecutor.java index bb9ce26f7e..10f62708a4 100644 --- a/qpid/java/perftests/src/main/java/org/apache/qpid/disttest/client/ParticipantExecutor.java +++ b/qpid/java/perftests/src/main/java/org/apache/qpid/disttest/client/ParticipantExecutor.java @@ -108,8 +108,16 @@ public class ParticipantExecutor } finally { + try + { + _participant.releaseResources(); + } + catch(Exception e) + { + LOGGER.error("Participant " + _participant + " unable to release resources", e); + } + _client.sendResults(result); - _participant.releaseResources(); } } } diff --git a/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/client/ParticipantExecutorTest.java b/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/client/ParticipantExecutorTest.java index f30e4664ff..dc73e597d5 100644 --- a/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/client/ParticipantExecutorTest.java +++ b/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/client/ParticipantExecutorTest.java @@ -20,6 +20,7 @@ package org.apache.qpid.disttest.client; import static org.mockito.Matchers.argThat; +import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.inOrder; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -69,8 +70,8 @@ public class ParticipantExecutorTest extends TestCase InOrder inOrder = inOrder(_participant, _client); inOrder.verify(_participant).doIt(CLIENT_NAME); - inOrder.verify(_client).sendResults(_mockResult); inOrder.verify(_participant).releaseResources(); + inOrder.verify(_client).sendResults(_mockResult); } public void testParticipantThrowsException() throws Exception @@ -82,13 +83,28 @@ public class ParticipantExecutorTest extends TestCase InOrder inOrder = inOrder(_participant, _client); inOrder.verify(_participant).doIt(CLIENT_NAME); + inOrder.verify(_participant).releaseResources(); inOrder.verify(_client).sendResults(argThat(HAS_ERROR)); + } + + public void testReleaseResourcesThrowsException() throws Exception + { + when(_participant.doIt(CLIENT_NAME)).thenReturn(_mockResult); + doThrow(DistributedTestException.class).when(_participant).releaseResources(); + + _participantExecutor.start(_client); + + InOrder inOrder = inOrder(_participant, _client); + + inOrder.verify(_participant).doIt(CLIENT_NAME); inOrder.verify(_participant).releaseResources(); + + // check that sendResults is called even though releaseResources threw an exception + inOrder.verify(_client).sendResults(_mockResult); } public void testThreadNameAndDaemonness() throws Exception { - ThreadPropertyReportingParticipant participant = new ThreadPropertyReportingParticipant(PARTICIPANT_NAME); _participantExecutor = new ParticipantExecutor(participant); -- cgit v1.2.1