use of joynr.MulticastSubscriptionQos in project joynr by bmwcarit.
the class AbstractBroadcastEnd2EndTest method subscribeAndUnsubscribeFromEmptyBroadcast.
@Ignore
@Test(timeout = CONST_DEFAULT_TEST_TIMEOUT)
public void subscribeAndUnsubscribeFromEmptyBroadcast() throws InterruptedException, ApplicationException {
final Semaphore broadcastReceived = new Semaphore(0);
Future<String> subscriptionId = proxy.subscribeToEmptyBroadcastBroadcast(new testBroadcastInterface.EmptyBroadcastBroadcastAdapter() {
@Override
public void onReceive() {
broadcastReceived.release();
}
}, new MulticastSubscriptionQos());
Thread.sleep(300);
provider.fireEmptyBroadcast();
broadcastReceived.acquire();
// unsubscribe incorrect subscription -> now, a firing broadcast shall still be received
proxy.unsubscribeFromEmptyBroadcastBroadcast(UUID.randomUUID().toString());
provider.fireEmptyBroadcast();
broadcastReceived.acquire();
// unsubscribe correct subscription -> now, no more broadcast shall be received
proxy.unsubscribeFromEmptyBroadcastBroadcast(subscriptionId.get());
Thread.sleep(300);
provider.fireEmptyBroadcast();
assertFalse(broadcastReceived.tryAcquire(300, TimeUnit.MILLISECONDS));
}
use of joynr.MulticastSubscriptionQos in project joynr by bmwcarit.
the class MqttProviderProxyEnd2EndTest method testMulticastWithPartitionsAndSingleLevelWildcardAsLastPartition.
@Test
public void testMulticastWithPartitionsAndSingleLevelWildcardAsLastPartition() throws Exception {
final Semaphore semaphore = new Semaphore(0);
testProxy testProxy = consumerRuntime.getProxyBuilder(domain, testProxy.class).setMessagingQos(messagingQos).setDiscoveryQos(discoveryQos).build();
final List<String> errors = new ArrayList<>();
testProxy.subscribeToEmptyBroadcastBroadcast(new testBroadcastInterface.EmptyBroadcastBroadcastAdapter() {
@Override
public void onReceive() {
semaphore.release();
}
}, new MulticastSubscriptionQos(), "one", "+");
// wait to allow the subscription request to arrive at the provider
Thread.sleep(500);
provider.fireEmptyBroadcast("anotherOne");
provider.fireEmptyBroadcast("one");
// match
provider.fireEmptyBroadcast("one", "two");
provider.fireEmptyBroadcast("one", "two", "three");
provider.fireEmptyBroadcast("one", "two", "three", "four", "five", "six");
semaphore.acquire(1);
if (errors.size() > 0) {
fail("Got errors. " + errors);
}
}
use of joynr.MulticastSubscriptionQos in project joynr by bmwcarit.
the class MqttProviderProxyEnd2EndTest method testSimpleMulticast.
@Test(timeout = CONST_DEFAULT_TEST_TIMEOUT * 1000)
public void testSimpleMulticast() throws Exception {
final Semaphore semaphore = new Semaphore(0);
testProxy proxy = consumerRuntime.getProxyBuilder(domain, testProxy.class).setMessagingQos(messagingQos).setDiscoveryQos(discoveryQos).build();
proxy.subscribeToEmptyBroadcastBroadcast(new testBroadcastInterface.EmptyBroadcastBroadcastAdapter() {
@Override
public void onReceive() {
semaphore.release();
}
}, new MulticastSubscriptionQos());
// wait to allow the subscription request to arrive at the provider
Thread.sleep(500);
provider.fireEmptyBroadcast();
semaphore.acquire();
}
use of joynr.MulticastSubscriptionQos 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());
}
}
use of joynr.MulticastSubscriptionQos 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());
}
}
Aggregations