Skip to content

Commit

Permalink
Cleaner exit
Browse files Browse the repository at this point in the history
  • Loading branch information
maniksurtani committed Oct 26, 2009
1 parent 2f8cc88 commit 79a16a4
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions core/src/test/java/org/infinispan/profiling/ProfileTestSlave.java
Expand Up @@ -47,11 +47,22 @@ public void testDistAsyncL1() throws Exception {
}

private void waitForTest() throws Exception {
Thread t = new Thread() {
@Override
public void run() {
try {
System.in.read();
} catch (Exception e) {
}
}
};

// attach a view change listener
cacheManager.addListener(new ShutdownHook());
cacheManager.addListener(new ShutdownHook(t));
System.out.println("Slave listening for remote connections. Hit Enter when done.");
System.in.read();
System.in.read();

t.start();
t.join();
}

private void doTest() {
Expand All @@ -69,11 +80,18 @@ protected void testWith(String cachename) throws Exception {

@Listener
public static final class ShutdownHook {
final Thread completionThread;

public ShutdownHook(Thread completionThread) {
this.completionThread = completionThread;
}

@ViewChanged
public void viewChanged(ViewChangedEvent vce) {
System.out.println("Saw view change event " + vce);
// if the new view ONLY contains me, die!
if (vce.getOldMembers().size() > vce.getNewMembers().size() && vce.getNewMembers().size() == 1 && vce.getNewMembers().contains(vce.getLocalAddress())) {
System.exit(0);
completionThread.interrupt();
}
}
}
Expand Down

0 comments on commit 79a16a4

Please sign in to comment.