summaryrefslogtreecommitdiff
path: root/qpid/java/broker/src/test
diff options
context:
space:
mode:
authorRobert Gemmell <robbie@apache.org>2012-08-03 09:31:58 +0000
committerRobert Gemmell <robbie@apache.org>2012-08-03 09:31:58 +0000
commit71ec27ab45190e0e78cef1830631ac4e753ff348 (patch)
tree9a34611a446604949c8df859214b94585a3654d4 /qpid/java/broker/src/test
parent3566e5541595848d70d777bbd3d2b76d57e6d08b (diff)
downloadqpid-python-71ec27ab45190e0e78cef1830631ac4e753ff348.tar.gz
QPID-4172: HouseKeepingTask now reverts thread name before exiting to reduce confusion when inspecting thread dumps.
Applied patch from Philip Harvey <phil@philharveyonline.com> and Oleksandr Rudyy<orudyy@gmail.com> merged from trunk r1368519 git-svn-id: https://svn.apache.org/repos/asf/qpid/branches/0.18@1368846 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java/broker/src/test')
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/virtualhost/HouseKeepingTaskTest.java46
1 files changed, 46 insertions, 0 deletions
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/virtualhost/HouseKeepingTaskTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/virtualhost/HouseKeepingTaskTest.java
index 0794154e47..8b4a52bb79 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/virtualhost/HouseKeepingTaskTest.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/virtualhost/HouseKeepingTaskTest.java
@@ -64,4 +64,50 @@ public class HouseKeepingTaskTest extends QpidTestCase
//clean up the test actor
CurrentActor.remove();
}
+
+ public void testThreadNameIsSetForDurationOfTask() throws Exception
+ {
+ //create and set a test actor
+ LogActor testActor = new TestLogActor(new NullRootMessageLogger());
+ CurrentActor.set(testActor);
+
+ String originalThreadName = Thread.currentThread().getName();
+
+ String vhostName = "HouseKeepingTaskTestVhost";
+
+ String expectedThreadNameDuringExecution = vhostName + ":" + "ThreadNameRememberingTask";
+
+ ThreadNameRememberingTask testTask = new ThreadNameRememberingTask(new MockVirtualHost(vhostName));
+
+ testTask.run();
+
+ assertEquals("Thread name should have been set during execution", expectedThreadNameDuringExecution, testTask.getThreadNameDuringExecution());
+ assertEquals("Thread name should have been reverted after task has run", originalThreadName, Thread.currentThread().getName());
+
+ //clean up the test actor
+ CurrentActor.remove();
+ }
+
+
+ private static final class ThreadNameRememberingTask extends HouseKeepingTask
+ {
+ private String _threadNameDuringExecution;
+
+ private ThreadNameRememberingTask(VirtualHost vhost)
+ {
+ super(vhost);
+ }
+
+ @Override
+ public void execute()
+ {
+ _threadNameDuringExecution = Thread.currentThread().getName(); // store current thread name so we can assert it later
+ throw new RuntimeException("deliberate exception to check that thread name still gets reverted");
+ }
+
+ public String getThreadNameDuringExecution()
+ {
+ return _threadNameDuringExecution;
+ }
+ }
}