Search in sources :

Example 31 with DiscoveryEntry

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

the class ArbitrationTest method setUp.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Before
public void setUp() throws Exception {
    initMocks(this);
    capabilitiesList = new ArrayList<DiscoveryEntryWithMetaInfo>();
    doAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            Object[] arguments = invocation.getArguments();
            assert (arguments[0] instanceof Callback);
            ((Callback) arguments[0]).resolve((Object) capabilitiesList.toArray(new DiscoveryEntryWithMetaInfo[0]));
            localDiscoveryAggregatorSemaphore.release();
            return null;
        }
    }).when(localDiscoveryAggregator).lookup(Mockito.<Callback>any(), eq(new String[] { domain }), eq(interfaceName), Mockito.<joynr.types.DiscoveryQos>any());
    Field discoveryEntryVersionFilterField = ArbitratorFactory.class.getDeclaredField("discoveryEntryVersionFilter");
    discoveryEntryVersionFilterField.setAccessible(true);
    discoveryEntryVersionFilterField.set(ArbitratorFactory.class, discoveryEntryVersionFilter);
    doAnswer(new Answer<Set<DiscoveryEntry>>() {

        @Override
        public Set<DiscoveryEntry> answer(InvocationOnMock invocation) throws Throwable {
            return (Set<DiscoveryEntry>) invocation.getArguments()[1];
        }
    }).when(discoveryEntryVersionFilter).filter(Mockito.<Version>any(), Mockito.<Set<DiscoveryEntryWithMetaInfo>>any(), Mockito.<Map<String, Set<Version>>>any());
    Field schedulerField = ArbitratorFactory.class.getDeclaredField("scheduler");
    schedulerField.setAccessible(true);
    String name = "TEST.joynr.scheduler.arbitration.arbitratorRunnable";
    ThreadFactory joynrThreadFactory = new JoynrThreadFactory(name, true);
    scheduler = Executors.newSingleThreadScheduledExecutor(joynrThreadFactory);
    schedulerField.set(ArbitratorFactory.class, scheduler);
    Field shutdownNotifierField = ArbitratorFactory.class.getDeclaredField("shutdownNotifier");
    shutdownNotifierField.setAccessible(true);
    shutdownNotifierField.set(ArbitratorFactory.class, shutdownNotifier);
    ArbitratorFactory.start();
    verify(shutdownNotifier).registerForShutdown(any(ShutdownListener.class));
}
Also used : JoynrThreadFactory(io.joynr.runtime.JoynrThreadFactory) ThreadFactory(java.util.concurrent.ThreadFactory) DiscoveryEntry(joynr.types.DiscoveryEntry) Set(java.util.Set) HashSet(java.util.HashSet) ShutdownListener(io.joynr.runtime.ShutdownListener) Field(java.lang.reflect.Field) Callback(io.joynr.proxy.Callback) InvocationOnMock(org.mockito.invocation.InvocationOnMock) JoynrThreadFactory(io.joynr.runtime.JoynrThreadFactory) DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo) Before(org.junit.Before)

Example 32 with DiscoveryEntry

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

the class ArbitrationTest method testMultiDomainIncompatibleVersionsReported.

