use of joynr.MulticastSubscriptionQos 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());
}
}
use of joynr.MulticastSubscriptionQos in project joynr by bmwcarit.
the class MqttProviderProxyEnd2EndTest method testMulticastWithPartitionsAndMultiLevelWildcard.
@Test(timeout = CONST_DEFAULT_TEST_TIMEOUT)
public void testMulticastWithPartitionsAndMultiLevelWildcard() 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", "*");
testProxy.subscribeToEmptyBroadcastBroadcast(new testBroadcastInterface.EmptyBroadcastBroadcastAdapter() {
@Override
public void onReceive() {
errors.add("Received multicast on partition which wasn't published to: four/five/six");
}
}, new MulticastSubscriptionQos(), "four", "five", "six");
// wait to allow the subscription request to arrive at the provider
Thread.sleep(500);
provider.fireEmptyBroadcast("anotherOne");
// match
provider.fireEmptyBroadcast("one");
// match
provider.fireEmptyBroadcast("one", "two");
// match
provider.fireEmptyBroadcast("one", "two", "three");
// match
provider.fireEmptyBroadcast("one", "two", "three", "four", "five", "six");
semaphore.acquire(4);
if (errors.size() > 0) {
fail("Got errors. " + errors);
}
}
use of joynr.MulticastSubscriptionQos in project joynr by bmwcarit.
the class MqttProviderProxyEnd2EndTest method testMulticastWithPartitions.
@Test(timeout = CONST_DEFAULT_TEST_TIMEOUT)
public void testMulticastWithPartitions() 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() {
errors.add("On receive called on listener with no partitions.");
}
}, new MulticastSubscriptionQos());
testProxy.subscribeToEmptyBroadcastBroadcast(new testBroadcastInterface.EmptyBroadcastBroadcastAdapter() {
@Override
public void onReceive() {
semaphore.release();
}
}, new MulticastSubscriptionQos(), "one", "two", "three");
// wait to allow the subscription request to arrive at the provider
Thread.sleep(500);
provider.fireEmptyBroadcast("one", "two", "three");
semaphore.acquire();
if (errors.size() > 0) {
fail("Got errors. " + errors);
}
}
use of joynr.MulticastSubscriptionQos in project joynr by bmwcarit.
the class MqttProviderProxyEnd2EndTest method testMulticastWithPartitionsAndSingleLevelWildcard.
@Test
public void testMulticastWithPartitionsAndSingleLevelWildcard() 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", "+", "three");
// wait to allow the subscription request to arrive at the provider
Thread.sleep(500);
provider.fireEmptyBroadcast("anotherOne");
provider.fireEmptyBroadcast("one");
provider.fireEmptyBroadcast("one", "two");
// match
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 AbstractBroadcastEnd2EndTest method subscribeAndUnsubscribeFromBroadcast.
@Ignore
@Test(timeout = CONST_DEFAULT_TEST_TIMEOUT)
public void subscribeAndUnsubscribeFromBroadcast() throws InterruptedException {
final Semaphore broadcastReceived = new Semaphore(0);
Future<String> subscriptionId = proxy.subscribeToLocationUpdateWithSpeedBroadcast(new testBroadcastInterface.LocationUpdateWithSpeedBroadcastAdapter() {
@Override
public void onReceive(GpsLocation location, Float speed) {
assertEquals(expectedLocation, location);
assertEquals(expectedSpeed, speed);
broadcastReceived.release();
}
}, new MulticastSubscriptionQos());
Thread.sleep(300);
provider.fireLocationUpdateWithSpeed(expectedLocation, expectedSpeed);
broadcastReceived.acquire();
// unsubscribe correct subscription -> now, no more broadcast shall be received
proxy.unsubscribeFromLocationUpdateWithSpeedBroadcast(UUID.randomUUID().toString());
provider.fireLocationUpdateWithSpeed(expectedLocation, expectedSpeed);
broadcastReceived.acquire();
// unsubscribe correct subscription -> now, no more broadcast shall be received
try {
proxy.unsubscribeFromLocationUpdateWithSpeedBroadcast(subscriptionId.get());
} catch (JoynrRuntimeException | ApplicationException e) {
logger.error(e.getMessage());
}
Thread.sleep(300);
provider.fireLocationUpdateWithSpeed(expectedLocation, expectedSpeed);
assertFalse(broadcastReceived.tryAcquire(300, TimeUnit.MILLISECONDS));
}
Aggregations