use of org.jowidgets.util.ValueHolder in project jo-client-platform by jo-source.
the class ServiceProviderTest method testConcurrentServiceRegistration.
@Test
public void testConcurrentServiceRegistration() {
ServiceProvider.registerServiceProviderHolder(SERVICE_PROVIDER_HOLDER_1);
ServiceProvider.registerServiceProviderHolder(SERVICE_PROVIDER_HOLDER_2);
SERVICE_PROVIDER_HOLDER_1.lock();
SERVICE_PROVIDER_HOLDER_2.lock();
final ValueHolder<ConcurrentModificationException> exceptionHolder = new ValueHolder<ConcurrentModificationException>();
final CountDownLatch latch1 = new CountDownLatch(1);
final CountDownLatch latch2 = new CountDownLatch(1);
new Thread(new Runnable() {
@Override
public void run() {
try {
latch1.countDown();
ServiceProvider.getService(SERVICE_ID_1);
} catch (final ConcurrentModificationException exception) {
exceptionHolder.set(exception);
} finally {
latch2.countDown();
}
}
}).start();
try {
latch1.await();
} catch (final InterruptedException e) {
throw new RuntimeException(e);
}
ServiceProvider.registerServiceProviderHolder(Mockito.mock(IServiceProviderHolder.class));
SERVICE_PROVIDER_HOLDER_1.unlock();
SERVICE_PROVIDER_HOLDER_2.unlock();
try {
latch2.await();
} catch (final InterruptedException e) {
throw new RuntimeException(e);
}
Assert.assertNull(exceptionHolder.get());
}
Aggregations