Search in sources :

Example 46 with DiscoveryEntryWithMetaInfo

use of joynr.types.DiscoveryEntryWithMetaInfo in project joynr by bmwcarit.

the class DiscoveryEntryVersionFilterTest method testEmptySetUnchanged.

@Test
public void testEmptySetUnchanged() {
    Version callerVersion = new Version(0, 0);
    Set<DiscoveryEntryWithMetaInfo> discoveryEntries = new HashSet<>();
    Set<DiscoveryEntryWithMetaInfo> result = subject.filter(callerVersion, discoveryEntries, null);
    assertNotNull(result);
    assertEquals(discoveryEntries, result);
}
Also used : Version(joynr.types.Version) DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 47 with DiscoveryEntryWithMetaInfo

use of joynr.types.DiscoveryEntryWithMetaInfo in project joynr by bmwcarit.

the class DiscoveryEntryVersionFilterTest method testIncompatibleVersionFilteredOut.

@Test
public void testIncompatibleVersionFilteredOut() {
    Version callerVersion = new Version(1, 0);
    DiscoveryEntryWithMetaInfo discoveryEntry = mock(DiscoveryEntryWithMetaInfo.class);
    Version providerVersion = new Version(2, 0);
    when(discoveryEntry.getProviderVersion()).thenReturn(providerVersion);
    Set<DiscoveryEntryWithMetaInfo> discoveryEntries = Sets.newHashSet(discoveryEntry);
    Set<DiscoveryEntryWithMetaInfo> result = subject.filter(callerVersion, discoveryEntries, null);
    assertNotNull(result);
    assertTrue(result.isEmpty());
}
Also used : Version(joynr.types.Version) DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo) Test(org.junit.Test)

Example 48 with DiscoveryEntryWithMetaInfo

use of joynr.types.DiscoveryEntryWithMetaInfo in project joynr by bmwcarit.

the class DiscoveryEntryVersionFilterTest method testCompatibleVersionLeftIn.

@Test
public void testCompatibleVersionLeftIn() {
    Version callerVersion = new Version(1, 0);
    DiscoveryEntryWithMetaInfo discoveryEntry = mock(DiscoveryEntryWithMetaInfo.class);
    Version providerVersion = new Version(1, 0);
    when(discoveryEntry.getProviderVersion()).thenReturn(providerVersion);
    Set<DiscoveryEntryWithMetaInfo> discoveryEntries = Sets.newHashSet(discoveryEntry);
    when(versionCompatibilityChecker.check(eq(callerVersion), eq(providerVersion))).thenReturn(true);
    Set<DiscoveryEntryWithMetaInfo> result = subject.filter(callerVersion, discoveryEntries, null);
    assertNotNull(result);
    assertEquals(1, result.size());
    assertEquals(discoveryEntries, result);
}
Also used : Version(joynr.types.Version) DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo) Test(org.junit.Test)

Example 49 with DiscoveryEntryWithMetaInfo

use of joynr.types.DiscoveryEntryWithMetaInfo 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));
}
Also used : SubscriptionException(io.joynr.exceptions.SubscriptionException) Pattern(java.util.regex.Pattern) MulticastSubscribeInvocation(io.joynr.proxy.invocation.MulticastSubscribeInvocation) Method(java.lang.reflect.Method) Matchers.anyString(org.mockito.Matchers.anyString) BroadcastSubscriptionListener(io.joynr.pubsub.subscription.BroadcastSubscriptionListener) SubscriptionRequest(joynr.SubscriptionRequest) MessagingQos(io.joynr.messaging.MessagingQos) OnChangeSubscriptionQos(joynr.OnChangeSubscriptionQos) PeriodicSubscriptionQos(joynr.PeriodicSubscriptionQos) MulticastSubscriptionQos(joynr.MulticastSubscriptionQos) SubscriptionQos(io.joynr.pubsub.SubscriptionQos) DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo) HashSet(java.util.HashSet)

Example 50 with DiscoveryEntryWithMetaInfo

