Search in sources :

Example 6 with Request

use of joynr.Request in project joynr by bmwcarit.

the class ConnectorTest method syncMethodCallCallsRequestReplyManagerWithCorrectArguments.

@Test
public void syncMethodCallCallsRequestReplyManagerWithCorrectArguments() {
    ConnectorInvocationHandler connector = createConnector();
    assertNotNull(connector);
    ArgumentCaptor<Request> requestCaptor = ArgumentCaptor.forClass(Request.class);
    try {
        Method method = TestSyncInterface.class.getDeclaredMethod("methodWithoutParameters");
        when(requestReplyManager.sendSyncRequest(any(String.class), any(DiscoveryEntryWithMetaInfo.class), any(Request.class), any(SynchronizedReplyCaller.class), any(MessagingQos.class))).thenReturn(new Reply());
        connector.executeSyncMethod(method, new Object[] {});
        verify(requestReplyManager, times(1)).sendSyncRequest(eq(fromParticipantId), eq(toDiscoveryEntry), requestCaptor.capture(), isA(SynchronizedReplyCaller.class), eq(qosSettings));
        Request actualRequest = requestCaptor.getValue();
        Request expectedRequest = new Request(method.getName(), new Object[] {}, new String[] {}, actualRequest.getRequestReplyId());
        assertEquals(expectedRequest, actualRequest);
    } catch (Exception e) {
        fail("Unexpected exception from sync method call: " + e);
    }
}
Also used : MessagingQos(io.joynr.messaging.MessagingQos) OneWayRequest(joynr.OneWayRequest) Request(joynr.Request) Reply(joynr.Reply) Method(java.lang.reflect.Method) SynchronizedReplyCaller(io.joynr.dispatching.rpc.SynchronizedReplyCaller) DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo) SubscriptionException(io.joynr.exceptions.SubscriptionException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) JoynrIllegalStateException(io.joynr.exceptions.JoynrIllegalStateException) Test(org.junit.Test)

Example 7 with Request

use of joynr.Request in project joynr by bmwcarit.

the class ConnectorTest method asyncMethodCallCallsRequestReplyManagerWithCorrectArguments.

@Test
public void asyncMethodCallCallsRequestReplyManagerWithCorrectArguments() {
    ConnectorInvocationHandler connector = createConnector();
    assertNotNull(connector);
    ArgumentCaptor<Request> requestCaptor = ArgumentCaptor.forClass(Request.class);
    Future<Void> future = new Future<Void>();
    try {
        Method method = TestAsyncInterface.class.getDeclaredMethod("methodWithoutParameters", Callback.class);
        connector.executeAsyncMethod(method, new Object[] { voidCallback }, future);
        verify(requestReplyManager, times(1)).sendRequest(eq(fromParticipantId), eq(toDiscoveryEntry), requestCaptor.capture(), eq(qosSettings));
        Request actualRequest = requestCaptor.getValue();
        Request expectedRequest = new Request(method.getName(), new Object[] {}, new String[] {}, actualRequest.getRequestReplyId());
        assertEquals(expectedRequest, actualRequest);
    } catch (Exception e) {
        fail("Unexpected exception from async method call: " + e);
    }
}
Also used : OneWayRequest(joynr.OneWayRequest) Request(joynr.Request) Method(java.lang.reflect.Method) SubscriptionException(io.joynr.exceptions.SubscriptionException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) JoynrIllegalStateException(io.joynr.exceptions.JoynrIllegalStateException) Test(org.junit.Test)

Example 8 with Request

use of joynr.Request in project joynr by bmwcarit.

the class TtlUpliftTest method setUp.

