use of io.joynr.pubsub.SubscriptionQos in project joynr by bmwcarit.
the class ProxyTest method createProxySubscribeAndUnsubscribeFromAttribute.
@Test
public void createProxySubscribeAndUnsubscribeFromAttribute() throws Exception {
NavigationProxy proxy = getNavigationProxy();
long minInterval_ms = 0;
long expiryDate = System.currentTimeMillis() + 30000;
long publicationTtl_ms = 5000;
SubscriptionQos subscriptionQos = new OnChangeSubscriptionQos().setMinIntervalMs(minInterval_ms).setExpiryDateMs(expiryDate).setPublicationTtlMs(publicationTtl_ms);
abstract class BooleanSubscriptionListener implements AttributeSubscriptionListener<Boolean> {
}
Future<String> subscriptionId = proxy.subscribeToGuidanceActive(mock(BooleanSubscriptionListener.class), subscriptionQos);
ArgumentCaptor<AttributeSubscribeInvocation> subscriptionRequest = ArgumentCaptor.forClass(AttributeSubscribeInvocation.class);
verify(subscriptionManager, times(1)).registerAttributeSubscription(eq(fromParticipantId), eq(Sets.newHashSet(toDiscoveryEntry)), subscriptionRequest.capture());
assertEquals("guidanceActive", subscriptionRequest.getValue().getAttributeName());
assertEquals(subscriptionId.get(), subscriptionRequest.getValue().getSubscriptionId());
// now, let's remove the previous subscriptionRequest
proxy.unsubscribeFromGuidanceActive(subscriptionId.get());
verify(subscriptionManager, times(1)).unregisterSubscription(eq(fromParticipantId), eq(Sets.newHashSet(toDiscoveryEntry)), eq(subscriptionId.get()), any(MessagingQos.class));
}
use of io.joynr.pubsub.SubscriptionQos in project joynr by bmwcarit.
the class SerializationTest method serializeAndDeserializeSubscriptionQosTest.
@Test
public void serializeAndDeserializeSubscriptionQosTest() throws Exception {
OnChangeWithKeepAliveSubscriptionQos qos = new OnChangeWithKeepAliveSubscriptionQos().setMinIntervalMs(1000L).setMaxIntervalMs(30000L).setValidityMs(60000).setAlertAfterIntervalMs(0L).setPublicationTtlMs(5000);
String valueAsString = objectMapper.writeValueAsString(qos);
System.out.println(valueAsString);
SubscriptionQos readValue = objectMapper.readValue(valueAsString, SubscriptionQos.class);
assertEquals(qos, readValue);
}
use of io.joynr.pubsub.SubscriptionQos in project joynr by bmwcarit.
the class MulticastSubscriptionRequestSerializationTest method testSerializeAndDeserialize.
@Test
public void testSerializeAndDeserialize() throws Exception {
ObjectMapper objectMapper = new ObjectMapper();
String multicastId = "multicastId";
String multicastName = "multicastName";
String subscriptionId = "subscriptionId";
SubscriptionQos qos = new OnChangeSubscriptionQos();
MulticastSubscriptionRequest multicastSubscriptionRequest = new MulticastSubscriptionRequest(multicastId, subscriptionId, multicastName, qos);
String serializedValue = objectMapper.writeValueAsString(multicastSubscriptionRequest);
logger.trace("Serialized {} is {}", multicastSubscriptionRequest, serializedValue);
assertNotNull(serializedValue);
MulticastSubscriptionRequest deserializedMulticastSubscriptionRequest = objectMapper.readValue(serializedValue, MulticastSubscriptionRequest.class);
assertNotNull(deserializedMulticastSubscriptionRequest);
assertEquals(multicastId, deserializedMulticastSubscriptionRequest.getMulticastId());
assertEquals(multicastName, deserializedMulticastSubscriptionRequest.getSubscribedToName());
assertEquals(subscriptionId, deserializedMulticastSubscriptionRequest.getSubscriptionId());
assertEquals(qos, deserializedMulticastSubscriptionRequest.getQos());
}
use of io.joynr.pubsub.SubscriptionQos in project joynr by bmwcarit.
the class MutableMessageFactoryTest method testCreateMulticastSubscriptionRequest.
@Test
public void testCreateMulticastSubscriptionRequest() {
String multicastId = "multicastId";
String subscriptionId = "subscriptionId";
String multicastName = "multicastName";
SubscriptionQos subscriptionQos = mock(SubscriptionQos.class);
MulticastSubscriptionRequest multicastSubscriptionRequest = new MulticastSubscriptionRequest(multicastId, subscriptionId, multicastName, subscriptionQos);
MutableMessage result = mutableMessageFactory.createSubscriptionRequest(fromParticipantId, toParticipantId, multicastSubscriptionRequest, messagingQos);
assertNotNull(result);
assertEquals(Message.VALUE_MESSAGE_TYPE_MULTICAST_SUBSCRIPTION_REQUEST, result.getType());
assertExpiryDateEquals(expiryDate.getValue(), result);
}
use of io.joynr.pubsub.SubscriptionQos in project joynr by bmwcarit.
the class SubscriptionManagerTest method testRegisterMulticastSubscription.
@SuppressWarnings("unchecked")
private void testRegisterMulticastSubscription(String subscriptionId, String... partitions) throws Exception {
Method method = TestMulticastSubscriptionInterface.class.getMethod("subscribeToMyMulticast", new Class[0]);
BroadcastSubscriptionListener listener = spy(new BroadcastSubscriptionListener() {
@Override
public void onError(SubscriptionException error) {
}
@Override
public void onSubscribed(String subscriptionId) {
}
@SuppressWarnings("unused")
public void onReceive() {
}
});
SubscriptionQos subscriptionQos = mock(MulticastSubscriptionQos.class);
Object[] args;
if (subscriptionId == null) {
args = new Object[] { listener, subscriptionQos, partitions };
} else {
args = new Object[] { subscriptionId, listener, subscriptionQos, partitions };
}
String multicastId = MulticastIdUtil.createMulticastId(toParticipantId, "myMulticast", partitions);
Set<String> subscriptionIdSet = new HashSet<>();
Pattern multicastIdPattern = Pattern.compile(multicastId);
multicastSubscribersDirectory.put(multicastIdPattern, subscriptionIdSet);
when(multicastWildcardRegexFactory.createIdPattern(multicastId)).thenReturn(multicastIdPattern);
MulticastSubscribeInvocation invocation = new MulticastSubscribeInvocation(method, args, future);
DiscoveryEntryWithMetaInfo toDiscoveryEntry = new DiscoveryEntryWithMetaInfo();
toDiscoveryEntry.setParticipantId(toParticipantId);
subscriptionManager.registerMulticastSubscription(fromParticipantId, Sets.newHashSet(toDiscoveryEntry), invocation);
verify(multicastSubscribersDirectory).put(any(Pattern.class), anySet());
assertEquals(1, subscriptionIdSet.size());
if (subscriptionId != null) {
assertEquals(subscriptionId, subscriptionIdSet.iterator().next());
}
verify(dispatcher).sendSubscriptionRequest(eq(fromParticipantId), eq(Sets.newHashSet(toDiscoveryEntry)), any(SubscriptionRequest.class), any(MessagingQos.class));
}
Aggregations