Search in sources :

Example 11 with Version

use of joynr.types.Version in project joynr by bmwcarit.

the class AttributePollInterpreter method execute.

@Nonnull
public Promise<?> execute(ProviderContainer providerContainer, Method method) {
    String interfaceName = providerContainer.getInterfaceName();
    Object returnValueFromProvider = null;
    try {
        returnValueFromProvider = method.invoke(providerContainer.getProviderProxy());
    } catch (IllegalAccessException e) {
        String message = String.format("Method \"%s\" is not accessible on \"%s\" provider (exception: \"%s\").", method.getName(), interfaceName, e.toString());
        logger.error(message, e);
        JoynrVersion joynrVersion = AnnotationUtil.getAnnotation(providerContainer.getProviderProxy().getClass(), JoynrVersion.class);
        throw new MethodInvocationException(message, new Version(joynrVersion.major(), joynrVersion.minor()));
    } catch (IllegalArgumentException e) {
        String message = String.format("Provider of interface \"%s\" does not declare method \"%s\" (exception: \"%s\")", interfaceName, method.getName(), e.toString());
        logger.error(message, e);
        JoynrVersion joynrVersion = AnnotationUtil.getAnnotation(providerContainer.getProviderProxy().getClass(), JoynrVersion.class);
        throw new MethodInvocationException(message, new Version(joynrVersion.major(), joynrVersion.minor()));
    } catch (InvocationTargetException e) {
        Throwable cause = e.getCause();
        String message = String.format("Calling method \"%s\" on \"%s\" provider threw an exception: \"%s\"", method.getName(), interfaceName, cause == null ? e.toString() : cause.toString());
        logger.error(message, e);
        throw new ProviderRuntimeException(cause == null ? e.toString() : cause.toString());
    } catch (Exception e) {
        String message = String.format("Calling method \"%s\" on \"%s\" provider threw an unexpected exception: \"%s\"", method.getName(), interfaceName, e.toString());
        logger.error(message, e);
        JoynrVersion joynrVersion = AnnotationUtil.getAnnotation(providerContainer.getProviderProxy().getClass(), JoynrVersion.class);
        throw new MethodInvocationException(message, new Version(joynrVersion.major(), joynrVersion.minor()));
    }
    if (returnValueFromProvider == null) {
        String message = String.format("Calling method \"%s\" on \"%s\" provider returned \"null\".", method.getName(), interfaceName);
        logger.error(message);
        throw new JoynrRuntimeException(message);
    }
    Promise<?> returnedPromiseFromProvider = null;
    try {
        returnedPromiseFromProvider = (Promise<?>) returnValueFromProvider;
    } catch (ClassCastException e) {
        String message = String.format("Calling method \"%s\" on \"%s\" provider did not return a promise.", method.getName(), interfaceName);
        logger.error(message, e);
        throw new JoynrRuntimeException(message, e);
    }
    return returnedPromiseFromProvider;
}
Also used : JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) InvocationTargetException(java.lang.reflect.InvocationTargetException) MethodInvocationException(joynr.exceptions.MethodInvocationException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ProviderRuntimeException(joynr.exceptions.ProviderRuntimeException) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) JoynrVersion(io.joynr.JoynrVersion) JoynrVersion(io.joynr.JoynrVersion) Version(joynr.types.Version) MethodInvocationException(joynr.exceptions.MethodInvocationException) ProviderRuntimeException(joynr.exceptions.ProviderRuntimeException) Nonnull(javax.annotation.Nonnull)

Example 12 with Version

use of joynr.types.Version 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 13 with Version

use of joynr.types.Version 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 14 with Version

use of joynr.types.Version in project joynr by bmwcarit.

