Shell shell = new BaseShell(factory);
CommandQueue commands = new CommandQueue();
AsyncShell asyncShell = new AsyncShell(commands, shell);
//
BaseProcessContext ctx = BaseProcessContext.create(asyncShell, "foo").execute();
assertEquals(Status.QUEUED, ((AsyncProcess)ctx.getProcess()).getStatus());
assertEquals(0, cancelCount.get());
assertEquals(1, commands.getSize());
// Execute the command
// And wait until the other thread is waiting
Future<?> future = commands.executeAsync();
latch1.await();
assertEquals(Status.EVALUATING, ((AsyncProcess)ctx.getProcess()).getStatus());
assertEquals(0, cancelCount.get());
//
ctx.getProcess().cancel();
assertEquals(Status.CANCELED, ((AsyncProcess)ctx.getProcess()).getStatus());
assertEquals(1, cancelCount.get());
//
ctx.getProcess().cancel();
assertEquals(Status.CANCELED, ((AsyncProcess)ctx.getProcess()).getStatus());
assertEquals(1, cancelCount.get());
// Wait until it's done
latch2.countDown();
future.get();
// Test we received a cancelled response even though we provided an OK result
assertEquals(ShellResponse.Cancelled.class, ctx.getResponse().getClass());
assertEquals(Status.TERMINATED, ((AsyncProcess)ctx.getProcess()).getStatus());
assertEquals(1, cancelCount.get());
//
safeFail(failure.get());
}