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);
}
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: "));
}
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());
}
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());
}
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());
}
Aggregations