Search in sources :

Example 1 with NoCompatibleProviderFoundException

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

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