Search in sources :

Example 1 with BroadcastWithMultipleByteBufferParametersBroadcastAdapter

use of joynr.interlanguagetest.TestInterfaceBroadcastInterface.BroadcastWithMultipleByteBufferParametersBroadcastAdapter 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)

Aggregations

SubscriptionException (io.joynr.exceptions.SubscriptionException)1 Semaphore (java.util.concurrent.Semaphore)1 MulticastSubscriptionQos (joynr.MulticastSubscriptionQos)1 BroadcastWithMultipleByteBufferParametersBroadcastAdapter (joynr.interlanguagetest.TestInterfaceBroadcastInterface.BroadcastWithMultipleByteBufferParametersBroadcastAdapter)1 Test (org.junit.Test)1