Search in sources :

Example 1 with BroadcastWithSingleEnumerationParameterBroadcastAdapter

use of joynr.interlanguagetest.TestInterfaceBroadcastInterface.BroadcastWithSingleEnumerationParameterBroadcastAdapter 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)1 MulticastSubscriptionQos (joynr.MulticastSubscriptionQos)1 BroadcastWithSingleEnumerationParameterBroadcastAdapter (joynr.interlanguagetest.TestInterfaceBroadcastInterface.BroadcastWithSingleEnumerationParameterBroadcastAdapter)1 ExtendedTypeCollectionEnumerationInTypeCollection (joynr.interlanguagetest.namedTypeCollection2.ExtendedTypeCollectionEnumerationInTypeCollection)1 Test (org.junit.Test)1