Search in sources :

Example 6 with ValueHolder

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());
}
Also used : ConcurrentModificationException(java.util.ConcurrentModificationException) ValueHolder(org.jowidgets.util.ValueHolder) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Aggregations

ValueHolder (org.jowidgets.util.ValueHolder)6 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 PropertyChangeListener (java.beans.PropertyChangeListener)1 ConcurrentModificationException (java.util.ConcurrentModificationException)1 LinkedList (java.util.LinkedList)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Condition (java.util.concurrent.locks.Condition)1 Lock (java.util.concurrent.locks.Lock)1 ReentrantLock (java.util.concurrent.locks.ReentrantLock)1 IExecutionCallback (org.jowidgets.cap.common.api.execution.IExecutionCallback)1 UserQuestionResult (org.jowidgets.cap.common.api.execution.UserQuestionResult)1 IBeanValidationResult (org.jowidgets.cap.common.api.validation.IBeanValidationResult)1 IBeanValidationResultListBuilder (org.jowidgets.cap.common.api.validation.IBeanValidationResultListBuilder)1 Progress (org.jowidgets.cap.remoting.common.Progress)1 UserQuestionRequest (org.jowidgets.cap.remoting.common.UserQuestionRequest)1 IExternalBeanValidator (org.jowidgets.cap.ui.api.bean.IExternalBeanValidator)1 IItemStateListener (org.jowidgets.common.widgets.controller.IItemStateListener)1 IChangeListener (org.jowidgets.util.event.IChangeListener)1 Test (org.junit.Test)1