use of org.bboxdb.commons.ServiceState in project bboxdb by jnidzwetzki.
the class TestServiceState method testTransition4.
/**
* Error dispatching
* @throws InterruptedException
*/
@Test(timeout = 1000)
public void testTransition4() throws InterruptedException {
final ServiceState state = new ServiceState();
(new Thread(() -> {
try {
Thread.sleep(200);
} catch (InterruptedException e) {
e.printStackTrace();
}
state.dipatchToStarting();
state.dispatchToRunning();
})).start();
state.awaitRunning();
Assert.assertTrue(state.isInRunningState());
}
use of org.bboxdb.commons.ServiceState in project bboxdb by jnidzwetzki.
the class TestServiceState method testReset.
/**
* Test the reset call
*/
@Test(timeout = 60000)
public void testReset() {
final ServiceState state = new ServiceState();
final IllegalArgumentException exception = new IllegalArgumentException();
state.dispatchToFailed(exception);
state.reset();
Assert.assertEquals(null, state.getThrowable());
Assert.assertTrue(state.isInNewState());
}
use of org.bboxdb.commons.ServiceState in project bboxdb by jnidzwetzki.
the class TestServiceState method testTransition5.
/**
* Error dispatching
* @throws InterruptedException
*/
@Test(timeout = 1000)
public void testTransition5() throws InterruptedException {
final ServiceState state = new ServiceState();
final IllegalArgumentException exception = new IllegalArgumentException();
state.dispatchToFailed(exception);
Assert.assertTrue(state.isInFinishedState());
Assert.assertEquals(exception, state.getThrowable());
state.dispatchToRunning();
state.dispatchToStopping();
state.dispatchToRunning();
state.dispatchToTerminated();
Assert.assertTrue(state.isInFinishedState());
}
use of org.bboxdb.commons.ServiceState in project bboxdb by jnidzwetzki.
the class TestServiceState method testCallbackListenerRegisterAndUnregister.
/**
* Test the register and unregister method
*/
@Test(timeout = 60000)
public void testCallbackListenerRegisterAndUnregister() {
final ServiceState state = new ServiceState();
final Consumer<? super ServiceState> consumer = (s) -> {
};
// Callback is unkown
Assert.assertFalse(state.removeCallback(consumer));
state.registerCallback(consumer);
// Callback is known
Assert.assertTrue(state.removeCallback(consumer));
// Callback is unkown
Assert.assertFalse(state.removeCallback(consumer));
}
use of org.bboxdb.commons.ServiceState in project bboxdb by jnidzwetzki.
the class TestServiceState method testCallbackListener.
/**
* Test the callback listener
*/
@Test(timeout = 1000)
public void testCallbackListener() {
final Semaphore semaphore = new Semaphore(0);
final ServiceState state = new ServiceState();
state.registerCallback((s) -> {
if (s.getState() == State.TERMINATED) {
semaphore.release();
}
});
Assert.assertEquals(0, semaphore.availablePermits());
state.dipatchToStarting();
Assert.assertEquals(0, semaphore.availablePermits());
state.dispatchToRunning();
Assert.assertEquals(0, semaphore.availablePermits());
state.dispatchToStopping();
Assert.assertEquals(0, semaphore.availablePermits());
state.dispatchToTerminated();
Assert.assertEquals(1, semaphore.availablePermits());
}