Search in sources :

Example 86 with UdpChannel

use of io.aeron.driver.media.UdpChannel in project aeron by real-logic.

the class UdpChannelTest method shouldHandleBeingUsedAsMapKey.

@Test
public void shouldHandleBeingUsedAsMapKey() {
    final UdpChannel udpChannel1 = UdpChannel.parse("aeron:udp?endpoint=localhost:40124");
    final UdpChannel udpChannel2 = UdpChannel.parse("aeron:udp?endpoint=localhost:40124");
    final Map<UdpChannel, Integer> map = new HashMap<>();
    map.put(udpChannel1, 1);
    assertThat(map.get(udpChannel2), is(1));
}
Also used : HashMap(java.util.HashMap) UdpChannel(io.aeron.driver.media.UdpChannel) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 87 with UdpChannel

use of io.aeron.driver.media.UdpChannel in project aeron by real-logic.

the class UdpChannelTest method shouldParseWithNameResolver.

@ParameterizedTest
@CsvSource({ "NAME_ENDPOINT,192.168.1.1,,,UDP-127.0.0.1:0-NAME_ENDPOINT", "localhost:41024,127.0.0.1,,,UDP-127.0.0.1:0-localhost:41024", "[fe80::5246:5dff:fe73:df06]:40456,[fe80::5246:5dff:fe73:df06],,," + "UDP-127.0.0.1:0-[fe80::5246:5dff:fe73:df06]:40456", "NAME_ENDPOINT,224.0.1.1,,,UDP-127.0.0.1:0-224.0.1.1:40124", "NAME_ENDPOINT,192.168.1.1,NAME_CONTROL,192.168.1.2,UDP-NAME_CONTROL-NAME_ENDPOINT", "NAME_ENDPOINT,224.0.1.1,NAME_CONTROL,127.0.0.1,UDP-127.0.0.1:0-224.0.1.1:40124", "192.168.1.1:40124,192.168.1.1,NAME_CONTROL,192.168.1.2,UDP-NAME_CONTROL-192.168.1.1:40124", "192.168.1.1:40124,192.168.1.1,192.168.1.2:40192,192.168.1.2,UDP-192.168.1.2:40192-192.168.1.1:40124" })
void shouldParseWithNameResolver(final String endpointName, final String endpointAddress, final String controlName, final String controlAddress, final String canonicalForm) {
    final int port = 40124;
    final NameResolver resolver = new NameResolver() {

        public InetAddress resolve(final String name, final String uriParamName, final boolean isReResolution) {
            return DefaultNameResolver.INSTANCE.resolve(name, uriParamName, isReResolution);
        }

        public String lookup(final String name, final String uriParamName, final boolean isReLookup) {
            if (endpointName.equals(name)) {
                return endpointAddress + ":" + port;
            } else if (controlName.equals(name)) {
                return controlAddress + ":" + port;
            }
            return name;
        }
    };
    final ChannelUriStringBuilder uriBuilder = new ChannelUriStringBuilder().media("udp").networkInterface("localhost");
    if (!Strings.isEmpty(endpointName)) {
        uriBuilder.endpoint(endpointName);
    }
    if (!Strings.isEmpty(controlName)) {
        uriBuilder.controlEndpoint(controlName);
    }
    final UdpChannel udpChannel = UdpChannel.parse(uriBuilder.build(), resolver);
    assertThat(udpChannel.canonicalForm(), is(canonicalForm));
}
Also used : ChannelUriStringBuilder(io.aeron.ChannelUriStringBuilder) UdpChannel(io.aeron.driver.media.UdpChannel) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 88 with UdpChannel

use of io.aeron.driver.media.UdpChannel in project aeron by real-logic.

the class UdpChannelTest method shouldHandleExplicitLocalAddressAndPortFormatWithAeronUri.

