Search in sources :

Example 1 with BroadcastWithSingleByteBufferParameterBroadcastAdapter

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

Aggregations

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