@Test
public void testMultiDomainIncompatibleVersionsReported() throws InterruptedException {
    final Version incompatibleVersion = new Version(100, 100);
    final String domain1 = "domain1";
    final String domain2 = "domain2";
    final DiscoveryEntryWithMetaInfo discoveryEntry1 = new DiscoveryEntryWithMetaInfo(incompatibleVersion, domain1, interfaceName, "participant1", new ProviderQos(), System.currentTimeMillis(), NO_EXPIRY, "public-key-1", true);
    final DiscoveryEntryWithMetaInfo discoveryEntry2 = new DiscoveryEntryWithMetaInfo(incompatibleVersion, domain2, interfaceName, "participant2", new ProviderQos(), System.currentTimeMillis(), NO_EXPIRY, "public-key-2", true);
    final Collection<DiscoveryEntryWithMetaInfo> discoveryEntries = Lists.newArrayList(discoveryEntry1, discoveryEntry2);
    ArbitrationStrategyFunction arbitrationStrategyFunction = mock(ArbitrationStrategyFunction.class);
    when(arbitrationStrategyFunction.select(Mockito.<Map<String, String>>any(), Mockito.<Collection<DiscoveryEntryWithMetaInfo>>any())).thenReturn(new HashSet<DiscoveryEntryWithMetaInfo>());
    doAnswer(new Answer<Set<DiscoveryEntry>>() {

        @SuppressWarnings("unchecked")
        @Override
        public Set<DiscoveryEntry> answer(InvocationOnMock invocation) throws Throwable {
            Set<DiscoveryEntry> discoveryEntries = (Set<DiscoveryEntry>) invocation.getArguments()[1];
            Map<String, Set<Version>> filteredVersions = (Map<String, Set<Version>>) invocation.getArguments()[2];
            filteredVersions.put(domain1, Sets.newHashSet(discoveryEntry1.getProviderVersion()));
            filteredVersions.put(domain2, Sets.newHashSet(discoveryEntry2.getProviderVersion()));
            discoveryEntries.clear();
            return new HashSet<>();
        }
    }).when(discoveryEntryVersionFilter).filter(Mockito.<Version>any(), Mockito.<Set<DiscoveryEntryWithMetaInfo>>any(), Mockito.<Map<String, Set<Version>>>any());
    DiscoveryQos discoveryQos = new DiscoveryQos(10L, arbitrationStrategyFunction, 0L);
    reset(localDiscoveryAggregator);
    doAnswer(new Answer<Object>() {

        @SuppressWarnings("unchecked")
        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            ((Callback<DiscoveryEntryWithMetaInfo[]>) invocation.getArguments()[0]).resolve((Object) discoveryEntries.toArray(new DiscoveryEntryWithMetaInfo[2]));
            localDiscoveryAggregatorSemaphore.release();
            return null;
        }
    }).when(localDiscoveryAggregator).lookup(Mockito.<Callback<DiscoveryEntryWithMetaInfo[]>>any(), any(String[].class), eq(interfaceName), Mockito.<joynr.types.DiscoveryQos>any());
    Arbitrator arbitrator = ArbitratorFactory.create(Sets.newHashSet(domain1, domain2), interfaceName, interfaceVersion, discoveryQos, localDiscoveryAggregator);
    arbitrator.setArbitrationListener(arbitrationCallback);
    arbitrator.scheduleArbitration();
    assertTrue(localDiscoveryAggregatorSemaphore.tryAcquire(1000, TimeUnit.MILLISECONDS));
    Set<Version> discoveredVersions = Sets.newHashSet(incompatibleVersion);
    ArgumentCaptor<MultiDomainNoCompatibleProviderFoundException> noCompatibleProviderFoundExceptionCaptor = ArgumentCaptor.forClass(MultiDomainNoCompatibleProviderFoundException.class);
    verify(arbitrationCallback).onError(noCompatibleProviderFoundExceptionCaptor.capture());
    assertEquals(discoveredVersions, noCompatibleProviderFoundExceptionCaptor.getValue().getDiscoveredVersionsForDomain(domain2));
    assertEquals(discoveredVersions, noCompatibleProviderFoundExceptionCaptor.getValue().getDiscoveredVersionsForDomain(domain1));
}
Also used : DiscoveryEntry(joynr.types.DiscoveryEntry) Set(java.util.Set) HashSet(java.util.HashSet) MultiDomainNoCompatibleProviderFoundException(io.joynr.exceptions.MultiDomainNoCompatibleProviderFoundException) Version(joynr.types.Version) InvocationOnMock(org.mockito.invocation.InvocationOnMock) DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo) Map(java.util.Map) HashMap(java.util.HashMap) ProviderQos(joynr.types.ProviderQos) Test(org.junit.Test)

Example 33 with DiscoveryEntry

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

the class StaticCapabilitiesProvisioning method addAddressesToRoutingTable.

private void addAddressesToRoutingTable(RoutingTable routingTable) {
    for (DiscoveryEntry discoveryEntry : discoveryEntries) {
        if (discoveryEntry instanceof GlobalDiscoveryEntry) {
            GlobalDiscoveryEntry globalDiscoveryEntry = (GlobalDiscoveryEntry) discoveryEntry;
            boolean isGloballyVisible = (globalDiscoveryEntry.getQos().getScope() == ProviderScope.GLOBAL);
            final long expiryDateMs = Long.MAX_VALUE;
            final boolean isSticky = true;
            final boolean allowUpdate = false;
            routingTable.put(globalDiscoveryEntry.getParticipantId(), CapabilityUtils.getAddressFromGlobalDiscoveryEntry(globalDiscoveryEntry), isGloballyVisible, expiryDateMs, isSticky, allowUpdate);
        }
    }
}
Also used : DiscoveryEntry(joynr.types.DiscoveryEntry) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry)

