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);
}
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();
}
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);
}
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());
}
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();
}
}
Aggregations