Search in sources :

Example 6 with SubscriptionException

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

the class PublicationManagerImpl method validateAndGetSubscriptionEndDelay.

private long validateAndGetSubscriptionEndDelay(SubscriptionRequest subscriptionRequest) {
    SubscriptionQos subscriptionQos = subscriptionRequest.getQos();
    long subscriptionEndDelay = getSubscriptionEndDelay(subscriptionQos);
    if (subscriptionEndDelay < 0) {
        throw new SubscriptionException(subscriptionRequest.getSubscriptionId(), "Subscription expired.");
    }
    return subscriptionEndDelay;
}
Also used : SubscriptionException(io.joynr.exceptions.SubscriptionException) OnChangeSubscriptionQos(joynr.OnChangeSubscriptionQos) UnicastSubscriptionQos(joynr.UnicastSubscriptionQos) SubscriptionQos(io.joynr.pubsub.SubscriptionQos)

Example 7 with SubscriptionException

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

the class PublicationManagerImpl method sendSubscriptionReplyWithError.

private void sendSubscriptionReplyWithError(PublicationInformation publicationInformation, String subscriptionId, Exception exception, MessagingQos messagingQos) {
    SubscriptionException subscriptionException = new SubscriptionException(subscriptionId, exception.getMessage());
    SubscriptionReply subscriptionReply = new SubscriptionReply(subscriptionId, subscriptionException);
    dispatcher.sendSubscriptionReply(publicationInformation.providerParticipantId, publicationInformation.proxyParticipantId, subscriptionReply, messagingQos);
}
Also used : SubscriptionException(io.joynr.exceptions.SubscriptionException) SubscriptionReply(joynr.SubscriptionReply)

Example 8 with SubscriptionException

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

the class IltConsumerBroadcastSubscriptionTest method callSubscribeBroadcastWithSingleByteBufferParameter.

