Search in sources :

Example 26 with Address

use of io.scalecube.transport.Address in project scalecube by scalecube.

the class ClientStreamProcessorTest method testListenFailedWhenSendFailedDueUnknownHostException.

@Test
public void testListenFailedWhenSendFailedDueUnknownHostException() throws Exception {
    // invalid both host and port
    Address failingAddress = Address.from("host:0");
    StreamProcessor streamProcessor = clientStreamProcessorFactory.newClientStreamProcessor(failingAddress);
    AssertableSubscriber<StreamMessage> subscriber = streamProcessor.listen().test();
    streamProcessor.onNext(StreamMessage.builder().qualifier("q/echo").build());
    subscriber.awaitTerminalEvent(TIMEOUT_MILLIS, TimeUnit.MILLISECONDS).assertNoValues().assertNotCompleted().assertError(UnknownHostException.class);
}
Also used : Address(io.scalecube.transport.Address) Test(org.junit.Test)

Example 27 with Address

use of io.scalecube.transport.Address in project scalecube by scalecube.

the class ClientStreamProcessorTest method testClientStreamChannelCloseEventsIsolated.

@Test
public void testClientStreamChannelCloseEventsIsolated() throws Exception {
    ServerStreamProcessors server = StreamProcessors.newServer();
    // mirror events to client
    server.listen().subscribe(sp -> sp.listen().subscribe(sp));
    Address addr = server.listenAddress("localhost").bindAwait();
    ClientStreamProcessors csp1 = StreamProcessors.newClient();
    ClientStreamProcessors csp2 = StreamProcessors.newClient();
    StreamProcessor sp1 = csp1.create(addr);
    StreamProcessor sp2 = csp2.create(addr);
    AssertableSubscriber<StreamMessage> assertion = sp2.listen().test();
    StreamMessage req = StreamMessage.builder().qualifier("REQ").build();
    sp1.onNext(req);
    sp2.onNext(req);
    TimeUnit.SECONDS.sleep(1);
    csp1.close();
    TimeUnit.SECONDS.sleep(2);
    assertion.assertNoErrors();
}
Also used : Address(io.scalecube.transport.Address) Test(org.junit.Test)

Example 28 with Address

use of io.scalecube.transport.Address in project scalecube by scalecube.

the class ClientStreamProcessorTest method testListenFailedWhenSendFailedDueConnectException.

@Test
public void testListenFailedWhenSendFailedDueConnectException() {
    // host is valid port is not
    Address failingAddress = Address.from("localhost:0");
    StreamProcessor streamProcessor = clientStreamProcessorFactory.newClientStreamProcessor(failingAddress);
    AssertableSubscriber<StreamMessage> subscriber = streamProcessor.listen().test();
    streamProcessor.onNext(StreamMessage.builder().qualifier("q/echo").build());
    subscriber.awaitTerminalEvent(TIMEOUT_MILLIS, TimeUnit.MILLISECONDS).assertNoValues().assertNotCompleted().assertError(ConnectException.class);
}
Also used : Address(io.scalecube.transport.Address) Test(org.junit.Test)

Example 29 with Address

use of io.scalecube.transport.Address in project scalecube by scalecube.

the class ListeningServerStreamTest method testServerStreamBindsOnAvailablePort.

@Test
public void testServerStreamBindsOnAvailablePort() throws Exception {
    int port = 5555;
    ListeningServerStream listeningServerStream = serverStream.withPort(port);
    Address address1 = listeningServerStream.bindAwait();
    Address address2 = listeningServerStream.bindAwait();
    Address address3 = listeningServerStream.bindAwait();
    assertEquals("127.0.0.1:5555", address1.toString());
    assertEquals("127.0.0.1:5556", address2.toString());
    assertEquals("127.0.0.1:5557", address3.toString());
}
Also used : Address(io.scalecube.transport.Address) Test(org.junit.Test)

Example 30 with Address

use of io.scalecube.transport.Address in project scalecube by scalecube.

the class ClientStreamTest method testClientStreamManagesConnections.

@Test
public void testClientStreamManagesConnections() throws Exception {
    ListeningServerStream anotherServerStream = ListeningServerStream.newListeningServerStream().withListenAddress("localhost");
    Address anotherAddress = anotherServerStream.bindAwait();
    try {
        // send two msgs on two addresses => activate two connections => emit events
        AssertableSubscriber<Event> clientSubscriber = clientStream.listenChannelContextSubscribed().test();
        // send msgs
        clientStream.send(address, StreamMessage.builder().qualifier("q/msg").build());
        clientStream.send(anotherAddress, StreamMessage.builder().qualifier("q/anotherMsg").build());
        List<Event> events = clientSubscriber.awaitValueCount(2, TIMEOUT_MILLIS, TimeUnit.MILLISECONDS).assertNoTerminalEvent().getOnNextEvents();
        Event firstEvent = events.get(0);
        Event secondEvent = events.get(1);
        assertEquals(Topic.ChannelContextSubscribed, firstEvent.getTopic());
        assertEquals(Topic.ChannelContextSubscribed, secondEvent.getTopic());
        assertThat(firstEvent.getAddress(), anyOf(is(address), is(anotherAddress)));
        assertThat(secondEvent.getAddress(), anyOf(is(address), is(anotherAddress)));
        // listen close
        AssertableSubscriber<Event> closeSubscriber = clientStream.listenChannelContextUnsubscribed().test();
        // close and ensure all connections closed
        clientStream.close();
        List<Event> closeEvents = new ArrayList<>(closeSubscriber.awaitValueCount(2, TIMEOUT_MILLIS, TimeUnit.MILLISECONDS).getOnNextEvents());
        Event firstCloseEvent = closeEvents.get(0);
        Event secondCloseEvent = closeEvents.get(1);
        assertEquals(Topic.ChannelContextUnsubscribed, firstCloseEvent.getTopic());
        assertEquals(Topic.ChannelContextUnsubscribed, secondCloseEvent.getTopic());
        assertThat(firstCloseEvent.getAddress(), anyOf(is(address), is(anotherAddress)));
        assertThat(secondCloseEvent.getAddress(), anyOf(is(address), is(anotherAddress)));
    } finally {
        anotherServerStream.close();
    }
}
Also used : Address(io.scalecube.transport.Address) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

Address (io.scalecube.transport.Address)43 Test (org.junit.Test)33 BaseTest (io.scalecube.testlib.BaseTest)22 Transport (io.scalecube.transport.Transport)20 ArrayList (java.util.ArrayList)13 List (java.util.List)12 InetAddress (java.net.InetAddress)10 CompletableFuture (java.util.concurrent.CompletableFuture)5 TimeUnit (java.util.concurrent.TimeUnit)5 Member (io.scalecube.cluster.Member)4 Collection (java.util.Collection)4 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)3 ALIVE (io.scalecube.cluster.membership.MemberStatus.ALIVE)3 Collectors (java.util.stream.Collectors)3 Lists (com.google.common.collect.Lists)2 Bootstrap (io.netty.bootstrap.Bootstrap)2 ClusterConfig (io.scalecube.cluster.ClusterConfig)2 DummyMembershipProtocol (io.scalecube.cluster.membership.DummyMembershipProtocol)2 MemberStatus (io.scalecube.cluster.membership.MemberStatus)2 SUSPECT (io.scalecube.cluster.membership.MemberStatus.SUSPECT)2