Search in sources :

Example 1 with SubscriptionException

use of io.joynr.exceptions.SubscriptionException in project joynr by bmwcarit.

the class AbstractBroadcastEnd2EndTest method subscribeToBroadcastWithByteBufferOutput.

@Ignore
@Test(timeout = CONST_DEFAULT_TEST_TIMEOUT)
public void subscribeToBroadcastWithByteBufferOutput() throws InterruptedException {
    final Semaphore broadcastReceived = new Semaphore(0);
    final Byte[] expectedByteBuffer = { 1, 2, 3 };
    proxy.subscribeToBroadcastWithByteBufferParameterBroadcast(new testBroadcastInterface.BroadcastWithByteBufferParameterBroadcastAdapter() {

        @Override
        public void onError(SubscriptionException error) {
            fail("Error subscribing to broadcast");
        }

        @Override
        public void onReceive(Byte[] byteBufferParameter) {
            assertArrayEquals(expectedByteBuffer, byteBufferParameter);
            broadcastReceived.release();
        }
    }, new MulticastSubscriptionQos());
    Thread.sleep(300);
    provider.fireBroadcastWithByteBufferParameter(expectedByteBuffer);
    broadcastReceived.acquire();
}
Also used : SubscriptionException(io.joynr.exceptions.SubscriptionException) Semaphore(java.util.concurrent.Semaphore) joynr.tests.testBroadcastInterface(joynr.tests.testBroadcastInterface) MulticastSubscriptionQos(joynr.MulticastSubscriptionQos) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with SubscriptionException

use of io.joynr.exceptions.SubscriptionException in project joynr by bmwcarit.

the class SubscriptionManagerTest method testHandleSubscriptionReplyWithErrorWithSubscriptionListener.

@Test
public void testHandleSubscriptionReplyWithErrorWithSubscriptionListener() {
    SubscriptionException subscriptionError = new SubscriptionException(subscriptionId);
    SubscriptionReply subscriptionReply = new SubscriptionReply(subscriptionId, subscriptionError);
    @SuppressWarnings("unchecked") Future<String> futureMock = mock(Future.class);
    subscriptionFutureMap.put(subscriptionId, futureMock);
    AttributeSubscriptionListener<?> subscriptionListener = mock(AttributeSubscriptionListener.class);
    attributeSubscriptionDirectory.put(subscriptionId, subscriptionListener);
    subscriptionManager.handleSubscriptionReply(subscriptionReply);
    verify(futureMock).onFailure(eq(subscriptionError));
    verify(subscriptionListener).onError(eq(subscriptionError));
}
Also used : SubscriptionException(io.joynr.exceptions.SubscriptionException) SubscriptionReply(joynr.SubscriptionReply) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 3 with SubscriptionException

use of io.joynr.exceptions.SubscriptionException in project joynr by bmwcarit.

the class SubscriptionManagerTest method testHandleSubscriptionReplyWithErrorWithBroadcastListener.

@Test
public void testHandleSubscriptionReplyWithErrorWithBroadcastListener() {
    SubscriptionException subscriptionError = new SubscriptionException(subscriptionId);
    SubscriptionReply subscriptionReply = new SubscriptionReply(subscriptionId, subscriptionError);
    @SuppressWarnings("unchecked") Future<String> futureMock = mock(Future.class);
    subscriptionFutureMap.put(subscriptionId, futureMock);
    BroadcastSubscriptionListener broadcastListener = mock(BroadcastSubscriptionListener.class);
    broadcastSubscriptionDirectory.put(subscriptionId, broadcastListener);
    subscriptionManager.handleSubscriptionReply(subscriptionReply);
    verify(futureMock).onFailure(eq(subscriptionError));
    verify(broadcastListener).onError(eq(subscriptionError));
}
Also used : SubscriptionException(io.joynr.exceptions.SubscriptionException) SubscriptionReply(joynr.SubscriptionReply) Matchers.anyString(org.mockito.Matchers.anyString) BroadcastSubscriptionListener(io.joynr.pubsub.subscription.BroadcastSubscriptionListener) Test(org.junit.Test)

Example 4 with SubscriptionException

use of io.joynr.exceptions.SubscriptionException in project joynr by bmwcarit.

the class IltConsumerBroadcastSubscriptionTest method callSubscribeBroadcastWithMultipleByteBufferParameters.

