Search in sources :

Example 1 with Status

use of org.apache.jackrabbit.oak.commons.jmx.ManagementOperation.Status in project jackrabbit-oak by apache.

the class ManagementOperationTest method checkConversion.

private static void checkConversion(Status status) {
    CompositeData cd = status.toCompositeData();
    assertEquals(status.getCode().ordinal(), cd.get("code"));
    assertEquals(status.getId(), cd.get("id"));
    assertEquals(status.getMessage(), cd.get("message"));
    Status status2 = Status.fromCompositeData(cd);
    CompositeData cd2 = status2.toCompositeData();
    assertEquals(status, status2);
    assertEquals(cd, cd2);
}
Also used : Status(org.apache.jackrabbit.oak.commons.jmx.ManagementOperation.Status) CompositeData(javax.management.openmbean.CompositeData)

Example 2 with Status

use of org.apache.jackrabbit.oak.commons.jmx.ManagementOperation.Status in project jackrabbit-oak by apache.

the class ManagementOperationTest method running.

@Test
public void running() throws InterruptedException {
    final LinkedBlockingDeque<Thread> thread = new LinkedBlockingDeque<Thread>(1);
    ManagementOperation<Void> op = newManagementOperation("test", new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            thread.add(currentThread());
            sleep(100000);
            return null;
        }
    });
    executor.execute(op);
    Status status = op.getStatus();
    assertEquals(op.getId(), status.getId());
    assertEquals(RUNNING, status.getCode());
    thread.poll(5, SECONDS).interrupt();
    try {
        op.get();
        fail("Expected InterruptedException");
    } catch (ExecutionException e) {
        assertTrue(e.getCause() instanceof InterruptedException);
    }
    assertTrue(op.isDone());
    status = op.getStatus();
    assertEquals(op.getId(), status.getId());
    assertEquals(FAILED, status.getCode());
    assertTrue(status.getMessage().contains("test failed: "));
}
Also used : Status(org.apache.jackrabbit.oak.commons.jmx.ManagementOperation.Status) LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException) ExecutionException(java.util.concurrent.ExecutionException) Thread.currentThread(java.lang.Thread.currentThread) Test(org.junit.Test)

Example 3 with Status

use of org.apache.jackrabbit.oak.commons.jmx.ManagementOperation.Status in project jackrabbit-oak by apache.

the class ManagementOperationTest method cancelled.

@Test
public void cancelled() {
    ManagementOperation<Void> op = newManagementOperation("test", new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            return null;
        }
    });
    op.cancel(false);
    executor.execute(op);
    assertTrue(op.isDone());
    Status status = op.getStatus();
    assertEquals(op.getId(), status.getId());
    assertEquals(FAILED, status.getCode());
    assertEquals("test cancelled", status.getMessage());
}
Also used : Status(org.apache.jackrabbit.oak.commons.jmx.ManagementOperation.Status) TimeoutException(java.util.concurrent.TimeoutException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 4 with Status

use of org.apache.jackrabbit.oak.commons.jmx.ManagementOperation.Status in project jackrabbit-oak by apache.

the class ManagementOperationTest method failed.

@Test
public void failed() throws InterruptedException, TimeoutException {
    final Exception failure = new Exception("fail");
    ManagementOperation<Void> op = newManagementOperation("test", new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            throw failure;
        }
    });
    executor.execute(op);
    try {
        assertEquals(null, op.get(5, SECONDS));
        fail("Expected " + failure);
    } catch (ExecutionException e) {
        assertEquals(failure, e.getCause());
    }
    assertTrue(op.isDone());
    Status status = op.getStatus();
    assertEquals(op.getId(), status.getId());
    assertEquals(FAILED, status.getCode());
    assertEquals("test failed: " + failure.getMessage(), status.getMessage());
}
Also used : Status(org.apache.jackrabbit.oak.commons.jmx.ManagementOperation.Status) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 5 with Status

use of org.apache.jackrabbit.oak.commons.jmx.ManagementOperation.Status in project jackrabbit-oak by apache.

the class ManagementOperationTest method succeeded.

@Test
public void succeeded() throws InterruptedException, ExecutionException, TimeoutException {
    ManagementOperation<Long> op = newManagementOperation("test", new Callable<Long>() {

        @Override
        public Long call() throws Exception {
            return 42L;
        }
    });
    executor.execute(op);
    assertEquals(42L, (long) op.get(5, SECONDS));
    assertTrue(op.isDone());
    Status status = op.getStatus();
    assertEquals(op.getId(), status.getId());
    assertEquals(SUCCEEDED, status.getCode());
}
Also used : Status(org.apache.jackrabbit.oak.commons.jmx.ManagementOperation.Status) TimeoutException(java.util.concurrent.TimeoutException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Aggregations

Status (org.apache.jackrabbit.oak.commons.jmx.ManagementOperation.Status)5 ExecutionException (java.util.concurrent.ExecutionException)4 TimeoutException (java.util.concurrent.TimeoutException)4 Test (org.junit.Test)4 Thread.currentThread (java.lang.Thread.currentThread)1 LinkedBlockingDeque (java.util.concurrent.LinkedBlockingDeque)1 CompositeData (javax.management.openmbean.CompositeData)1