Search in sources :

Example 16 with Version

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

the class LocalDiscoveryAggregatorTest method setUp.

@Before
public void setUp() {
    systemServicesDomain = "test.system.service.domain";
    anotherDomain = "anotherDomain";
    discoveryProviderParticipantId = "test.discovery.provider.participant";
    when(proxyBuilderFactory.get(anyString(), eq(DiscoveryProxy.class))).thenReturn(proxyBuilder);
    when(proxyBuilder.build()).thenReturn(discoveryProxyMock);
    when(proxyBuilder.setMessagingQos(any(MessagingQos.class))).thenReturn(proxyBuilder);
    localDiscoveryAggregator = new LocalDiscoveryAggregator(systemServicesDomain, discoveryProviderParticipantId, "routingProviderParticipantId", proxyBuilderFactory);
    localDiscoveryAggregator.forceQueryOfDiscoveryProxy();
    ProviderQos providerQos = new ProviderQos();
    providerQos.setScope(ProviderScope.LOCAL);
    discoveryProviderEntry = new DiscoveryEntryWithMetaInfo(new Version(0, 1), systemServicesDomain, Discovery.INTERFACE_NAME, discoveryProviderParticipantId, providerQos, System.currentTimeMillis(), expiryDateMs, publicKeyId, true);
    anotherDiscoveryProviderEntry = new DiscoveryEntryWithMetaInfo(new Version(0, 0), anotherDomain, Discovery.INTERFACE_NAME, discoveryProviderParticipantId, providerQos, System.currentTimeMillis(), expiryDateMs, publicKeyId, true);
}
Also used : MessagingQos(io.joynr.messaging.MessagingQos) DiscoveryProxy(joynr.system.DiscoveryProxy) Version(joynr.types.Version) DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo) ProviderQos(joynr.types.ProviderQos) Before(org.junit.Before)

Example 17 with Version

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

the class SerializationTest method serializeSubtypeInCompoundType.

@Test
public void serializeSubtypeInCompoundType() throws Exception {
    MqttAddress mqttAddress = new MqttAddress("brokerUri", "topic");
    GlobalDiscoveryEntry globalDiscoveryEntry = new GlobalDiscoveryEntry(new Version(47, 11), "domain", "interface", "participantId", new ProviderQos(), System.currentTimeMillis(), expiryDateMs, publicKeyId, objectMapper.writeValueAsString(mqttAddress));
    String serializedGlobalDiscoveryEntry = objectMapper.writeValueAsString(globalDiscoveryEntry);
    GlobalDiscoveryEntry receivedDiscoveryEntry = objectMapper.readValue(serializedGlobalDiscoveryEntry, GlobalDiscoveryEntry.class);
    Assert.assertTrue(objectMapper.readValue(receivedDiscoveryEntry.getAddress(), Address.class) instanceof MqttAddress);
    Assert.assertEquals(globalDiscoveryEntry, receivedDiscoveryEntry);
}
Also used : Version(joynr.types.Version) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) ProviderQos(joynr.types.ProviderQos) MqttAddress(joynr.system.RoutingTypes.MqttAddress) Test(org.junit.Test)

Example 18 with Version

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

the class ArbitrationTest method keywordArbitratorOnChangeSubscriptionsTest.