@Test
public void callSubscribeBroadcastWithMultipleByteBufferParameters() {
    final Semaphore resultsAvailable = new Semaphore(0);
    Future<String> subscriptionIdFuture;
    String subscriptionId;
    boolean result;
    final Byte[] expectedByteBuffer1 = { -5, 125 };
    final Byte[] expectedByteBuffer2 = { 78, 0 };
    LOG.info(name.getMethodName());
    try {
        subscriptionIdFuture = testInterfaceProxy.subscribeToBroadcastWithMultipleByteBufferParametersBroadcast(new BroadcastWithMultipleByteBufferParametersBroadcastAdapter() {

            @Override
            public void onReceive(Byte[] byteBufferOut1, Byte[] byteBufferOut2) {
                LOG.info(name.getMethodName() + " - callback - got broadcast");
                if (!java.util.Objects.deepEquals(byteBufferOut1, expectedByteBuffer1) || !java.util.Objects.deepEquals(byteBufferOut2, expectedByteBuffer2)) {
                    LOG.info(name.getMethodName() + " - callback - invalid content");
                    subscribeBroadcastWithMultipleByteBufferParametersCallbackResult = false;
                } else {
                    LOG.info(name.getMethodName() + " - callback - content OK");
                    subscribeBroadcastWithMultipleByteBufferParametersCallbackResult = true;
                }
                resultsAvailable.release();
            }

            @Override
            public void onError(SubscriptionException error) {
                LOG.info(name.getMethodName() + " - callback - error");
                subscribeBroadcastWithMultipleByteBufferParametersCallbackResult = false;
                resultsAvailable.release();
            }
        }, new MulticastSubscriptionQos(), partitions);
        subscriptionId = subscriptionIdFuture.get(10000);
        LOG.info(name.getMethodName() + " - subscription successful, subscriptionId = " + subscriptionId);
        LOG.info(name.getMethodName() + " - Invoking fire method");
        testInterfaceProxy.methodToFireBroadcastWithMultipleByteBufferParameters(expectedByteBuffer1, expectedByteBuffer2, partitions);
        LOG.info(name.getMethodName() + " - fire method invoked");
        // wait for results from callback
        Assert.assertTrue(name.getMethodName() + " - FAILED - callback was not received in time", resultsAvailable.tryAcquire(2, TimeUnit.SECONDS));
        // check results from callback
        Assert.assertTrue(name.getMethodName() + " - FAILED - callback got called but received unexpected error or publication event", subscribeBroadcastWithMultipleByteBufferParametersCallbackResult);
        // try to unsubscribe in any case
        try {
            testInterfaceProxy.unsubscribeFromBroadcastWithMultipleByteBufferParametersBroadcast(subscriptionId);
            LOG.info(name.getMethodName() + " - unsubscribe successful");
        } catch (Exception e) {
            fail(name.getMethodName() + " - FAILED - caught unexpected exception on unsubscribe: " + e.getMessage());
        }
    } catch (Exception e) {
        // also catches InterruptedException from Thread.sleep() call
        fail(name.getMethodName() + " - FAILED - caught unexpected exception: " + e.getMessage());
    }
}
Also used : SubscriptionException(io.joynr.exceptions.SubscriptionException) Semaphore(java.util.concurrent.Semaphore) BroadcastWithMultipleByteBufferParametersBroadcastAdapter(joynr.interlanguagetest.TestInterfaceBroadcastInterface.BroadcastWithMultipleByteBufferParametersBroadcastAdapter) SubscriptionException(io.joynr.exceptions.SubscriptionException) MulticastSubscriptionQos(joynr.MulticastSubscriptionQos) Test(org.junit.Test)

Example 5 with SubscriptionException

use of io.joynr.exceptions.SubscriptionException in project joynr by bmwcarit.

the class IltConsumerMulticastSubscriptionTest method doNotReceivePublicationsForOtherPartitions.

