Search in sources :

Example 1 with MultiDomainNoCompatibleProviderFoundException

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);
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) MultiDomainNoCompatibleProviderFoundException(io.joynr.exceptions.MultiDomainNoCompatibleProviderFoundException) NoCompatibleProviderFoundException(io.joynr.exceptions.NoCompatibleProviderFoundException) ArbitrationCallback(io.joynr.arbitration.ArbitrationCallback) MultiDomainNoCompatibleProviderFoundException(io.joynr.exceptions.MultiDomainNoCompatibleProviderFoundException) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) Callable(java.util.concurrent.Callable) JoynrVersion(io.joynr.JoynrVersion) Version(joynr.types.Version) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ExecutorService(java.util.concurrent.ExecutorService) Test(org.junit.Test)

Example 2 with 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));
}
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)

Aggregations

MultiDomainNoCompatibleProviderFoundException (io.joynr.exceptions.MultiDomainNoCompatibleProviderFoundException)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 Version (joynr.types.Version)2 Test (org.junit.Test)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 JoynrVersion (io.joynr.JoynrVersion)1 ArbitrationCallback (io.joynr.arbitration.ArbitrationCallback)1 JoynrRuntimeException (io.joynr.exceptions.JoynrRuntimeException)1 NoCompatibleProviderFoundException (io.joynr.exceptions.NoCompatibleProviderFoundException)1 Map (java.util.Map)1 Callable (java.util.concurrent.Callable)1 ExecutorService (java.util.concurrent.ExecutorService)1 DiscoveryEntry (joynr.types.DiscoveryEntry)1 DiscoveryEntryWithMetaInfo (joynr.types.DiscoveryEntryWithMetaInfo)1 ProviderQos (joynr.types.ProviderQos)1