@Test
public void callSubscribeBroadcastWithSingleByteBufferParameter() {
    final Semaphore resultsAvailable = new Semaphore(0);
    Future<String> subscriptionIdFuture;
    String subscriptionId;
    boolean result;
    final Byte[] expectedByteBuffer = { -128, 0, 127 };
    LOG.info(name.getMethodName());
    try {
        subscriptionIdFuture = testInterfaceProxy.subscribeToBroadcastWithSingleByteBufferParameterBroadcast(new BroadcastWithSingleByteBufferParameterBroadcastAdapter() {

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

            @Override
            public void onError(SubscriptionException error) {
                LOG.info(name.getMethodName() + " - callback - error");
                subscribeBroadcastWithSingleByteBufferParameterCallbackResult = 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.methodToFireBroadcastWithSingleByteBufferParameter(expectedByteBuffer, 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));
        LOG.info(name.getMethodName() + " - results received");
        // check results from callback
        Assert.assertTrue(name.getMethodName() + " - FAILED - callback got called but received unexpected error or publication event", subscribeBroadcastWithSingleByteBufferParameterCallbackResult);
        // try to unsubscribe in any case
        try {
            testInterfaceProxy.unsubscribeFromBroadcastWithSingleByteBufferParameterBroadcast(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) BroadcastWithSingleByteBufferParameterBroadcastAdapter(joynr.interlanguagetest.TestInterfaceBroadcastInterface.BroadcastWithSingleByteBufferParameterBroadcastAdapter) Semaphore(java.util.concurrent.Semaphore) SubscriptionException(io.joynr.exceptions.SubscriptionException) MulticastSubscriptionQos(joynr.MulticastSubscriptionQos) Test(org.junit.Test)

Example 9 with SubscriptionException

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

the class IltConsumerFilteredBroadcastSubscriptionTest method callSubscribeBroadcastWithFiltering.

@SuppressWarnings("checkstyle:methodlength")
@Test
public void callSubscribeBroadcastWithFiltering() {
    Future<String> subscriptionIdFuture;
    String subscriptionId;
    int minIntervalMs = 0;
    int maxIntervalMs = 10000;
    long validityMs = 60000;
    int alertAfterIntervalMs = 20000;
    int publicationTtlMs = 5000;
    OnChangeWithKeepAliveSubscriptionQos subscriptionQos = new OnChangeWithKeepAliveSubscriptionQos().setMinIntervalMs(minIntervalMs).setMaxIntervalMs(maxIntervalMs).setValidityMs(validityMs).setAlertAfterIntervalMs(alertAfterIntervalMs).setPublicationTtlMs(publicationTtlMs);
    boolean result;
    LOG.info(name.getMethodName() + "");
    try {
        BroadcastWithFilteringBroadcastFilterParameters filterParameters = new BroadcastWithFilteringBroadcastFilterParameters();
        String stringOfInterst = "fireBroadcast";
        filterParameters.setStringOfInterest(stringOfInterst);
        String[] stringArrayOfInterest = IltUtil.createStringArray();
        String json;
        try {
            LOG.info(name.getMethodName() + " - objectMapper is " + objectMapper);
            LOG.info(name.getMethodName() + " - objectMapper stringArrayOfInterest " + stringArrayOfInterest);
            json = objectMapper.writeValueAsString(stringArrayOfInterest);
        } catch (JsonProcessingException je) {
            fail(name.getMethodName() + " - FAILED - got exception when serializing stringArrayOfInterest" + je.getMessage());
            return;
        }
        filterParameters.setStringArrayOfInterest(json);
        ExtendedTypeCollectionEnumerationInTypeCollection enumerationOfInterest = ExtendedTypeCollectionEnumerationInTypeCollection.ENUM_2_VALUE_EXTENSION_FOR_TYPECOLLECTION;
        try {
            json = objectMapper.writeValueAsString(enumerationOfInterest);
        } catch (JsonProcessingException je) {
            fail(name.getMethodName() + " - FAILED - got exception when serializing enumerationOfInterest" + je.getMessage());
            return;
        }
        filterParameters.setEnumerationOfInterest(json);
        StructWithStringArray structWithStringArrayOfInterest = IltUtil.createStructWithStringArray();
        try {
            json = objectMapper.writeValueAsString(structWithStringArrayOfInterest);
        } catch (JsonProcessingException je) {
            fail(name.getMethodName() + " - FAILED - got exception when serializing structWithStringArrayOfInterest" + je.getMessage());
            return;
        }
        filterParameters.setStructWithStringArrayOfInterest(json);
        StructWithStringArray[] structWithStringArrayArrayOfInterest = IltUtil.createStructWithStringArrayArray();
        try {
            json = objectMapper.writeValueAsString(structWithStringArrayArrayOfInterest);
        } catch (JsonProcessingException je) {
            fail(name.getMethodName() + " - FAILED - got exception when serializing structWithStringArrayArrayOfInterest" + je.getMessage());
            return;
        }
        filterParameters.setStructWithStringArrayArrayOfInterest(json);
        subscriptionIdFuture = testInterfaceProxy.subscribeToBroadcastWithFilteringBroadcast(new BroadcastWithFilteringBroadcastAdapter() {

            @Override
            public void onReceive(String stringOut, String[] stringArrayOut, ExtendedTypeCollectionEnumerationInTypeCollection enumerationOut, StructWithStringArray structWithStringArrayOut, StructWithStringArray[] structWithStringArrayArrayOut) {
                LOG.info(name.getMethodName() + " - callback - got broadcast");
                if (!IltUtil.checkStringArray(stringArrayOut)) {
                    subscribeBroadcastWithFilteringCallbackResult = false;
                } else if (enumerationOut != ExtendedTypeCollectionEnumerationInTypeCollection.ENUM_2_VALUE_EXTENSION_FOR_TYPECOLLECTION) {
                    LOG.info(name.getMethodName() + " - callback - invalid content");
                    subscribeBroadcastWithFilteringCallbackResult = false;
                } else if (!IltUtil.checkStructWithStringArray(structWithStringArrayOut)) {
                    LOG.info(name.getMethodName() + " - callback - invalid content");
                    subscribeBroadcastWithFilteringCallbackResult = false;
                } else if (!IltUtil.checkStructWithStringArrayArray(structWithStringArrayArrayOut)) {
                    LOG.info(name.getMethodName() + " - callback - invalid content");
                    subscribeBroadcastWithFilteringCallbackResult = false;
                } else {
                    LOG.info(name.getMethodName() + " - callback - content OK");
                    subscribeBroadcastWithFilteringCallbackResult = true;
                }
                subscribeBroadcastWithFilteringCallbackDone = true;
            }

            @Override
            public void onError(SubscriptionException error) {
                LOG.info(name.getMethodName() + " - callback - error");
                subscribeBroadcastWithFilteringCallbackResult = false;
                subscribeBroadcastWithFilteringCallbackDone = true;
            }
        }, subscriptionQos, filterParameters);
        subscriptionId = subscriptionIdFuture.get(10000);
        LOG.info(name.getMethodName() + " - subscription successful, subscriptionId = " + subscriptionId);
        LOG.info(name.getMethodName() + " - Waiting one second");
        Thread.sleep(1000);
        LOG.info(name.getMethodName() + " - Wait done, invoking fire method");
        String stringArg = "fireBroadcast";
        testInterfaceProxy.methodToFireBroadcastWithFiltering(stringArg);
        LOG.info(name.getMethodName() + " - fire method invoked");
        // should have been called ahead anyway
        if (subscribeBroadcastWithFilteringCallbackDone == false) {
            LOG.info(name.getMethodName() + " - about to wait for a second for callback");
            Thread.sleep(1000);
            LOG.info(name.getMethodName() + " - wait for callback is over");
        } else {
            LOG.info(name.getMethodName() + " - callback already done");
        }
        if (!subscribeBroadcastWithFilteringCallbackDone) {
            fail(name.getMethodName() + " - FAILED - callback did not get called in time");
            result = false;
        } else if (subscribeBroadcastWithFilteringCallbackResult) {
            LOG.info(name.getMethodName() + " - callback got called and received expected publication");
            result = true;
        } else {
            fail(name.getMethodName() + " - FAILED - callback got called but received unexpected error or publication content");
            result = false;
        }
        // get out, if first test run failed
        if (result == false) {
            return;
        }
        // reset counter for 2nd test
        subscribeBroadcastWithFilteringCallbackResult = false;
        subscribeBroadcastWithFilteringCallbackDone = false;
        LOG.info(name.getMethodName() + " - invoking fire method with wrong stringArg");
        stringArg = "doNotfireBroadcast";
        testInterfaceProxy.methodToFireBroadcastWithFiltering(stringArg);
        LOG.info(name.getMethodName() + " - fire method invoked");
        // should have been called ahead anyway
        if (subscribeBroadcastWithFilteringCallbackDone == false) {
            LOG.info(name.getMethodName() + " - about to wait for a second for callback");
            Thread.sleep(1000);
            LOG.info(name.getMethodName() + " - wait for callback is over");
        } else {
            LOG.info(name.getMethodName() + " - callback already done");
        }
        if (!subscribeBroadcastWithFilteringCallbackDone) {
            LOG.info(name.getMethodName() + " - callback did not get called in time (expected)");
            result = true;
        } else {
            fail(name.getMethodName() + " - FAILED - callback got called unexpectedly");
            result = false;
        }
        // try to unsubscribe
        try {
            testInterfaceProxy.unsubscribeFromBroadcastWithFilteringBroadcast(subscriptionId);
            LOG.info(name.getMethodName() + " - unsubscribe successful");
        } catch (Exception e) {
            fail(name.getMethodName() + " - FAILED - caught unexpected exception on unsubscribe: " + e.getMessage());
            result = false;
        }
        if (!result) {
            LOG.info(name.getMethodName() + " - FAILED");
        } else {
            LOG.info(name.getMethodName() + " - OK");
        }
        return;
    } catch (Exception e) {
        // also catches InterruptedException from Thread.sleep() call
        StringWriter stringWriter = new StringWriter();
        PrintWriter printWriter = new PrintWriter(stringWriter);
        e.printStackTrace(printWriter);
        printWriter.flush();
        fail(name.getMethodName() + " - FAILED - caught unexpected exception: " + stringWriter.toString());
        return;
    }
}
Also used : SubscriptionException(io.joynr.exceptions.SubscriptionException) OnChangeWithKeepAliveSubscriptionQos(joynr.OnChangeWithKeepAliveSubscriptionQos) BroadcastWithFilteringBroadcastAdapter(joynr.interlanguagetest.TestInterfaceBroadcastInterface.BroadcastWithFilteringBroadcastAdapter) ExtendedTypeCollectionEnumerationInTypeCollection(joynr.interlanguagetest.namedTypeCollection2.ExtendedTypeCollectionEnumerationInTypeCollection) SubscriptionException(io.joynr.exceptions.SubscriptionException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) StringWriter(java.io.StringWriter) StructWithStringArray(joynr.interlanguagetest.namedTypeCollection1.StructWithStringArray) BroadcastWithFilteringBroadcastFilterParameters(joynr.interlanguagetest.TestInterfaceBroadcastInterface.BroadcastWithFilteringBroadcastFilterParameters) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) PrintWriter(java.io.PrintWriter) Test(org.junit.Test) SuppressWarnings(edu.umd.cs.findbugs.annotations.SuppressWarnings)

Example 10 with SubscriptionException

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

the class AbstractBroadcastEnd2EndTest method subscribeToBroadcastWithEnumOutput.

@Ignore
@Test(timeout = CONST_DEFAULT_TEST_TIMEOUT)
public void subscribeToBroadcastWithEnumOutput() throws InterruptedException {
    final Semaphore broadcastReceived = new Semaphore(0);
    final TestEnum expectedTestEnum = TestEnum.TWO;
    proxy.subscribeToBroadcastWithEnumOutputBroadcast(new testBroadcastInterface.BroadcastWithEnumOutputBroadcastAdapter() {

        @Override
        public void onReceive(TestEnum testEnum) {
            assertEquals(expectedTestEnum, testEnum);
            broadcastReceived.release();
        }

        @Override
        public void onError(SubscriptionException error) {
            fail("Error subscribing to broadcast");
        }
    }, new MulticastSubscriptionQos());
    Thread.sleep(300);
    provider.fireBroadcastWithEnumOutput(expectedTestEnum);
    broadcastReceived.acquire();
}
Also used : SubscriptionException(io.joynr.exceptions.SubscriptionException) TestEnum(joynr.tests.testTypes.TestEnum) Semaphore(java.util.concurrent.Semaphore) joynr.tests.testBroadcastInterface(joynr.tests.testBroadcastInterface) MulticastSubscriptionQos(joynr.MulticastSubscriptionQos) Ignore(org.junit.Ignore) 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