@Before
public void setUp() throws NoSuchMethodException, SecurityException {
    fromParticipantId = "sender";
    toParticipantId = "receiver";
    cleanupScheduler = new ScheduledThreadPoolExecutor(1);
    cleanupSchedulerSpy = Mockito.spy(cleanupScheduler);
    Module defaultModule = Modules.override(new JoynrPropertiesModule(new Properties())).with(new JsonMessageSerializerModule(), new AbstractModule() {

        @Override
        protected void configure() {
            bind(Long.class).annotatedWith(Names.named(ConfigurableMessagingSettings.PROPERTY_TTL_UPLIFT_MS)).toInstance(NO_TTL_UPLIFT);
            requestStaticInjection(Request.class);
            Multibinder<JoynrMessageProcessor> joynrMessageProcessorMultibinder = Multibinder.newSetBinder(binder(), new TypeLiteral<JoynrMessageProcessor>() {
            });
            joynrMessageProcessorMultibinder.addBinding().toInstance(new JoynrMessageProcessor() {

                @Override
                public MutableMessage processOutgoing(MutableMessage joynrMessage) {
                    return joynrMessage;
                }

                @Override
                public ImmutableMessage processIncoming(ImmutableMessage joynrMessage) {
                    return joynrMessage;
                }
            });
            bind(PublicationManager.class).to(PublicationManagerImpl.class);
            bind(SubscriptionRequestStorage.class).toInstance(Mockito.mock(FileSubscriptionRequestStorage.class));
            bind(AttributePollInterpreter.class).toInstance(attributePollInterpreter);
            bind(Dispatcher.class).toInstance(dispatcher);
            bind(ProviderDirectory.class).toInstance(providerDirectory);
            bind(ScheduledExecutorService.class).annotatedWith(Names.named(JoynrInjectionConstants.JOYNR_SCHEDULER_CLEANUP)).toInstance(cleanupSchedulerSpy);
        }
    });
    Injector injector = Guice.createInjector(defaultModule);
    messageFactory = injector.getInstance(MutableMessageFactory.class);
    Module ttlUpliftModule = Modules.override(defaultModule).with(new AbstractModule() {

        @Override
        protected void configure() {
            bind(Long.class).annotatedWith(Names.named(ConfigurableMessagingSettings.PROPERTY_TTL_UPLIFT_MS)).toInstance(TTL_UPLIFT_MS);
        }
    });
    Injector injectorWithTtlUplift = Guice.createInjector(ttlUpliftModule);
    messageFactoryWithTtlUplift = injectorWithTtlUplift.getInstance(MutableMessageFactory.class);
    requestCaller = new RequestCallerFactory().create(provider);
    when(providerContainer.getProviderProxy()).thenReturn(requestCaller.getProxy());
    when(providerContainer.getSubscriptionPublisher()).thenReturn(subscriptionPublisher);
    Deferred<String> valueToPublishDeferred = new Deferred<String>();
    valueToPublishDeferred.resolve(valueToPublish);
    Promise<Deferred<String>> valueToPublishPromise = new Promise<Deferred<String>>(valueToPublishDeferred);
    doReturn(valueToPublishPromise).when(attributePollInterpreter).execute(any(ProviderContainer.class), any(Method.class));
    Module subcriptionUpliftModule = Modules.override(defaultModule).with(new AbstractModule() {

        @Override
        protected void configure() {
            bind(Long.class).annotatedWith(Names.named(ConfigurableMessagingSettings.PROPERTY_TTL_UPLIFT_MS)).toInstance(SUBSCRIPTION_UPLIFT_MS);
        }
    });
    Injector injectorWithPublicationUplift = Guice.createInjector(subcriptionUpliftModule);
    publicationManager = (PublicationManagerImpl) injector.getInstance(PublicationManager.class);
    publicationManagerWithTtlUplift = (PublicationManagerImpl) injectorWithPublicationUplift.getInstance(PublicationManager.class);
    payload = "payload";
    Method method = TestProvider.class.getMethod("methodWithStrings", new Class[] { String.class });
    request = new Request(method.getName(), new String[] { payload }, method.getParameterTypes());
    messagingQos = new MessagingQos(TTL);
    expiryDate = DispatcherUtils.convertTtlToExpirationDate(messagingQos.getRoundTripTtl_ms());
}
Also used : ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) Deferred(io.joynr.provider.Deferred) JoynrMessageProcessor(io.joynr.messaging.JoynrMessageProcessor) Properties(java.util.Properties) MessagingQos(io.joynr.messaging.MessagingQos) TypeLiteral(com.google.inject.TypeLiteral) MutableMessage(joynr.MutableMessage) JoynrPropertiesModule(io.joynr.common.JoynrPropertiesModule) Injector(com.google.inject.Injector) PublicationManagerImpl(io.joynr.dispatching.subscription.PublicationManagerImpl) ProviderContainer(io.joynr.provider.ProviderContainer) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Multibinder(com.google.inject.multibindings.Multibinder) JsonMessageSerializerModule(io.joynr.messaging.JsonMessageSerializerModule) SubscriptionRequest(joynr.SubscriptionRequest) BroadcastSubscriptionRequest(joynr.BroadcastSubscriptionRequest) Request(joynr.Request) Method(java.lang.reflect.Method) AbstractModule(com.google.inject.AbstractModule) Promise(io.joynr.provider.Promise) ImmutableMessage(joynr.ImmutableMessage) Matchers.anyLong(org.mockito.Matchers.anyLong) Module(com.google.inject.Module) JsonMessageSerializerModule(io.joynr.messaging.JsonMessageSerializerModule) JoynrPropertiesModule(io.joynr.common.JoynrPropertiesModule) AbstractModule(com.google.inject.AbstractModule) Before(org.junit.Before)

