use of joynr.system.RoutingTypes.Address in project joynr by bmwcarit.
the class StaticCapabilitiesProvisioningTest method assertContainsEntryFor.
private void assertContainsEntryFor(Collection<DiscoveryEntry> entries, String interfaceName, String participantId, String url) {
boolean found = false;
for (DiscoveryEntry entry : entries) {
if (entry instanceof GlobalDiscoveryEntry) {
GlobalDiscoveryEntry globalDiscoveryEntry = (GlobalDiscoveryEntry) entry;
if (globalDiscoveryEntry.getInterfaceName().equals(interfaceName) && (participantId == null || participantId.equals(globalDiscoveryEntry.getParticipantId()))) {
if (url != null) {
Address address = CapabilityUtils.getAddressFromGlobalDiscoveryEntry(globalDiscoveryEntry);
assertTrue(address instanceof ChannelAddress);
assertEquals(url, ((ChannelAddress) address).getMessagingEndpointUrl());
}
found = true;
}
}
}
assertTrue("Couldn't find " + interfaceName + ((participantId == null ? "" : " / " + participantId)) + " in " + entries, found);
}
use of joynr.system.RoutingTypes.Address in project joynr by bmwcarit.
the class StaticCapabilitiesProvisioningTest method createDiscoveryEntries.
private Set<DiscoveryEntry> createDiscoveryEntries(String domain, String... interfaceNames) {
Set<DiscoveryEntry> discoveryEntries = new HashSet<DiscoveryEntry>();
String participantId = "particpantId";
ProviderQos qos = new ProviderQos();
Long lastSeenDateMs = 0L;
Long expiryDateMs = 0L;
String publicKeyId = "publicKeyId";
Address address = new MqttAddress("brokerUri", "topic");
for (String interfaceName : interfaceNames) {
GlobalDiscoveryEntry entry = CapabilityUtils.newGlobalDiscoveryEntry(new Version(0, 1), domain, interfaceName, participantId, qos, lastSeenDateMs, expiryDateMs, publicKeyId, address);
discoveryEntries.add(entry);
}
return discoveryEntries;
}
use of joynr.system.RoutingTypes.Address in project joynr by bmwcarit.
the class AbstractMessageRouter method registerGlobalRoutingEntryIfRequired.
private void registerGlobalRoutingEntryIfRequired(final ImmutableMessage message) {
if (!message.isReceivedFromGlobal()) {
return;
}
String messageType = message.getType();
if (!messageType.equals(Message.VALUE_MESSAGE_TYPE_REQUEST) && !messageType.equals(Message.VALUE_MESSAGE_TYPE_SUBSCRIPTION_REQUEST) && !messageType.equals(Message.VALUE_MESSAGE_TYPE_BROADCAST_SUBSCRIPTION_REQUEST) && !messageType.equals(Message.VALUE_MESSAGE_TYPE_MULTICAST_SUBSCRIPTION_REQUEST)) {
return;
}
String replyTo = message.getReplyTo();
if (replyTo != null && !replyTo.isEmpty()) {
Address address = RoutingTypesUtil.fromAddressString(replyTo);
// If the message was received from global, the sender is globally visible by definition.
final boolean isGloballyVisible = true;
long expiryDateMs;
try {
expiryDateMs = Math.addExact(message.getTtlMs(), routingTableGracePeriodMs);
} catch (ArithmeticException e) {
expiryDateMs = Long.MAX_VALUE;
}
final boolean isSticky = false;
final boolean allowUpdate = false;
routingTable.put(message.getSender(), address, isGloballyVisible, expiryDateMs, isSticky, allowUpdate);
}
}
use of joynr.system.RoutingTypes.Address in project joynr by bmwcarit.
the class AddressManagerTest method testGetLocalAndGlobalAddressesForGloballyInvisibleProvider.
@Test
public void testGetLocalAndGlobalAddressesForGloballyInvisibleProvider() {
createAddressManager(GLOBAL_TRANSPORT_MQTT, multicastAddressCalculator);
when(joynrMessage.getSender()).thenReturn("participantId");
String multicastId = participantId + "/to";
when(joynrMessage.getRecipient()).thenReturn(multicastId);
when(routingTable.getIsGloballyVisible(participantId)).thenReturn(false);
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(1, result.size());
assertTrue(result.contains(localAddress));
assertFalse(result.contains(globalAddress));
}
use of joynr.system.RoutingTypes.Address in project joynr by bmwcarit.
the class RoutingTableImplTest method testOnlyPutOnce.
@Test
public void testOnlyPutOnce() {
String participantId = "participantId";
assertFalse(subject.containsKey(participantId));
Address address1 = new Address();
final boolean isGloballyVisible1 = false;
final long expiryDateMs1 = Long.MAX_VALUE;
final boolean isSticky1 = false;
final boolean allowUpdate = false;
subject.put(participantId, address1, isGloballyVisible1, expiryDateMs1, isSticky1, allowUpdate);
assertEquals(isGloballyVisible1, subject.getIsGloballyVisible(participantId));
assertEquals(address1, subject.get(participantId));
Address address2 = new Address();
final boolean isGloballyVisible2 = true;
final long expiryDateMs2 = Long.MAX_VALUE;
final boolean isSticky2 = false;
// insertion shouldn't take place. participantId is already exists in the table and has address1
subject.put(participantId, address2, isGloballyVisible2, expiryDateMs2, isSticky2, allowUpdate);
assertEquals(address1, subject.get(participantId));
assertEquals(isGloballyVisible1, subject.getIsGloballyVisible(participantId));
}
Aggregations