Search in sources :

Example 6 with OnChangeWithKeepAliveSubscriptionQos

use of joynr.OnChangeWithKeepAliveSubscriptionQos 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 7 with OnChangeWithKeepAliveSubscriptionQos

use of joynr.OnChangeWithKeepAliveSubscriptionQos in project joynr by bmwcarit.

the class AbstractSubscriptionEnd2EndTest method testOnChangeWithKeepAliveSubscriptionSendsOnChange.

@Test
@Ignore
public void testOnChangeWithKeepAliveSubscriptionSendsOnChange() throws InterruptedException, ApplicationException {
    final Semaphore onReceiveSemaphore = new Semaphore(0);
    AttributeSubscriptionListener<Integer> integerListener = prepareOnReceiveListenerMock(onReceiveSemaphore);
    // NOTE: 50 is the minimum minInterval supported
    long minInterval_ms = 50;
    long subscriptionDuration = 1000;
    // publications don't live longer than subscription
    OnChangeWithKeepAliveSubscriptionQos subscriptionQos = new OnChangeWithKeepAliveSubscriptionQos();
    subscriptionQos.setMinIntervalMs(minInterval_ms);
    subscriptionQos.setMaxIntervalMs(subscriptionDuration + 1);
    subscriptionQos.setValidityMs(subscriptionDuration);
    subscriptionQos.setAlertAfterIntervalMs(subscriptionDuration);
    subscriptionQos.setPublicationTtlMs(subscriptionDuration);
    Future<String> subscriptionId = proxy.subscribeToTestAttribute(integerListener, subscriptionQos);
    getSubscriptionTestsPublisher().waitForAttributeSubscription("testAttribute");
    // when subscribing, we automatically get 1 publication. Expect the starting-publication
    verify(integerListener, times(0)).onError(null);
    assertTrue(onReceiveSemaphore.tryAcquire(1000, TimeUnit.MILLISECONDS));
    // Wait minimum time between onChanged
    Thread.sleep(minInterval_ms);
    provider.setTestAttribute(5);
    // expect the onChangeSubscription to have arrived
    assertTrue(onReceiveSemaphore.tryAcquire(1000, TimeUnit.MILLISECONDS));
    Thread.sleep(subscriptionDuration);
    // expect no more publications to arrive
    verifyNoMoreInteractions(integerListener);
    proxy.unsubscribeFromTestAttribute(subscriptionId.get(FUTURE_SUBSCRIPTION_ID_TIMEOUTMS));
    getSubscriptionTestsPublisher().waitForAttributeUnsubscription("testAttribute");
}
Also used : OnChangeWithKeepAliveSubscriptionQos(joynr.OnChangeWithKeepAliveSubscriptionQos) Semaphore(java.util.concurrent.Semaphore) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 8 with OnChangeWithKeepAliveSubscriptionQos

use of joynr.OnChangeWithKeepAliveSubscriptionQos in project joynr by bmwcarit.

the class AbstractSubscriptionEnd2EndTest method testOnChangeWithKeepAliveSubscription.

@Test
public void testOnChangeWithKeepAliveSubscription() throws InterruptedException, ApplicationException {
    Semaphore onReceiveSemaphore = new Semaphore(0);
    AttributeSubscriptionListener<Integer> integerListener = prepareOnReceiveListenerMock(onReceiveSemaphore);
    // NOTE: 50 is the minimum minInterval
    long minInterval_ms = 50;
    // supported
    // get an interval update after 200 ms
    long maxInterval_ms = 500;
    long subscriptionDuration = maxInterval_ms * 3;
    OnChangeWithKeepAliveSubscriptionQos subscriptionQos = new OnChangeWithKeepAliveSubscriptionQos();
    subscriptionQos.setMinIntervalMs(minInterval_ms);
    subscriptionQos.setMaxIntervalMs(maxInterval_ms);
    subscriptionQos.setValidityMs(subscriptionDuration);
    subscriptionQos.setAlertAfterIntervalMs(maxInterval_ms + 100);
    // publications don't live
    subscriptionQos.setPublicationTtlMs(maxInterval_ms);
    Future<String> subscriptionId = proxy.subscribeToTestAttribute(integerListener, subscriptionQos);
    getSubscriptionTestsPublisher().waitForAttributeSubscription("testAttribute");
    // when subscribing, we automatically get 1 publication. Expect the
    // starting-publication
    verify(integerListener, times(0)).onError(null);
    assertTrue(onReceiveSemaphore.tryAcquire(1000, TimeUnit.MILLISECONDS));
    // Wait minimum time between onChanged
    Thread.sleep(minInterval_ms);
    provider.setTestAttribute(5);
    // expect the onChangeSubscription to have arrived
    assertTrue(onReceiveSemaphore.tryAcquire(1000, TimeUnit.MILLISECONDS));
    // expect the third publication due to exceeding the maxInterval_ms
    assertTrue(onReceiveSemaphore.tryAcquire(maxInterval_ms + 1000, TimeUnit.MILLISECONDS));
    proxy.unsubscribeFromTestAttribute(subscriptionId.get(FUTURE_SUBSCRIPTION_ID_TIMEOUTMS));
    getSubscriptionTestsPublisher().waitForAttributeUnsubscription("testAttribute");
}
Also used : OnChangeWithKeepAliveSubscriptionQos(joynr.OnChangeWithKeepAliveSubscriptionQos) Semaphore(java.util.concurrent.Semaphore) Test(org.junit.Test)

