Search in sources :

Example 1 with AbstractSubscriptionPublisher

use of io.joynr.provider.AbstractSubscriptionPublisher in project joynr by bmwcarit.

the class DispatcherImplTest method addRequestCallerDoesNotBlock.

@Test
public void addRequestCallerDoesNotBlock() throws InterruptedException, ExecutionException, TimeoutException {
    final Callable<Boolean> stuffToDo = new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            try {
                String requestReplyId = UUID.randomUUID().toString();
                RequestCaller requestCaller = mock(RequestCaller.class);
                AbstractSubscriptionPublisher subscriptionPublisher = mock(AbstractSubscriptionPublisher.class);
                /* setBlockInitialisation to true causes the messageReceiver to block
                     * during startup
                     * The MessageReceiver is invoked by the dispatcher once a request caller
                     * is registered
                     *
                     */
                messageReceiverMock.setBlockOnInitialisation(true);
                requestCallerDirectory.add(requestReplyId, new ProviderContainer("interfaceName", DispatcherImplTest.class, requestCaller, subscriptionPublisher));
            } finally {
                messageReceiverMock.setBlockOnInitialisation(false);
            }
            return true;
        }
    };
    final ExecutorService executor = Executors.newSingleThreadExecutor();
    final Future<Boolean> future = executor.submit(stuffToDo);
    // should not throw a timeout exception
    future.get(1000, TimeUnit.MILLISECONDS);
    verify(messageReceiverMock).start(eq(fixture), any(ReceiverStatusListener.class));
}
Also used : AbstractSubscriptionPublisher(io.joynr.provider.AbstractSubscriptionPublisher) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ExecutorService(java.util.concurrent.ExecutorService) Matchers.anyString(org.mockito.Matchers.anyString) ReceiverStatusListener(io.joynr.messaging.ReceiverStatusListener) ProviderContainer(io.joynr.provider.ProviderContainer) Callable(java.util.concurrent.Callable) Test(org.junit.Test)

Aggregations

ReceiverStatusListener (io.joynr.messaging.ReceiverStatusListener)1 AbstractSubscriptionPublisher (io.joynr.provider.AbstractSubscriptionPublisher)1 ProviderContainer (io.joynr.provider.ProviderContainer)1 Callable (java.util.concurrent.Callable)1 ExecutorService (java.util.concurrent.ExecutorService)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 Test (org.junit.Test)1 Matchers.anyString (org.mockito.Matchers.anyString)1