Search in sources :

Example 16 with Request

use of joynr.Request in project joynr by bmwcarit.

the class SerializationTest method serializeAndDeserializeRequestWithVariousTypesTest.

@Test
public void serializeAndDeserializeRequestWithVariousTypesTest() throws Exception {
    String methodName = "methodName";
    GpsLocation gpsLocation = new GpsLocation(1.0d, 2.0d, 0d, GpsFixEnum.MODE2D, 0d, 0d, 0d, 0d, 0l, 0l, 0);
    GpsLocation[] gpsLocations = { new GpsLocation(1.0d, 2.0d, 0d, GpsFixEnum.MODE2D, 0d, 0d, 0d, 0d, 0l, 0l, 0), new GpsLocation(1.0d, 2.0d, 0d, GpsFixEnum.MODE2D, 0d, 0d, 0d, 0d, 0l, 0l, 0), new GpsLocation(1.0d, 2.0d, 0d, GpsFixEnum.MODE2D, 0d, 0d, 0d, 0d, 0l, 0l, 0) };
    TestClass testObject = new TestClass();
    testObject.setMyByte((byte) 4);
    testObject.setObjects(new Object[] { gpsLocation, "hello" });
    String[][] stringArray = new String[][] { { "test1", "test2", "test3" }, { "test4", "test5", "test6" } };
    Boolean[] booleanArray = { true, false };
    Boolean[] emptyArray = {};
    Object[] mixedArray = new Object[] { "one", gpsLocation, stringArray };
    Object[] params = new Object[] { true, Integer.MAX_VALUE, Long.MAX_VALUE, Double.MAX_VALUE, gpsLocation, "param1", gpsLocations, stringArray, booleanArray, emptyArray, mixedArray };
    String[] paramDatatypes = new String[params.length];
    for (int i = 0; i < params.length; i++) {
        paramDatatypes[i] = ReflectionUtils.toDatatypeNames(params[i].getClass())[0];
    }
    Request request = new Request(methodName, params, paramDatatypes, null);
    String valueAsString = objectMapper.writeValueAsString(request);
    System.out.println(valueAsString);
    Request request2 = objectMapper.readValue(valueAsString, Request.class);
    assertEquals(request, request2);
}
Also used : OneWayRequest(joynr.OneWayRequest) SubscriptionRequest(joynr.SubscriptionRequest) PersistedSubscriptionRequest(io.joynr.dispatching.subscription.PersistedSubscriptionRequest) BroadcastSubscriptionRequest(joynr.BroadcastSubscriptionRequest) Request(joynr.Request) GpsLocation(joynr.types.Localisation.GpsLocation) Test(org.junit.Test)

Example 17 with Request

use of joynr.Request in project joynr by bmwcarit.

the class DispatcherImplTest method testPropagateCompressFlagFromRequestToRepliesImpl.

private void testPropagateCompressFlagFromRequestToRepliesImpl(final boolean compress) throws Exception {
    MessagingQos messagingQos = new MessagingQos(1000L);
    messagingQos.setCompress(compress);
    String requestReplyId = UUID.randomUUID().toString();
    Request request = new Request("methodName", new Object[] {}, new String[] {}, requestReplyId);
    final String providerParticipantId = "toParticipantId";
    MutableMessage joynrMessage = messageFactory.createRequest("fromParticipantId", providerParticipantId, request, messagingQos);
    ImmutableMessage outgoingMessage = joynrMessage.getImmutableMessage();
    fixture.messageArrived(outgoingMessage);
    verify(requestReplyManagerMock).handleRequest(providerCallbackReply.capture(), eq(providerParticipantId), eq(request), eq(joynrMessage.getTtlMs()));
    providerCallbackReply.getValue().onSuccess(new Reply(requestReplyId));
    verify(messageSenderMock).sendMessage(argThat(new MessageIsCompressedMatcher(compress)));
}
Also used : MessagingQos(io.joynr.messaging.MessagingQos) MutableMessage(joynr.MutableMessage) ImmutableMessage(joynr.ImmutableMessage) OneWayRequest(joynr.OneWayRequest) SubscriptionRequest(joynr.SubscriptionRequest) MulticastSubscriptionRequest(joynr.MulticastSubscriptionRequest) Request(joynr.Request) Reply(joynr.Reply) Matchers.anyString(org.mockito.Matchers.anyString)

Example 18 with Request

use of joynr.Request in project joynr by bmwcarit.

the class MutableMessageFactoryTest method setUp.

@Before
public void setUp() throws NoSuchMethodException, SecurityException {
    fromParticipantId = "sender";
    toParticipantId = "receiver";
    Injector injector = Guice.createInjector(new JoynrPropertiesModule(new Properties()), 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) {
                    joynrMessage.getCustomHeaders().put("test", "test");
                    return joynrMessage;
                }

                @Override
                public ImmutableMessage processIncoming(ImmutableMessage joynrMessage) {
                    return joynrMessage;
                }
            });
        }
    });
    objectMapper = injector.getInstance(ObjectMapper.class);
    payload = "payload";
    Method method = TestProvider.class.getMethod("methodWithStrings", new Class[] { String.class });
    request = new Request(method.getName(), new String[] { payload }, method.getParameterTypes());
    String requestReplyId = request.getRequestReplyId();
    reply = new Reply(requestReplyId, objectMapper.<JsonNode>valueToTree(payload));
    messagingQos = new MessagingQos(TTL);
    expiryDate = DispatcherUtils.convertTtlToExpirationDate(messagingQos.getRoundTripTtl_ms());
    String subscriptionId = "subscription";
    String attributeName = "attribute";
    PeriodicSubscriptionQos subscriptionqos = new PeriodicSubscriptionQos();
    subscriptionqos.setPeriodMs(1000).setValidityMs(10).setAlertAfterIntervalMs(1500).setPublicationTtlMs(1000);
    subscriptionRequest = new SubscriptionRequest(subscriptionId, attributeName, subscriptionqos);
    String response = "response";
    publication = new SubscriptionPublication(Arrays.asList(response), subscriptionId);
    mutableMessageFactory = injector.getInstance(MutableMessageFactory.class);
}
Also used : Multibinder(com.google.inject.multibindings.Multibinder) JsonMessageSerializerModule(io.joynr.messaging.JsonMessageSerializerModule) MulticastSubscriptionRequest(joynr.MulticastSubscriptionRequest) SubscriptionRequest(joynr.SubscriptionRequest) Request(joynr.Request) JoynrMessageProcessor(io.joynr.messaging.JoynrMessageProcessor) JsonNode(com.fasterxml.jackson.databind.JsonNode) Method(java.lang.reflect.Method) Properties(java.util.Properties) AbstractModule(com.google.inject.AbstractModule) PeriodicSubscriptionQos(joynr.PeriodicSubscriptionQos) MessagingQos(io.joynr.messaging.MessagingQos) MulticastSubscriptionRequest(joynr.MulticastSubscriptionRequest) SubscriptionRequest(joynr.SubscriptionRequest) TypeLiteral(com.google.inject.TypeLiteral) MutableMessage(joynr.MutableMessage) Injector(com.google.inject.Injector) JoynrPropertiesModule(io.joynr.common.JoynrPropertiesModule) SubscriptionPublication(joynr.SubscriptionPublication) ImmutableMessage(joynr.ImmutableMessage) Reply(joynr.Reply) 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