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));
}
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));
}
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);
}
}
}
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);
}
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);
}
Aggregations