Example 34 with DiscoveryEntry

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

the class CapabilitiesUtilsTest method testConvertDiscoveryEntryWithMetaInfoToDiscoveryEntry.

@Test
public void testConvertDiscoveryEntryWithMetaInfoToDiscoveryEntry() {
    boolean isLocal = true;
    DiscoveryEntryWithMetaInfo discoveryEntry = new DiscoveryEntryWithMetaInfo(new Version(42, 23), "testDomain", "testInterfaceName", "testParticipantId", new ProviderQos(), 4711l, 4712l, "testPublicKeyId", isLocal);
    DiscoveryEntry convertedEntry = CapabilityUtils.convertToDiscoveryEntry(discoveryEntry);
    assertTrue(DiscoveryEntry.class.equals(convertedEntry.getClass()));
    compareDiscoveryEntries(isLocal, convertedEntry, discoveryEntry);
}
Also used : DiscoveryEntry(joynr.types.DiscoveryEntry) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) Version(joynr.types.Version) DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo) ProviderQos(joynr.types.ProviderQos) Test(org.junit.Test)

Example 35 with DiscoveryEntry

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

the class CapabilitiesUtilsTest method testConvertGlobalDiscoveryEntryToDiscoveryEntryWithMetaInfo.

@Test
public void testConvertGlobalDiscoveryEntryToDiscoveryEntryWithMetaInfo() {
    boolean isLocal = false;
    DiscoveryEntry discoveryEntry = new DiscoveryEntry(new Version(42, 23), "testDomain", "testInterfaceName", "testParticipantId", new ProviderQos(), 4711l, 4712l, "testPublicKeyId");
    GlobalDiscoveryEntry globalDiscoveryEntry = CapabilityUtils.discoveryEntry2GlobalDiscoveryEntry(discoveryEntry, new MqttAddress());
    DiscoveryEntryWithMetaInfo convertedEntry = CapabilityUtils.convertToDiscoveryEntryWithMetaInfo(isLocal, discoveryEntry);
    compareDiscoveryEntries(isLocal, discoveryEntry, convertedEntry);
    DiscoveryEntryWithMetaInfo convertedGlobalEntry = CapabilityUtils.convertToDiscoveryEntryWithMetaInfo(isLocal, globalDiscoveryEntry);
    compareDiscoveryEntries(isLocal, globalDiscoveryEntry, convertedGlobalEntry);
}
Also used : DiscoveryEntry(joynr.types.DiscoveryEntry) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) Version(joynr.types.Version) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo) ProviderQos(joynr.types.ProviderQos) MqttAddress(joynr.system.RoutingTypes.MqttAddress) Test(org.junit.Test)

Aggregations

DiscoveryEntry (joynr.types.DiscoveryEntry)60 GlobalDiscoveryEntry (joynr.types.GlobalDiscoveryEntry)43 Test (org.junit.Test)30 ProviderQos (joynr.types.ProviderQos)25 Version (joynr.types.Version)22 Callback (io.joynr.proxy.Callback)18 Matchers.anyString (org.mockito.Matchers.anyString)17 DiscoveryEntryWithMetaInfo (joynr.types.DiscoveryEntryWithMetaInfo)16 DiscoveryQos (io.joynr.arbitration.DiscoveryQos)15 ArrayList (java.util.ArrayList)14 HashSet (java.util.HashSet)9 InvocationOnMock (org.mockito.invocation.InvocationOnMock)9 DeferredVoid (io.joynr.provider.DeferredVoid)7 JoynrRuntimeException (io.joynr.exceptions.JoynrRuntimeException)6 MqttAddress (joynr.system.RoutingTypes.MqttAddress)6 Injector (com.google.inject.Injector)5 MessagingQos (io.joynr.messaging.MessagingQos)4 Future (io.joynr.proxy.Future)4 CheckForNull (javax.annotation.CheckForNull)4 ChannelAddress (joynr.system.RoutingTypes.ChannelAddress)4