use of joynr.system.RoutingTypes.Address in project joynr by bmwcarit.
the class MqttMulticastAddressCalculator method calculate.
@Override
public Address calculate(ImmutableMessage message) {
Address result = null;
if (globalAddress != null) {
String topic = mqttTopicPrefixProvider.getMulticastTopicPrefix() + message.getRecipient();
result = new MqttAddress(globalAddress.getBrokerUri(), topic);
}
return result;
}
use of joynr.system.RoutingTypes.Address in project joynr by bmwcarit.
the class AddressManagerTest method testGetLocalAndGlobalAddressesForGloballyVisibleProvider.
@Test
public void testGetLocalAndGlobalAddressesForGloballyVisibleProvider() {
createAddressManager(GLOBAL_TRANSPORT_MQTT, multicastAddressCalculator);
String multicastId = participantId + "/to";
when(joynrMessage.getSender()).thenReturn(participantId);
when(joynrMessage.getRecipient()).thenReturn(multicastId);
when(routingTable.getIsGloballyVisible(participantId)).thenReturn(true);
Set<String> localParticipantIds = Sets.newHashSet("one");
when(multicastReceiverRegistry.getReceivers(multicastId)).thenReturn(localParticipantIds);
Address localAddress = mock(Address.class);
when(routingTable.get("one")).thenReturn(localAddress);
Address globalAddress = mock(Address.class);
when(multicastAddressCalculator.supports(GLOBAL_TRANSPORT_MQTT)).thenReturn(true);
when(multicastAddressCalculator.createsGlobalTransportAddresses()).thenReturn(true);
when(multicastAddressCalculator.calculate(joynrMessage)).thenReturn(globalAddress);
Set<Address> result = subject.getAddresses(joynrMessage);
assertNotNull(result);
assertEquals(2, result.size());
assertTrue(result.contains(localAddress));
assertTrue(result.contains(globalAddress));
}
use of joynr.system.RoutingTypes.Address in project joynr by bmwcarit.
the class RpcStubbingTest method setUp.
@Before
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "NP_NULL_PARAM_DEREF", justification = "NPE in test would fail test")
public void setUp() throws JoynrCommunicationException, JoynrSendBufferFullException, JsonGenerationException, JsonMappingException, IOException, JoynrMessageNotSentException {
Deferred<GpsLocation> deferredGpsLocation = new Deferred<GpsLocation>();
deferredGpsLocation.resolve(gpsValue);
when(testMock.returnsGpsLocation()).thenReturn(new Promise<Deferred<GpsLocation>>(deferredGpsLocation));
Deferred<List<GpsLocation>> deferredGpsLocationList = new Deferred<List<GpsLocation>>();
deferredGpsLocationList.resolve(gpsList);
when(testMock.returnsGpsLocationList()).thenReturn(new Promise<Deferred<List<GpsLocation>>>(deferredGpsLocationList));
DeferredVoid deferredVoid = new DeferredVoid();
deferredVoid.resolve();
when(testMock.noParamsNoReturnValue()).thenReturn(new Promise<DeferredVoid>(deferredVoid));
when(testMock.takesTwoSimpleParams(any(Integer.class), any(String.class))).thenReturn(new Promise<DeferredVoid>(deferredVoid));
fromParticipantId = UUID.randomUUID().toString();
toParticipantId = UUID.randomUUID().toString();
toDiscoveryEntry = new DiscoveryEntryWithMetaInfo();
toDiscoveryEntry.setParticipantId(toParticipantId);
// required to inject static members of JoynMessagingConnectorFactory
injector = Guice.createInjector(new JoynrPropertiesModule(PropertyLoader.loadProperties(MessagingPropertyKeys.DEFAULT_MESSAGING_PROPERTIES_FILE)), new JsonMessageSerializerModule(), new AbstractModule() {
@Override
protected void configure() {
requestStaticInjection(RpcUtils.class);
install(new JoynrMessageScopeModule());
MapBinder<Class<? extends Address>, AbstractMiddlewareMessagingStubFactory<? extends IMessagingStub, ? extends Address>> messagingStubFactory;
messagingStubFactory = MapBinder.newMapBinder(binder(), new TypeLiteral<Class<? extends Address>>() {
}, new TypeLiteral<AbstractMiddlewareMessagingStubFactory<? extends IMessagingStub, ? extends Address>>() {
}, Names.named(MessagingStubFactory.MIDDLEWARE_MESSAGING_STUB_FACTORIES));
messagingStubFactory.addBinding(InProcessAddress.class).to(InProcessMessagingStubFactory.class);
}
});
final RequestInterpreter requestInterpreter = injector.getInstance(RequestInterpreter.class);
final RequestCallerFactory requestCallerFactory = injector.getInstance(RequestCallerFactory.class);
when(requestReplyManager.sendSyncRequest(eq(fromParticipantId), eq(toDiscoveryEntry), any(Request.class), any(SynchronizedReplyCaller.class), eq(messagingQos))).thenAnswer(new Answer<Reply>() {
@Override
public Reply answer(InvocationOnMock invocation) throws Throwable {
RequestCaller requestCaller = requestCallerFactory.create(testMock);
Object[] args = invocation.getArguments();
Request request = null;
for (Object arg : args) {
if (arg instanceof Request) {
request = (Request) arg;
break;
}
}
final Future<Reply> future = new Future<Reply>();
ProviderCallback<Reply> callback = new ProviderCallback<Reply>() {
@Override
public void onSuccess(Reply result) {
future.onSuccess(result);
}
@Override
public void onFailure(JoynrException error) {
future.onFailure(error);
}
};
requestInterpreter.execute(callback, requestCaller, request);
return future.get();
}
});
JoynrMessagingConnectorFactory joynrMessagingConnectorFactory = new JoynrMessagingConnectorFactory(requestReplyManager, replyCallerDirectory, subscriptionManager);
connector = joynrMessagingConnectorFactory.create(fromParticipantId, Sets.newHashSet(toDiscoveryEntry), messagingQos);
}
use of joynr.system.RoutingTypes.Address in project joynr by bmwcarit.
the class SerializationTest method serializeSubtype.
@Test
public void serializeSubtype() throws Exception {
MqttAddress mqttAddress = new MqttAddress("brokerUri", "topic");
String serializedMqttAddress = objectMapper.writeValueAsString(mqttAddress);
Address receivedAddress = objectMapper.readValue(serializedMqttAddress, Address.class);
Assert.assertTrue(receivedAddress instanceof MqttAddress);
Assert.assertEquals(mqttAddress, receivedAddress);
}
use of joynr.system.RoutingTypes.Address in project joynr by bmwcarit.
the class ArbitrationTest method testPriorityArbitratorWithOnlyNegativePriorities.
@Test
public void testPriorityArbitratorWithOnlyNegativePriorities() throws InterruptedException {
ProviderQos providerQos = new ProviderQos();
providerQos.setPriority(Long.MIN_VALUE);
expectedEndpointAddress = new ChannelAddress("http://testUrl", "testChannelId");
ArrayList<Address> expectedEndpointAddresses = new ArrayList<Address>();
expectedEndpointAddresses.add(expectedEndpointAddress);
capabilitiesList.add(new DiscoveryEntryWithMetaInfo(new Version(47, 11), domain, TestInterface.INTERFACE_NAME, expectedParticipantId, providerQos, System.currentTimeMillis(), NO_EXPIRY, publicKeyId, true));
ProviderQos providerQos2 = new ProviderQos();
providerQos2.setPriority(Long.MIN_VALUE);
capabilitiesList.add(new DiscoveryEntryWithMetaInfo(new Version(47, 11), domain, TestInterface.INTERFACE_NAME, "wrongParticipantId", providerQos2, System.currentTimeMillis(), NO_EXPIRY, publicKeyId, true));
long negativePriority = Long.MIN_VALUE;
ProviderQos providerQos3 = new ProviderQos();
providerQos3.setPriority(negativePriority);
capabilitiesList.add(new DiscoveryEntryWithMetaInfo(new Version(47, 11), domain, TestInterface.INTERFACE_NAME, "thirdParticipantId", providerQos3, System.currentTimeMillis(), NO_EXPIRY, publicKeyId, true));
discoveryQos = new DiscoveryQos(ARBITRATION_TIMEOUT, ArbitrationStrategy.HighestPriority, Long.MAX_VALUE);
try {
Arbitrator arbitrator = ArbitratorFactory.create(Sets.newHashSet(domain), interfaceName, interfaceVersion, discoveryQos, localDiscoveryAggregator);
arbitrator.setArbitrationListener(arbitrationCallback);
arbitrator.scheduleArbitration();
assertTrue(localDiscoveryAggregatorSemaphore.tryAcquire(1000, TimeUnit.MILLISECONDS));
verify(arbitrationCallback, times(1)).onError(any(Throwable.class));
verify(arbitrationCallback, never()).onSuccess(any(ArbitrationResult.class));
} catch (DiscoveryException e) {
fail("A Joyn Arbitration Exception has been thrown");
}
}
Aggregations