Example 9 with OnChangeWithKeepAliveSubscriptionQos

use of joynr.OnChangeWithKeepAliveSubscriptionQos in project joynr by bmwcarit.

the class SerializationTest method serializeAndDeserializeSubscriptionQosTest.

@Test
public void serializeAndDeserializeSubscriptionQosTest() throws Exception {
    OnChangeWithKeepAliveSubscriptionQos qos = new OnChangeWithKeepAliveSubscriptionQos().setMinIntervalMs(1000L).setMaxIntervalMs(30000L).setValidityMs(60000).setAlertAfterIntervalMs(0L).setPublicationTtlMs(5000);
    String valueAsString = objectMapper.writeValueAsString(qos);
    System.out.println(valueAsString);
    SubscriptionQos readValue = objectMapper.readValue(valueAsString, SubscriptionQos.class);
    assertEquals(qos, readValue);
}
Also used : OnChangeWithKeepAliveSubscriptionQos(joynr.OnChangeWithKeepAliveSubscriptionQos) OnChangeSubscriptionQos(joynr.OnChangeSubscriptionQos) SubscriptionQos(io.joynr.pubsub.SubscriptionQos) OnChangeWithKeepAliveSubscriptionQos(joynr.OnChangeWithKeepAliveSubscriptionQos) Test(org.junit.Test)

Example 10 with OnChangeWithKeepAliveSubscriptionQos

use of joynr.OnChangeWithKeepAliveSubscriptionQos in project joynr by bmwcarit.

the class PushingPublicationTest method setupMixedQos.

void setupMixedQos() {
    OnChangeWithKeepAliveSubscriptionQos qos = new OnChangeWithKeepAliveSubscriptionQos();
    qos.setMinIntervalMs(10);
    // TODO Also write this test with -1
    qos.setMaxIntervalMs(3000);
    qos.setValidityMs(19000);
    qos.setAlertAfterIntervalMs(500);
    qos.setPublicationTtlMs(1000);
    subscriptionRequest = new SubscriptionRequest(subscriptionId, attributeName, qos);
}
Also used : OnChangeWithKeepAliveSubscriptionQos(joynr.OnChangeWithKeepAliveSubscriptionQos) SubscriptionRequest(joynr.SubscriptionRequest)

Aggregations

OnChangeWithKeepAliveSubscriptionQos (joynr.OnChangeWithKeepAliveSubscriptionQos)10 Test (org.junit.Test)7 JoynrRuntimeException (io.joynr.exceptions.JoynrRuntimeException)4 AttributeSubscriptionAdapter (io.joynr.pubsub.subscription.AttributeSubscriptionAdapter)4 Semaphore (java.util.concurrent.Semaphore)3 ProviderRuntimeException (joynr.exceptions.ProviderRuntimeException)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 SuppressWarnings (edu.umd.cs.findbugs.annotations.SuppressWarnings)2 DiscoveryQos (io.joynr.arbitration.DiscoveryQos)2 MessagingQos (io.joynr.messaging.MessagingQos)2 OnChangeSubscriptionQos (joynr.OnChangeSubscriptionQos)2 Ignore (org.junit.Ignore)2 DiscoveryException (io.joynr.exceptions.DiscoveryException)1 JoynrCommunicationException (io.joynr.exceptions.JoynrCommunicationException)1 SubscriptionException (io.joynr.exceptions.SubscriptionException)1 SubscriptionQos (io.joynr.pubsub.SubscriptionQos)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 ConsoleReader (jline.console.ConsoleReader)1