use of io.joynr.exceptions.MultiDomainNoCompatibleProviderFoundException in project joynr by bmwcarit.
the class ProxyBuilderDefaultImplTest method testMultiDomainNoCompatibleProviderFoundSetOnInvocationHandler.
@Test
public void testMultiDomainNoCompatibleProviderFoundSetOnInvocationHandler() throws Exception {
final Set<String> domains = Sets.newHashSet("domain-1", "domain-2");
setup(domains);
final ExecutorService executor = Executors.newSingleThreadExecutor();
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
executor.submit(new Callable<Void>() {
@Override
public Void call() throws Exception {
Thread.sleep(10L);
verify(arbitrator).setArbitrationListener(arbitrationCallbackCaptor.capture());
ArbitrationCallback callback = arbitrationCallbackCaptor.getValue();
Map<String, Set<Version>> versionsByDomain = new HashMap<>();
HashSet<Version> discoveredVersions = Sets.newHashSet(new Version(100, 100));
Map<String, NoCompatibleProviderFoundException> exceptionsByDomain = Maps.newHashMap();
for (String domain : domains) {
versionsByDomain.put(domain, discoveredVersions);
exceptionsByDomain.put(domain, new NoCompatibleProviderFoundException("interfaceName", new Version(1, 1), domain, discoveredVersions));
}
callback.onError(new MultiDomainNoCompatibleProviderFoundException(exceptionsByDomain));
return null;
}
});
return null;
}
}).when(arbitrator).scheduleArbitration();
subject.build(proxyCreatedCallback);
executor.shutdown();
executor.awaitTermination(100L, TimeUnit.MILLISECONDS);
verify(proxyCreatedCallback).onProxyCreationError(exceptionCaptor.capture());
JoynrRuntimeException capturedException = exceptionCaptor.getValue();
assertTrue(capturedException instanceof MultiDomainNoCompatibleProviderFoundException);
}
use of io.joynr.exceptions.MultiDomainNoCompatibleProviderFoundException 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));
}
Aggregations