use of joynr.types.DiscoveryEntryWithMetaInfo in project joynr by bmwcarit.

the class SubscriptionManagerTest method setUp.

@Before
public void setUp() {
    subscriptionManager = new SubscriptionManagerImpl(attributeSubscriptionDirectory, broadcastSubscriptionDirectory, multicastSubscribersDirectory, subscriptionStates, missedPublicationTimers, subscriptionEndFutures, subscriptionAttributeTypes, unicastBroadcastTypes, multicastBroadcastTypes, subscriptionFutureMap, cleanupScheduler, dispatcher, multicastWildcardRegexFactory);
    subscriptionId = "testSubscription";
    attributeName = "testAttribute";
    attributeSubscriptionCallback = new AttributeSubscriptionAdapter<Integer>();
    long minInterval_ms = 100;
    long maxInterval_ms = 5000;
    long subscriptionDuration = 20000;
    long alertInterval_ms = 6000;
    long publicationTtl_ms = 1000;
    qos = new PeriodicSubscriptionQos();
    qos.setPeriodMs(maxInterval_ms);
    qos.setValidityMs(subscriptionDuration);
    qos.setAlertAfterIntervalMs(alertInterval_ms);
    qos.setPublicationTtlMs(publicationTtl_ms);
    onChangeQos = new OnChangeSubscriptionQos();
    onChangeQos.setMinIntervalMs(minInterval_ms);
    onChangeQos.setValidityMs(subscriptionDuration);
    onChangeQos.setPublicationTtlMs(publicationTtl_ms);
    qosWithoutExpiryDate = new PeriodicSubscriptionQos();
    qosWithoutExpiryDate.setPeriodMs(maxInterval_ms);
    qosWithoutExpiryDate.setValidityMs(SubscriptionQos.IGNORE_VALUE);
    qosWithoutExpiryDate.setAlertAfterIntervalMs(alertInterval_ms);
    qosWithoutExpiryDate.setPublicationTtlMs(publicationTtl_ms);
    missedPublicationTimer = new MissedPublicationTimer(System.currentTimeMillis() + subscriptionDuration, maxInterval_ms, alertInterval_ms, attributeSubscriptionCallback, subscriptionState, subscriptionId);
    qosSettings = new MessagingQos();
    fromParticipantId = "fromParticipantId";
    toParticipantId = "toParticipantId";
    toDiscoveryEntry = new DiscoveryEntryWithMetaInfo();
    toDiscoveryEntry.setParticipantId(toParticipantId);
    future = new Future<String>();
}
Also used : MessagingQos(io.joynr.messaging.MessagingQos) OnChangeSubscriptionQos(joynr.OnChangeSubscriptionQos) Matchers.anyString(org.mockito.Matchers.anyString) DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo) PeriodicSubscriptionQos(joynr.PeriodicSubscriptionQos) Before(org.junit.Before)

Aggregations

DiscoveryEntryWithMetaInfo (joynr.types.DiscoveryEntryWithMetaInfo)66 Test (org.junit.Test)32 Version (joynr.types.Version)29 ProviderQos (joynr.types.ProviderQos)24 DiscoveryEntry (joynr.types.DiscoveryEntry)16 HashSet (java.util.HashSet)14 GlobalDiscoveryEntry (joynr.types.GlobalDiscoveryEntry)13 DiscoveryQos (io.joynr.arbitration.DiscoveryQos)11 Matchers.anyString (org.mockito.Matchers.anyString)10 InvocationOnMock (org.mockito.invocation.InvocationOnMock)10 ChannelAddress (joynr.system.RoutingTypes.ChannelAddress)9 Before (org.junit.Before)9 DiscoveryException (io.joynr.exceptions.DiscoveryException)7 MessagingQos (io.joynr.messaging.MessagingQos)7 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)7 Set (java.util.Set)7 Callback (io.joynr.proxy.Callback)6 JoynrRuntimeException (io.joynr.exceptions.JoynrRuntimeException)5 Collection (java.util.Collection)5