the class ProxyTest method setUp.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Before
public void setUp() throws Exception {
    navigationProxyCreatedSemaphore = new Semaphore(0);
    navigationProxyCreatedCallback = new ProxyCreatedCallback<NavigationProxy>() {

        @Override
        public void onProxyCreationFinished(NavigationProxy result) {
            navigationProxyCreatedSemaphore.release();
        }

        @Override
        public void onProxyCreationError(JoynrRuntimeException error) {
            fail("Navigation proxy creation failed: " + error);
        }
    };
    testInterfaceProxyCreatedSemaphore = new Semaphore(0);
    testInterfaceProxyCreatedCallback = new ProxyCreatedCallback<TestInterface>() {

        @Override
        public void onProxyCreationFinished(TestInterface result) {
            testInterfaceProxyCreatedSemaphore.release();
        }

        @Override
        public void onProxyCreationError(JoynrRuntimeException error) {
            fail("TestInterface proxy creation failed: " + error);
        }
    };
    domain = "TestDomain";
    fromParticipantId = "ProxyTestFromParticipantId";
    toParticipantId = "ProxyTestToParticipantId";
    toDiscoveryEntry = new DiscoveryEntryWithMetaInfo(new Version(47, 11), domain, TestInterface.INTERFACE_NAME, toParticipantId, new ProviderQos(), System.currentTimeMillis(), System.currentTimeMillis() + ONE_MINUTE_IN_MS, "publicKeyId", true);
    toDiscoveryEntries = new HashSet<DiscoveryEntryWithMetaInfo>();
    toDiscoveryEntries.add(toDiscoveryEntry);
    MockitoAnnotations.initMocks(this);
    Injector injector = Guice.createInjector(new AbstractModule() {

        @Override
        protected void configure() {
            requestStaticInjection(RpcUtils.class);
            bind(ReplyCallerDirectory.class).toInstance(replyCallerDirectory);
            bind(RequestReplyManager.class).toInstance(requestReplyManager);
            bind(SubscriptionManager.class).toInstance(subscriptionManager);
            bind(MessageRouter.class).toInstance(messageRouter);
            bind(RoutingTable.class).toInstance(routingTable);
            install(new FactoryModuleBuilder().implement(ProxyInvocationHandler.class, ProxyInvocationHandlerImpl.class).build(ProxyInvocationHandlerFactory.class));
        }

        @Provides
        @Singleton
        @Named(SystemServicesSettings.PROPERTY_DISPATCHER_ADDRESS)
        Address getDispatcherAddress() {
            return new InProcessAddress();
        }
    });
    proxyBuilderFactory = new ProxyBuilderFactoryImpl(localDiscoveryAggregator, injector.getInstance(ProxyInvocationHandlerFactory.class), MAX_TTL_MS, DISCOVERY_TIMEOUT_MS, RETRY_INTERVAL_MS);
    Mockito.doAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) {
            Object[] args = invocation.getArguments();
            DiscoveryEntryWithMetaInfo[] fakeCapabilitiesResult = { toDiscoveryEntry };
            ((Callback) args[0]).resolve((Object) fakeCapabilitiesResult);
            return null;
        }
    }).when(localDiscoveryAggregator).lookup(Mockito.<Callback>any(), Mockito.<String[]>any(), Mockito.<String>any(), Mockito.<joynr.types.DiscoveryQos>any());
    Mockito.doAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) {
            Object[] args = invocation.getArguments();
            AttributeSubscribeInvocation request = (AttributeSubscribeInvocation) args[2];
            if (request.getSubscriptionId() == null) {
                request.setSubscriptionId(UUID.randomUUID().toString());
            }
            request.getFuture().resolve(request.getSubscriptionId());
            return null;
        }
    }).when(subscriptionManager).registerAttributeSubscription(any(String.class), eq(Sets.newHashSet(toDiscoveryEntry)), Mockito.any(AttributeSubscribeInvocation.class));
    Mockito.doAnswer(new // TODO simulate resolve here ! subscription reply bastern ... handle subscriptionreply ausführen..
    Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) {
            Object[] args = invocation.getArguments();
            BroadcastSubscribeInvocation request = (BroadcastSubscribeInvocation) args[2];
            if (request.getSubscriptionId() == null) {
                request.setSubscriptionId(UUID.randomUUID().toString());
            }
            request.getFuture().resolve(request.getSubscriptionId());
            return null;
        }
    }).when(subscriptionManager).registerBroadcastSubscription(any(String.class), eq(Sets.newHashSet(toDiscoveryEntry)), Mockito.any(BroadcastSubscribeInvocation.class));
    Mockito.doAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) {
            Object[] args = invocation.getArguments();
            MulticastSubscribeInvocation request = (MulticastSubscribeInvocation) args[2];
            if (request.getSubscriptionId() == null) {
                request.setSubscriptionId(UUID.randomUUID().toString());
            }
            request.getFuture().resolve(request.getSubscriptionId());
            return null;
        }
    }).when(subscriptionManager).registerMulticastSubscription(any(String.class), eq(Sets.newHashSet(toDiscoveryEntry)), Mockito.any(MulticastSubscribeInvocation.class));
    discoveryQos = new DiscoveryQos(10000, ArbitrationStrategy.HighestPriority, Long.MAX_VALUE);
    messagingQos = new MessagingQos();
    doAnswer(new Answer<Set<DiscoveryEntryWithMetaInfo>>() {

        @Override
        public Set<DiscoveryEntryWithMetaInfo> answer(InvocationOnMock invocation) throws Throwable {
            return (Set<DiscoveryEntryWithMetaInfo>) invocation.getArguments()[1];
        }
    }).when(discoveryEntryVersionFilter).filter(Mockito.<Version>any(), Mockito.<Set<DiscoveryEntryWithMetaInfo>>any(), Mockito.<Map<String, Set<Version>>>any());
    Field discoveryEntryVersionFilterField = ArbitratorFactory.class.getDeclaredField("discoveryEntryVersionFilter");
    discoveryEntryVersionFilterField.setAccessible(true);
    discoveryEntryVersionFilterField.set(ArbitratorFactory.class, discoveryEntryVersionFilter);
    doAnswer(new Answer<Set<DiscoveryEntryWithMetaInfo>>() {

        @Override
        public Set<DiscoveryEntryWithMetaInfo> answer(InvocationOnMock invocation) throws Throwable {
            return (Set<DiscoveryEntryWithMetaInfo>) 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));
}
Also used : JoynrThreadFactory(io.joynr.runtime.JoynrThreadFactory) ThreadFactory(java.util.concurrent.ThreadFactory) RpcUtils(io.joynr.dispatching.rpc.RpcUtils) Set(java.util.Set) HashSet(java.util.HashSet) InProcessAddress(io.joynr.messaging.inprocess.InProcessAddress) Address(joynr.system.RoutingTypes.Address) InProcessAddress(io.joynr.messaging.inprocess.InProcessAddress) FactoryModuleBuilder(com.google.inject.assistedinject.FactoryModuleBuilder) MulticastSubscribeInvocation(io.joynr.proxy.invocation.MulticastSubscribeInvocation) Semaphore(java.util.concurrent.Semaphore) Matchers.anyString(org.mockito.Matchers.anyString) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) ShutdownListener(io.joynr.runtime.ShutdownListener) Field(java.lang.reflect.Field) MessagingQos(io.joynr.messaging.MessagingQos) BroadcastSubscribeInvocation(io.joynr.proxy.invocation.BroadcastSubscribeInvocation) JoynrVersion(io.joynr.JoynrVersion) Version(joynr.types.Version) Injector(com.google.inject.Injector) JoynrThreadFactory(io.joynr.runtime.JoynrThreadFactory) NavigationProxy(joynr.vehicle.NavigationProxy) Named(com.google.inject.name.Named) AttributeSubscribeInvocation(io.joynr.proxy.invocation.AttributeSubscribeInvocation) Provides(com.google.inject.Provides) DiscoveryQos(io.joynr.arbitration.DiscoveryQos) AbstractModule(com.google.inject.AbstractModule) Singleton(com.google.inject.Singleton) InvocationOnMock(org.mockito.invocation.InvocationOnMock) DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo) ProviderQos(joynr.types.ProviderQos) Before(org.junit.Before)

