public void testServiceProxiesCanBeInterrupted() throws Exception
{
AddonRegistry registry = LocalServices.getFurnace(getClass().getClassLoader())
.getAddonRegistry();
final MockSimpleCountService service = registry.getServices(MockSimpleCountService.class).get();
final AtomicReference<ContainerException> exception = new AtomicReference<>();
Thread t = new Thread(new Runnable()
{
@Override
public void run()
{
try
{
while (true)
{
service.execute();
}
}
catch (ContainerException e)
{
exception.set(e);
}
if (!Thread.currentThread().isInterrupted())
throw new RuntimeException("Should have been interrupted at this point.");
}
});
Assert.assertNull(exception.get());
t.start();
Thread.sleep(250);
t.interrupt();
Thread.sleep(250);
Assert.assertTrue(service.execute() > 0);
Assert.assertNotNull(exception.get());
}