Search in sources :

Example 21 with Address

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);
}
Also used : DiscoveryEntry(joynr.types.DiscoveryEntry) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) ChannelAddress(joynr.system.RoutingTypes.ChannelAddress) MqttAddress(joynr.system.RoutingTypes.MqttAddress) Address(joynr.system.RoutingTypes.Address) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) ChannelAddress(joynr.system.RoutingTypes.ChannelAddress)

Example 22 with Address

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;
}
Also used : DiscoveryEntry(joynr.types.DiscoveryEntry) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) ChannelAddress(joynr.system.RoutingTypes.ChannelAddress) MqttAddress(joynr.system.RoutingTypes.MqttAddress) Address(joynr.system.RoutingTypes.Address) Version(joynr.types.Version) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) ProviderQos(joynr.types.ProviderQos) HashSet(java.util.HashSet) MqttAddress(joynr.system.RoutingTypes.MqttAddress)

Example 23 with Address

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);
    }
}
Also used : Address(joynr.system.RoutingTypes.Address)

Example 24 with Address

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));
}
Also used : Address(joynr.system.RoutingTypes.Address) Test(org.junit.Test)

Example 25 with Address

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));
}
Also used : Address(joynr.system.RoutingTypes.Address) Test(org.junit.Test)

Aggregations

Address (joynr.system.RoutingTypes.Address)43 Test (org.junit.Test)21 ChannelAddress (joynr.system.RoutingTypes.ChannelAddress)15 MqttAddress (joynr.system.RoutingTypes.MqttAddress)13 ProviderQos (joynr.types.ProviderQos)9 Version (joynr.types.Version)9 InProcessAddress (io.joynr.messaging.inprocess.InProcessAddress)7 JoynrRuntimeException (io.joynr.exceptions.JoynrRuntimeException)6 TypeLiteral (com.google.inject.TypeLiteral)5 GlobalDiscoveryEntry (joynr.types.GlobalDiscoveryEntry)5 AbstractModule (com.google.inject.AbstractModule)4 HashSet (java.util.HashSet)4 DiscoveryEntryWithMetaInfo (joynr.types.DiscoveryEntryWithMetaInfo)4 DiscoveryException (io.joynr.exceptions.DiscoveryException)3 AbstractMiddlewareMessagingStubFactory (io.joynr.messaging.AbstractMiddlewareMessagingStubFactory)3 IMessagingSkeleton (io.joynr.messaging.IMessagingSkeleton)3 IMessagingStub (io.joynr.messaging.IMessagingStub)3 CcMessageRouter (io.joynr.messaging.routing.CcMessageRouter)3 ArrayList (java.util.ArrayList)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2