@ParameterizedTest
@CsvSource("endpoint,interface")
public void shouldHandleExplicitLocalAddressAndPortFormatWithAeronUri(final String endpointKey, final String interfaceKey) {
    final UdpChannel udpChannel = UdpChannel.parse(uri(endpointKey, "localhost:40124", interfaceKey, "localhost:40123"));
    assertThat(udpChannel.localData(), is(new InetSocketAddress("localhost", 40123)));
    assertThat(udpChannel.localControl(), is(new InetSocketAddress("localhost", 40123)));
    assertThat(udpChannel.remoteData(), is(new InetSocketAddress("localhost", 40124)));
    assertThat(udpChannel.remoteControl(), is(new InetSocketAddress("localhost", 40124)));
}
Also used : UdpChannel(io.aeron.driver.media.UdpChannel) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 89 with UdpChannel

use of io.aeron.driver.media.UdpChannel in project aeron by real-logic.

the class UdpChannelTest method shouldParseValidMulticastAddress.

@Test
public void shouldParseValidMulticastAddress() throws IOException {
    final UdpChannel udpChannel = UdpChannel.parse("aeron:udp?interface=localhost|endpoint=224.10.9.9:40124");
    assertThat(udpChannel.localControl(), is(new InetSocketAddress("localhost", 0)));
    assertThat(udpChannel.remoteControl(), isMulticastAddress("224.10.9.10", 40124));
    assertThat(udpChannel.localData(), is(new InetSocketAddress("localhost", 0)));
    assertThat(udpChannel.remoteData(), isMulticastAddress("224.10.9.9", 40124));
    assertThat(udpChannel.localInterface(), is(NetworkInterface.getByInetAddress(getByName("localhost"))));
}
Also used : UdpChannel(io.aeron.driver.media.UdpChannel) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 90 with UdpChannel

use of io.aeron.driver.media.UdpChannel in project aeron by real-logic.

the class UdpChannelTest method shouldHandleIPv6AnyAddressAsInterfaceAddressForUnicast.

@ParameterizedTest
@CsvSource("endpoint,interface")
public void shouldHandleIPv6AnyAddressAsInterfaceAddressForUnicast(final String endpointKey, final String interfaceKey) {
    final UdpChannel udpChannel = UdpChannel.parse(uri(endpointKey, "[::1]:40124", interfaceKey, "[::]"));
    assertThat(udpChannel.localData(), is(new InetSocketAddress("::", 0)));
    assertThat(udpChannel.localControl(), is(new InetSocketAddress("::", 0)));
    assertThat(udpChannel.remoteData(), is(new InetSocketAddress("::1", 40124)));
    assertThat(udpChannel.remoteControl(), is(new InetSocketAddress("::1", 40124)));
}
Also used : UdpChannel(io.aeron.driver.media.UdpChannel) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

UdpChannel (io.aeron.driver.media.UdpChannel)94 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)70 Test (org.junit.jupiter.api.Test)52 CsvSource (org.junit.jupiter.params.provider.CsvSource)22 ReceiveChannelEndpoint (io.aeron.driver.media.ReceiveChannelEndpoint)14 SendChannelEndpoint (io.aeron.driver.media.SendChannelEndpoint)8 ControlProtocolException (io.aeron.exceptions.ControlProtocolException)6 ChannelUri (io.aeron.ChannelUri)4 PublicationParams (io.aeron.driver.PublicationParams)4 ReceiveDestinationTransport (io.aeron.driver.media.ReceiveDestinationTransport)4 Pattern (java.util.regex.Pattern)3 Aeron (io.aeron.Aeron)2 SPY_QUALIFIER (io.aeron.ChannelUri.SPY_QUALIFIER)2 CommonContext (io.aeron.CommonContext)2 FORCE_TRUE (io.aeron.CommonContext.InferableBoolean.FORCE_TRUE)2 INFER (io.aeron.CommonContext.InferableBoolean.INFER)2 ErrorCode (io.aeron.ErrorCode)2 Context (io.aeron.driver.MediaDriver.Context)2 SubscriptionParams.validateInitialWindowForRcvBuf (io.aeron.driver.SubscriptionParams.validateInitialWindowForRcvBuf)2 LogFactory (io.aeron.driver.buffer.LogFactory)2