Improvements on Thread check
This commit is contained in:
parent
8b6d3a65be
commit
2d3061d9b6
|
@ -51,18 +51,15 @@ public class ThreadLeakCheckRule extends ExternalResource {
|
|||
* Override to tear down your specific external resource.
|
||||
*/
|
||||
protected void after() {
|
||||
try {
|
||||
if (enabled) {
|
||||
StringBuffer buffer = null;
|
||||
|
||||
boolean failed = true;
|
||||
|
||||
boolean failedOnce = false;
|
||||
|
||||
long timeout = System.currentTimeMillis() + 60000;
|
||||
while (failed && timeout > System.currentTimeMillis()) {
|
||||
buffer = new StringBuffer();
|
||||
|
||||
failed = checkThread(buffer);
|
||||
failed = checkThread();
|
||||
|
||||
if (failed) {
|
||||
failedOnce = true;
|
||||
|
@ -72,17 +69,10 @@ public class ThreadLeakCheckRule extends ExternalResource {
|
|||
}
|
||||
catch (Throwable e) {
|
||||
}
|
||||
|
||||
System.out.println("There are still threads running, trying again");
|
||||
System.out.println(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
if (failed) {
|
||||
System.out.println("Thread leaked on test \n" +
|
||||
buffer);
|
||||
System.out.println("Thread leakage! Failure!!!");
|
||||
|
||||
Assert.fail("Thread leaked");
|
||||
}
|
||||
else if (failedOnce) {
|
||||
|
@ -90,45 +80,49 @@ public class ThreadLeakCheckRule extends ExternalResource {
|
|||
System.out.println();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else {
|
||||
enabled = true;
|
||||
}
|
||||
}
|
||||
finally {
|
||||
// clearing just to help GC
|
||||
previousThreads = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param buffer
|
||||
* @return
|
||||
*/
|
||||
private boolean checkThread(StringBuffer buffer) {
|
||||
private boolean checkThread() {
|
||||
boolean failedThread = false;
|
||||
|
||||
Map<Thread, StackTraceElement[]> postThreads = Thread.getAllStackTraces();
|
||||
|
||||
if (postThreads != null && previousThreads != null && postThreads.size() > previousThreads.size()) {
|
||||
|
||||
buffer.append("*********************************************************************************\n");
|
||||
buffer.append("LEAKING THREADS\n");
|
||||
|
||||
for (Thread aliveThread : postThreads.keySet()) {
|
||||
if (!isExpectedThread(aliveThread) && !previousThreads.containsKey(aliveThread)) {
|
||||
if (aliveThread.isAlive() && !isExpectedThread(aliveThread) && !previousThreads.containsKey(aliveThread)) {
|
||||
if (!failedThread) {
|
||||
System.out.println("*********************************************************************************");
|
||||
System.out.println("LEAKING THREADS");
|
||||
}
|
||||
failedThread = true;
|
||||
buffer.append("=============================================================================\n");
|
||||
buffer.append("Thread " + aliveThread + " is still alive with the following stackTrace:\n");
|
||||
System.out.println("=============================================================================");
|
||||
System.out.println("Thread " + aliveThread + " is still alive with the following stackTrace:");
|
||||
StackTraceElement[] elements = postThreads.get(aliveThread);
|
||||
for (StackTraceElement el : elements) {
|
||||
buffer.append(el + "\n");
|
||||
System.out.println(el);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
buffer.append("*********************************************************************************\n");
|
||||
|
||||
if (failedThread) {
|
||||
System.out.println("*********************************************************************************");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return failedThread;
|
||||
}
|
||||
|
||||
|
|
|
@ -1393,7 +1393,6 @@ public class FailoverTest extends FailoverTestBase {
|
|||
|
||||
@Test
|
||||
public void testCreateNewFactoryAfterFailover() throws Exception {
|
||||
this.disableCheckThread();
|
||||
locator.setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setFailoverOnInitialConnection(true);
|
||||
sf = createSessionFactoryAndWaitForTopology(locator, 2);
|
||||
|
||||
|
|
|
@ -246,7 +246,6 @@ public class LiveToLiveFailoverTest extends FailoverTest {
|
|||
@Override
|
||||
@Test
|
||||
public void testCreateNewFactoryAfterFailover() throws Exception {
|
||||
this.disableCheckThread();
|
||||
locator.setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setFailoverOnInitialConnection(true);
|
||||
sf = createSessionFactoryAndWaitForTopology(locator, 2);
|
||||
|
||||
|
|
Loading…
Reference in New Issue