// Check that the keyword arbitrator will only consider providers that support onChange subscriptions
// when this is requested by the DiscoveryQos
@Test
public void keywordArbitratorOnChangeSubscriptionsTest() throws InterruptedException {
    ProviderQos providerQos = new ProviderQos();
    CustomParameter[] qosParameters = { new CustomParameter(ArbitrationConstants.KEYWORD_PARAMETER, testKeyword) };
    // Create a capability entry for a provider with the correct keyword but that does not support onChange subscriptions
    providerQos.setCustomParameters(qosParameters);
    providerQos.setSupportsOnChangeSubscriptions(false);
    capabilitiesList.add(new DiscoveryEntryWithMetaInfo(new Version(47, 11), domain, TestInterface.INTERFACE_NAME, "wrongParticipantId", providerQos, System.currentTimeMillis(), NO_EXPIRY, publicKeyId, true));
    // Create a capability entry for a provider with the correct keyword and that also supports onChange subscriptions
    ProviderQos providerQos2 = new ProviderQos();
    CustomParameter[] qosParameters2 = { new CustomParameter(ArbitrationConstants.KEYWORD_PARAMETER, testKeyword) };
    providerQos2.setCustomParameters(qosParameters2);
    providerQos2.setSupportsOnChangeSubscriptions(true);
    expectedEndpointAddress = new ChannelAddress("http://testUrl", "testChannelId");
    DiscoveryEntryWithMetaInfo expectedDiscoveryEntry = new DiscoveryEntryWithMetaInfo(new Version(47, 11), domain, TestInterface.INTERFACE_NAME, "expectedParticipantId", providerQos2, System.currentTimeMillis(), NO_EXPIRY, publicKeyId, true);
    capabilitiesList.add(expectedDiscoveryEntry);
    discoveryQos = new DiscoveryQos(ARBITRATION_TIMEOUT, ArbitrationStrategy.Keyword, Long.MAX_VALUE);
    discoveryQos.addCustomParameter(ArbitrationConstants.KEYWORD_PARAMETER, testKeyword);
    discoveryQos.setProviderMustSupportOnChange(true);
    try {
        Arbitrator arbitrator = ArbitratorFactory.create(Sets.newHashSet(domain), interfaceName, interfaceVersion, discoveryQos, localDiscoveryAggregator);
        arbitrator.setArbitrationListener(arbitrationCallback);
        arbitrator.scheduleArbitration();
        assertTrue(localDiscoveryAggregatorSemaphore.tryAcquire(1000, TimeUnit.MILLISECONDS));
        ArbitrationResult expectedArbitrationResult = new ArbitrationResult(expectedDiscoveryEntry);
        verify(arbitrationCallback, times(1)).onSuccess(eq(expectedArbitrationResult));
    } catch (DiscoveryException e) {
        fail("A Joyn Arbitration Exception has been thrown");
    }
}
Also used : Version(joynr.types.Version) ChannelAddress(joynr.system.RoutingTypes.ChannelAddress) CustomParameter(joynr.types.CustomParameter) DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo) DiscoveryException(io.joynr.exceptions.DiscoveryException) ProviderQos(joynr.types.ProviderQos) Test(org.junit.Test)

Example 19 with Version

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

the class ArbitrationTest method keyWordArbitratorMissingKeywordTest.

@Test
public void keyWordArbitratorMissingKeywordTest() throws InterruptedException {
    ProviderQos providerQos = new ProviderQos();
    CustomParameter[] qosParameters = { new CustomParameter(ArbitrationConstants.KEYWORD_PARAMETER, "wrongkeyword") };
    providerQos.setCustomParameters(qosParameters);
    expectedEndpointAddress = new ChannelAddress("http://testUrl", "testChannelId");
    capabilitiesList.add(new DiscoveryEntryWithMetaInfo(new Version(47, 11), domain, TestInterface.INTERFACE_NAME, expectedParticipantId, providerQos, System.currentTimeMillis(), NO_EXPIRY, publicKeyId, true));
    ProviderQos providerQos2 = new ProviderQos();
    CustomParameter[] qosParameters2 = { new CustomParameter(ArbitrationConstants.KEYWORD_PARAMETER, "otherKeyword") };
    providerQos2.setCustomParameters(qosParameters2);
    capabilitiesList.add(new DiscoveryEntryWithMetaInfo(new Version(47, 11), domain, TestInterface.INTERFACE_NAME, "wrongParticipantId", providerQos2, System.currentTimeMillis(), NO_EXPIRY, publicKeyId, true));
    // use minimal timeout to prevent restarting arbitration
    int discoveryTimeout = 0;
    discoveryQos = new DiscoveryQos(discoveryTimeout, ArbitrationStrategy.Keyword, Long.MAX_VALUE);
    discoveryQos.addCustomParameter(ArbitrationConstants.KEYWORD_PARAMETER, testKeyword);
    try {
        Arbitrator arbitrator = ArbitratorFactory.create(Sets.newHashSet(domain), interfaceName, interfaceVersion, discoveryQos, localDiscoveryAggregator);
        arbitrator.setArbitrationListener(arbitrationCallback);
        arbitrator.scheduleArbitration();
        assertTrue(localDiscoveryAggregatorSemaphore.tryAcquire(1000, TimeUnit.MILLISECONDS));
        verify(arbitrationCallback, times(1)).onError(any(Throwable.class));
        verify(arbitrationCallback, never()).onSuccess(any(ArbitrationResult.class));
    } catch (DiscoveryException e) {
        fail("A Joyn Arbitration Exception has been thrown");
    }
}
Also used : Version(joynr.types.Version) ChannelAddress(joynr.system.RoutingTypes.ChannelAddress) CustomParameter(joynr.types.CustomParameter) DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo) DiscoveryException(io.joynr.exceptions.DiscoveryException) ProviderQos(joynr.types.ProviderQos) Test(org.junit.Test)