Example 9 with Request

use of joynr.Request in project joynr by bmwcarit.

the class MutableMessageFactoryTest method testMessageProcessorUsed.

@Test
public void testMessageProcessorUsed() {
    MutableMessage message = mutableMessageFactory.createRequest("from", "to", new Request("name", new Object[0], new Class[0]), new MessagingQos());
    assertNotNull(message.getCustomHeaders().get("test"));
    assertEquals("test", message.getCustomHeaders().get("test"));
}
Also used : MessagingQos(io.joynr.messaging.MessagingQos) MutableMessage(joynr.MutableMessage) MulticastSubscriptionRequest(joynr.MulticastSubscriptionRequest) SubscriptionRequest(joynr.SubscriptionRequest) Request(joynr.Request) Test(org.junit.Test)

Example 10 with Request

use of joynr.Request in project joynr by bmwcarit.

the class RequestReplyManagerTest method setUp.

@Before
public void setUp() throws NoSuchMethodException, SecurityException, JsonGenerationException, IOException {
    requestCallerFactory = new RequestCallerFactory();
    testOneWayRecipientParticipantId = "testOneWayRecipientParticipantId";
    testOneWayRecipientDiscoveryEntry = new DiscoveryEntryWithMetaInfo();
    testOneWayRecipientDiscoveryEntry.setParticipantId(testOneWayRecipientParticipantId);
    testOneWayRecipientDiscoveryEntries = Sets.newHashSet(testOneWayRecipientDiscoveryEntry);
    testMessageResponderParticipantId = "testMessageResponderParticipantId";
    testMessageResponderDiscoveryEntry = new DiscoveryEntryWithMetaInfo();
    testMessageResponderDiscoveryEntry.setParticipantId(testMessageResponderParticipantId);
    testSenderParticipantId = "testSenderParticipantId";
    testResponderUnregisteredParticipantId = "testResponderUnregisteredParticipantId";
    Injector injector = Guice.createInjector(new AbstractModule() {

        @Override
        protected void configure() {
            install(new JoynrMessageScopeModule());
            bind(MessageSender.class).toInstance(messageSenderMock);
            bind(MessageRouter.class).toInstance(messageRouterMock);
            bind(RequestReplyManager.class).to(RequestReplyManagerImpl.class);
            requestStaticInjection(RpcUtils.class, Request.class, JoynrMessagingConnectorFactory.class);
            ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNameFormat("joynr.Cleanup-%d").build();
            ScheduledExecutorService cleanupExecutor = Executors.newSingleThreadScheduledExecutor(namedThreadFactory);
            bind(ScheduledExecutorService.class).annotatedWith(Names.named(JOYNR_SCHEDULER_CLEANUP)).toInstance(cleanupExecutor);
            Multibinder.newSetBinder(binder(), new TypeLiteral<JoynrMessageProcessor>() {
            });
        }
    });
    objectMapper = injector.getInstance(ObjectMapper.class);
    objectMapper.registerSubtypes(Request.class, OneWayRequest.class);
    requestReplyManager = injector.getInstance(RequestReplyManager.class);
    providerDirectory = injector.getInstance(ProviderDirectory.class);
    replyCallerDirectory = injector.getInstance(ReplyCallerDirectory.class);
    requestReplyManager = injector.getInstance(RequestReplyManager.class);
    // dispatcher.addListener(testOneWayRecipientParticipantId, testListener);
    // jsonRequestString1 = "{\"_typeName\":\"Request\", \"methodName\":\"respond\",\"params\":{\"payload\": \""
    // + payload1 + "\"}}";
    // jsonRequestString2 = "{\"_typeName\":\"Request\", \"methodName\":\"respond\",\"params\":{\"payload\": \""
    // + payload2 + "\"}}";
    Object[] params1 = new Object[] { payload1 };
    Object[] params2 = new Object[] { payload2 };
    // MethodMetaInformation methodMetaInformation = new
    // MethodMetaInformation(TestRequestCaller.class.getMethod("respond", new Class[]{ Object.class }));
    Method method = TestProvider.class.getMethod("methodWithStrings", new Class[] { String.class });
    request1 = new Request(method.getName(), params1, method.getParameterTypes());
    request2 = new Request(method.getName(), params2, method.getParameterTypes());
    request3 = new Request("unknownMethodName", params2, method.getParameterTypes());
    Method fireAndForgetMethod = TestOneWayRecipient.class.getMethod("fireAndForgetMethod", new Class[] { String.class });
    oneWay1 = new OneWayRequest(fireAndForgetMethod.getName(), new Object[] { payload1 }, fireAndForgetMethod.getParameterTypes());
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) RpcUtils(io.joynr.dispatching.rpc.RpcUtils) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) OneWayRequest(joynr.OneWayRequest) Request(joynr.Request) Method(java.lang.reflect.Method) AbstractModule(com.google.inject.AbstractModule) JoynrMessageScopeModule(io.joynr.context.JoynrMessageScopeModule) OneWayRequest(joynr.OneWayRequest) TypeLiteral(com.google.inject.TypeLiteral) ReplyCallerDirectory(io.joynr.dispatching.rpc.ReplyCallerDirectory) Injector(com.google.inject.Injector) JoynrMessagingConnectorFactory(io.joynr.proxy.JoynrMessagingConnectorFactory) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Before(org.junit.Before)

Aggregations

Request (joynr.Request)18 OneWayRequest (joynr.OneWayRequest)11 SubscriptionRequest (joynr.SubscriptionRequest)8 MessagingQos (io.joynr.messaging.MessagingQos)7 Reply (joynr.Reply)6 AbstractModule (com.google.inject.AbstractModule)5 Injector (com.google.inject.Injector)5 TypeLiteral (com.google.inject.TypeLiteral)5 Method (java.lang.reflect.Method)5 MutableMessage (joynr.MutableMessage)5 Before (org.junit.Before)5 Test (org.junit.Test)5 JoynrIllegalStateException (io.joynr.exceptions.JoynrIllegalStateException)4 MulticastSubscriptionRequest (joynr.MulticastSubscriptionRequest)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 JoynrPropertiesModule (io.joynr.common.JoynrPropertiesModule)3 SynchronizedReplyCaller (io.joynr.dispatching.rpc.SynchronizedReplyCaller)3 JsonMessageSerializerModule (io.joynr.messaging.JsonMessageSerializerModule)3 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)2