Search in sources :

Example 1 with ServiceState

use of org.bboxdb.commons.ServiceState in project bboxdb by jnidzwetzki.

the class TestServiceState method testDispatchToStarting2.

/**
 * Dispath to starting
 */
@Test(expected = IllegalStateException.class)
public void testDispatchToStarting2() {
    final ServiceState state = new ServiceState();
    state.dipatchToStarting();
    state.dipatchToStarting();
}
Also used : ServiceState(org.bboxdb.commons.ServiceState) Test(org.junit.Test)

Example 2 with ServiceState

use of org.bboxdb.commons.ServiceState in project bboxdb by jnidzwetzki.

the class TestServiceState method testTransition1.

/**
 * Normal dispatching
 * @throws InterruptedException
 */
@Test(timeout = 1000)
public void testTransition1() throws InterruptedException {
    final ServiceState state = new ServiceState();
    Assert.assertFalse(state.isInFinishedState());
    state.dipatchToStarting();
    state.awaitStarting();
    Assert.assertTrue(state.isInStartingState());
    Assert.assertFalse(state.isInRunningState());
    Assert.assertFalse(state.isInStoppingState());
    Assert.assertFalse(state.isInFailedState());
    state.dispatchToRunning();
    Assert.assertTrue(state.isInRunningState());
    state.awaitRunning();
    Assert.assertFalse(state.isInShutdownState());
    state.dispatchToStopping();
    Assert.assertTrue(state.isInShutdownState());
    state.awaitStopping();
    state.dispatchToTerminated();
    state.awaitTerminatedOrFailed();
    Assert.assertTrue(state.isInFinishedState());
}
Also used : ServiceState(org.bboxdb.commons.ServiceState) Test(org.junit.Test)

Example 3 with ServiceState

use of org.bboxdb.commons.ServiceState in project bboxdb by jnidzwetzki.

the class TestServiceState method testTransition2.

/**
 * Error dispatching
 * @throws InterruptedException
 */
@Test(timeout = 1000, expected = IllegalStateException.class)
public void testTransition2() throws InterruptedException {
    final ServiceState state = new ServiceState();
    Assert.assertFalse(state.isInShutdownState());
    state.dispatchToTerminated();
    Assert.assertTrue(state.isInShutdownState());
    state.awaitTerminatedOrFailed();
}
Also used : ServiceState(org.bboxdb.commons.ServiceState) Test(org.junit.Test)

Example 4 with ServiceState

use of org.bboxdb.commons.ServiceState in project bboxdb by jnidzwetzki.

the class TestServiceState method testToString.

/**
 * Test the to string method
 */
@Test(timeout = 60000)
public void testToString() {
    final ServiceState state = new ServiceState();
    final int length = state.toString().length();
    final IllegalArgumentException exception = new IllegalArgumentException();
    state.dispatchToFailed(exception);
    final int lengthWithException = state.toString().length();
    // Assume at least 100 chars for stacktrace
    Assert.assertTrue(length + 100 < lengthWithException);
}
Also used : ServiceState(org.bboxdb.commons.ServiceState) Test(org.junit.Test)

Example 5 with ServiceState

use of org.bboxdb.commons.ServiceState in project bboxdb by jnidzwetzki.

the class TestServiceState method testTransition3.

/**
 * Error dispatching
 * @throws InterruptedException
 */
@Test(timeout = 1000)
public void testTransition3() throws InterruptedException {
    final ServiceState state = new ServiceState();
    final IllegalArgumentException exception = new IllegalArgumentException();
    state.dispatchToFailed(exception);
    state.awaitTerminatedOrFailed();
    Assert.assertTrue(state.isInFinishedState());
    Assert.assertFalse(state.isInRunningState());
}
Also used : ServiceState(org.bboxdb.commons.ServiceState) Test(org.junit.Test)

Aggregations

ServiceState (org.bboxdb.commons.ServiceState)12 Test (org.junit.Test)12 Semaphore (java.util.concurrent.Semaphore)2 Consumer (java.util.function.Consumer)1 State (org.bboxdb.commons.ServiceState.State)1 Assert (org.junit.Assert)1