@Test
public void doNotReceivePublicationsForOtherPartitions() {
    String[] subscribeToPartitions = new String[] { "partitions0", "partitions1" };
    String[] broadcastPartitions = new String[] { "otherPartition" };
    try {
        BroadcastWithSingleEnumerationParameterBroadcastAdapter adapter = new BroadcastWithSingleEnumerationParameterBroadcastAdapter() {

            @Override
            public void onReceive(ExtendedTypeCollectionEnumerationInTypeCollection enumerationOut) {
                LOG.info(name.getMethodName() + " - callback - got broadcast");
                subscribeBroadcastWithSingleEnumerationParameterCallbackResult = true;
                subscribeBroadcastWithSingleEnumerationParameterCallbackDone = true;
                synchronized (callbackCalledSemaphore) {
                    callbackCalledSemaphore.notify();
                }
            }

            @Override
            public void onError(SubscriptionException error) {
                LOG.info(name.getMethodName() + " - callback - error");
                subscribeBroadcastWithSingleEnumerationParameterCallbackResult = false;
                subscribeBroadcastWithSingleEnumerationParameterCallbackDone = true;
                synchronized (callbackCalledSemaphore) {
                    callbackCalledSemaphore.notify();
                }
            }
        };
        Future<String> subscriptionIdFuture = testInterfaceProxy.subscribeToBroadcastWithSingleEnumerationParameterBroadcast(adapter, new MulticastSubscriptionQos(), subscribeToPartitions);
        String subscriptionId = subscriptionIdFuture.get(10000);
        LOG.info(name.getMethodName() + " - subscription successful, subscriptionId = " + subscriptionId);
        LOG.info(name.getMethodName() + " - Invoking fire method with not matching partitions");
        testInterfaceProxy.methodToFireBroadcastWithSingleEnumerationParameter(broadcastPartitions);
        synchronized (callbackCalledSemaphore) {
            callbackCalledSemaphore.wait(2000);
        }
        Assert.assertEquals(false, subscribeBroadcastWithSingleEnumerationParameterCallbackDone);
        LOG.info(name.getMethodName() + " - Invoking fire method with matching partitions");
        testInterfaceProxy.methodToFireBroadcastWithSingleEnumerationParameter(subscribeToPartitions);
        synchronized (callbackCalledSemaphore) {
            callbackCalledSemaphore.wait(1000);
        }
        Assert.assertEquals(true, subscribeBroadcastWithSingleEnumerationParameterCallbackDone);
        Assert.assertEquals(true, subscribeBroadcastWithSingleEnumerationParameterCallbackResult);
        LOG.info(name.getMethodName() + " - received expected broadcast");
        testInterfaceProxy.unsubscribeFromBroadcastWithSingleEnumerationParameterBroadcast(subscriptionId);
    } catch (Exception e) {
        // also catches InterruptedException from Thread.sleep() call
        fail(name.getMethodName() + " - FAILED - caught unexpected exception: " + e.getMessage());
    }
}
Also used : SubscriptionException(io.joynr.exceptions.SubscriptionException) BroadcastWithSingleEnumerationParameterBroadcastAdapter(joynr.interlanguagetest.TestInterfaceBroadcastInterface.BroadcastWithSingleEnumerationParameterBroadcastAdapter) ExtendedTypeCollectionEnumerationInTypeCollection(joynr.interlanguagetest.namedTypeCollection2.ExtendedTypeCollectionEnumerationInTypeCollection) SubscriptionException(io.joynr.exceptions.SubscriptionException) MulticastSubscriptionQos(joynr.MulticastSubscriptionQos) Test(org.junit.Test)

Aggregations

SubscriptionException (io.joynr.exceptions.SubscriptionException)12 Test (org.junit.Test)9 MulticastSubscriptionQos (joynr.MulticastSubscriptionQos)6 Semaphore (java.util.concurrent.Semaphore)4 SubscriptionReply (joynr.SubscriptionReply)4 Matchers.anyString (org.mockito.Matchers.anyString)4 SubscriptionQos (io.joynr.pubsub.SubscriptionQos)2 BroadcastSubscriptionListener (io.joynr.pubsub.subscription.BroadcastSubscriptionListener)2 OnChangeSubscriptionQos (joynr.OnChangeSubscriptionQos)2 ExtendedTypeCollectionEnumerationInTypeCollection (joynr.interlanguagetest.namedTypeCollection2.ExtendedTypeCollectionEnumerationInTypeCollection)2 joynr.tests.testBroadcastInterface (joynr.tests.testBroadcastInterface)2 Ignore (org.junit.Ignore)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 SuppressWarnings (edu.umd.cs.findbugs.annotations.SuppressWarnings)1 MessagingQos (io.joynr.messaging.MessagingQos)1 MulticastSubscribeInvocation (io.joynr.proxy.invocation.MulticastSubscribeInvocation)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 Method (java.lang.reflect.Method)1 HashSet (java.util.HashSet)1