use of io.joynr.exceptions.NoCompatibleProviderFoundException 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.NoCompatibleProviderFoundException in project joynr by bmwcarit.
the class ProxyBuilderDefaultImplTest method testNoCompatibleProviderPassedToOnError.
@Test
public void testNoCompatibleProviderPassedToOnError() throws Exception {
final String domain = "domain1";
final Set<String> domains = Sets.newHashSet(domain);
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();
Set<Version> discoveredVersions = Sets.newHashSet(new Version(100, 100));
callback.onError(new NoCompatibleProviderFoundException(TestInterface.INTERFACE_NAME, new Version(1, 1), domain, discoveredVersions));
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 NoCompatibleProviderFoundException);
}
use of io.joynr.exceptions.NoCompatibleProviderFoundException in project joynr by bmwcarit.
the class ArbitrationTest method testIncompatibleVersionsReported.
@Test
public void testIncompatibleVersionsReported() throws InterruptedException {
Version incompatibleVersion = new Version(100, 100);
final Collection<DiscoveryEntryWithMetaInfo> discoveryEntries = Lists.newArrayList(new DiscoveryEntryWithMetaInfo(incompatibleVersion, domain, interfaceName, "first-participant", new ProviderQos(), System.currentTimeMillis(), NO_EXPIRY, "public-key-1", true));
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<DiscoveryEntryWithMetaInfo>>() {
@SuppressWarnings("unchecked")
@Override
public Set<DiscoveryEntryWithMetaInfo> answer(InvocationOnMock invocation) throws Throwable {
Map<String, Set<Version>> filteredVersions = (Map<String, Set<Version>>) invocation.getArguments()[2];
Set<DiscoveryEntryWithMetaInfo> discoveryEntries = (Set<DiscoveryEntryWithMetaInfo>) invocation.getArguments()[1];
filteredVersions.put(domain, Sets.newHashSet(discoveryEntries.iterator().next().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[1]));
localDiscoveryAggregatorSemaphore.release();
return null;
}
}).when(localDiscoveryAggregator).lookup(Mockito.<Callback<DiscoveryEntryWithMetaInfo[]>>any(), eq(new String[] { domain }), eq(interfaceName), Mockito.<joynr.types.DiscoveryQos>any());
Arbitrator arbitrator = ArbitratorFactory.create(Sets.newHashSet(domain), interfaceName, interfaceVersion, discoveryQos, localDiscoveryAggregator);
arbitrator.setArbitrationListener(arbitrationCallback);
arbitrator.scheduleArbitration();
assertTrue(localDiscoveryAggregatorSemaphore.tryAcquire(1000, TimeUnit.MILLISECONDS));
Set<Version> discoveredVersions = Sets.newHashSet(incompatibleVersion);
ArgumentCaptor<NoCompatibleProviderFoundException> noCompatibleProviderFoundExceptionCaptor = ArgumentCaptor.forClass(NoCompatibleProviderFoundException.class);
verify(arbitrationCallback).onError(noCompatibleProviderFoundExceptionCaptor.capture());
assertEquals(discoveredVersions, noCompatibleProviderFoundExceptionCaptor.getValue().getDiscoveredVersions());
}
Aggregations