Example 15 with Version

use of joynr.types.Version in project joynr by bmwcarit.

the class LocalDiscoveryAggregatorTest method passesUnknownEntry.

@SuppressWarnings("unchecked")
@Test
public void passesUnknownEntry() {
    DiscoveryEntry discoveryEntry = new DiscoveryEntry(new Version(0, 0), "anyDomain", "anyInterface", "anyParticipant", new ProviderQos(), System.currentTimeMillis(), expiryDateMs, publicKeyId);
    localDiscoveryAggregator.add(addCallback, discoveryEntry);
    verify(discoveryProxyMock, times(1)).add(any(Callback.class), eq(discoveryEntry));
}
Also used : DiscoveryEntry(joynr.types.DiscoveryEntry) Callback(io.joynr.proxy.Callback) Version(joynr.types.Version) ProviderQos(joynr.types.ProviderQos) Test(org.junit.Test)

Aggregations

Version (joynr.types.Version)65 Test (org.junit.Test)47 ProviderQos (joynr.types.ProviderQos)43 DiscoveryEntryWithMetaInfo (joynr.types.DiscoveryEntryWithMetaInfo)29 GlobalDiscoveryEntry (joynr.types.GlobalDiscoveryEntry)24 DiscoveryEntry (joynr.types.DiscoveryEntry)22 ArrayList (java.util.ArrayList)13 ChannelAddress (joynr.system.RoutingTypes.ChannelAddress)13 Matchers.anyString (org.mockito.Matchers.anyString)12 Callback (io.joynr.proxy.Callback)11 HashSet (java.util.HashSet)11 DiscoveryQos (io.joynr.arbitration.DiscoveryQos)10 InvocationOnMock (org.mockito.invocation.InvocationOnMock)10 JoynrVersion (io.joynr.JoynrVersion)9 Address (joynr.system.RoutingTypes.Address)9 HashMap (java.util.HashMap)8 MqttAddress (joynr.system.RoutingTypes.MqttAddress)8 DiscoveryException (io.joynr.exceptions.DiscoveryException)7 Set (java.util.Set)7 DeferredVoid (io.joynr.provider.DeferredVoid)6