BlockingStatus { public void changeStatus(final Status status) { synchronized (this) { this.status = status; if (Status.isStatusFinished(status)) { unblock(); } } } BlockingStatus(final int execId, final String jobId, final Status initialStatus); Status blockOnFinishedStatus(); Status viewStatus(); void unblock(); void changeStatus(final Status status); int getExecId(); String getJobId();  }
@Ignore @Test public void testUnfinishedBlock() throws InterruptedException { final BlockingStatus status = new BlockingStatus(1, "test", Status.QUEUED); final WatchingThread thread = new WatchingThread(status); thread.start(); Thread.sleep(3000); status.changeStatus(Status.SUCCEEDED); thread.join(); System.out.println("Diff " + thread.getDiff()); Assert.assertTrue(thread.getDiff() >= 3000 && thread.getDiff() < 3100); }
@Ignore @Test public void testUnfinishedBlockSeveralChanges() throws InterruptedException { final BlockingStatus status = new BlockingStatus(1, "test", Status.QUEUED); final WatchingThread thread = new WatchingThread(status); thread.start(); Thread.sleep(3000); status.changeStatus(Status.PAUSED); Thread.sleep(1000); status.changeStatus(Status.FAILED); thread.join(1000); System.out.println("Diff " + thread.getDiff()); Assert.assertTrue(thread.getDiff() >= 4000 && thread.getDiff() < 4100); }
@Ignore @Test public void testMultipleWatchers() throws InterruptedException { final BlockingStatus status = new BlockingStatus(1, "test", Status.QUEUED); final WatchingThread thread1 = new WatchingThread(status); thread1.start(); Thread.sleep(2000); final WatchingThread thread2 = new WatchingThread(status); thread2.start(); Thread.sleep(2000); status.changeStatus(Status.FAILED); thread2.join(1000); thread1.join(1000); System.out.println("Diff thread 1 " + thread1.getDiff()); System.out.println("Diff thread 2 " + thread2.getDiff()); Assert.assertTrue(thread1.getDiff() >= 4000 && thread1.getDiff() < 4200); Assert.assertTrue(thread2.getDiff() >= 2000 && thread2.getDiff() < 2200); }