Example 20 with Version

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

the class DiscoveryEntryVersionFilterTest method testOnlyIncompatibleVersionsFilteredOut.

@Test
public void testOnlyIncompatibleVersionsFilteredOut() {
    Version callerVersion = new Version(0, 0);
    DiscoveryEntryWithMetaInfo compatibleEntry = mock(DiscoveryEntryWithMetaInfo.class);
    Version compatibleVersion = new Version(0, 1);
    when(compatibleEntry.getProviderVersion()).thenReturn(compatibleVersion);
    when(versionCompatibilityChecker.check(eq(callerVersion), eq(compatibleVersion))).thenReturn(true);
    DiscoveryEntryWithMetaInfo incompatibleEntry = mock(DiscoveryEntryWithMetaInfo.class);
    Version incompatibleVersion = new Version(2, 2);
    when(incompatibleEntry.getProviderVersion()).thenReturn(incompatibleVersion);
    when(versionCompatibilityChecker.check(callerVersion, incompatibleVersion)).thenReturn(false);
    Set<DiscoveryEntryWithMetaInfo> discoveryEntries = Sets.newHashSet(compatibleEntry, incompatibleEntry);
    Set<DiscoveryEntryWithMetaInfo> result = subject.filter(callerVersion, discoveryEntries, null);
    assertNotNull(result);
    assertEquals(1, result.size());
    assertEquals(compatibleEntry, result.iterator().next());
}
Also used : Version(joynr.types.Version) DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo) Test(org.junit.Test)

Aggregations

Version (joynr.types.Version)65 Test (org.junit.Test)47 ProviderQos (joynr.types.ProviderQos)43 DiscoveryEntryWithMetaInfo (joynr.types.DiscoveryEntryWithMetaInfo)29 GlobalDiscoveryEntry (joynr.types.GlobalDiscoveryEntry)24 DiscoveryEntry (joynr.types.DiscoveryEntry)22 ArrayList (java.util.ArrayList)13 ChannelAddress (joynr.system.RoutingTypes.ChannelAddress)13 Matchers.anyString (org.mockito.Matchers.anyString)12 Callback (io.joynr.proxy.Callback)11 HashSet (java.util.HashSet)11 DiscoveryQos (io.joynr.arbitration.DiscoveryQos)10 InvocationOnMock (org.mockito.invocation.InvocationOnMock)10 JoynrVersion (io.joynr.JoynrVersion)9 Address (joynr.system.RoutingTypes.Address)9 HashMap (java.util.HashMap)8 MqttAddress (joynr.system.RoutingTypes.MqttAddress)8 DiscoveryException (io.joynr.exceptions.DiscoveryException)7 Set (java.util.Set)7 DeferredVoid (io.joynr.provider.DeferredVoid)6