use of io.scalecube.transport.Address in project scalecube by scalecube.
the class ListeningServerStreamTest method testServerStreamRemotePartyClosed.
@Test
public void testServerStreamRemotePartyClosed() throws Exception {
AssertableSubscriber<Event> serverStreamSubscriber = serverStream.listen().test();
Address address = serverStream.bindAwait();
ClientStream clientStream = ClientStream.newClientStream();
clientStream.send(address, StreamMessage.builder().qualifier("q/test").build());
List<Event> events = serverStreamSubscriber.awaitValueCount(2, TIMEOUT_MILLIS, TimeUnit.MILLISECONDS).getOnNextEvents();
assertEquals(Topic.ChannelContextSubscribed, events.get(0).getTopic());
assertEquals(Topic.ReadSuccess, events.get(1).getTopic());
// close remote party and receive corresp events
AssertableSubscriber<Event> channelInactiveSubscriber = serverStream.listenChannelContextClosed().test();
// close connector channel at client stream
clientStream.close();
// await a bit
TimeUnit.SECONDS.sleep(3);
// assert that serverStream received event about closed client connector channel
Event event = channelInactiveSubscriber.getOnNextEvents().get(0);
assertEquals(Topic.ChannelContextClosed, event.getTopic());
assertFalse("Must not have error at this point", event.hasError());
}
use of io.scalecube.transport.Address in project scalecube by scalecube.
the class ClientStreamTest method testClientStreamSendFailedDueUnknownHostException.
@Test
public void testClientStreamSendFailedDueUnknownHostException() throws Exception {
// invalid both host and port
Address failedAddress = Address.from("host:0");
StreamMessage message = StreamMessage.builder().qualifier("q/helloFail").build();
AssertableSubscriber<Event> clientSubscriber = clientStreamCustom.listen().filter(Event::isWriteError).test();
clientStreamCustom.send(failedAddress, message);
Event event = clientSubscriber.awaitValueCount(1, TIMEOUT_MILLIS, TimeUnit.MILLISECONDS).assertNoTerminalEvent().getOnNextEvents().get(0);
assertEquals(Topic.WriteError, event.getTopic());
assertEquals(failedAddress, event.getAddress());
assertEquals(message, event.getMessageOrThrow());
assertTrue("An error must be here", event.getError().isPresent());
assertThat(event.getErrorOrThrow(), is(instanceOf(UnknownHostException.class)));
}
use of io.scalecube.transport.Address in project scalecube by scalecube.
the class ClientStreamTest method testClientStreamSendFailedDueConnectException.
@Test
public void testClientStreamSendFailedDueConnectException() throws Exception {
// host is valid port is not
Address failedAddress = Address.from("localhost:0");
StreamMessage message = StreamMessage.builder().qualifier("q/helloFail").build();
AssertableSubscriber<Event> clientSubscriber = clientStreamCustom.listen().filter(Event::isWriteError).test();
clientStreamCustom.send(failedAddress, message);
Event event = clientSubscriber.awaitValueCount(1, TIMEOUT_MILLIS, TimeUnit.MILLISECONDS).assertNoTerminalEvent().getOnNextEvents().get(0);
assertEquals(Topic.WriteError, event.getTopic());
assertEquals(failedAddress, event.getAddress());
assertEquals(message, event.getMessageOrThrow());
assertTrue("An error must be here", event.getError().isPresent());
assertThat(event.getErrorOrThrow(), is(instanceOf(ConnectException.class)));
}
use of io.scalecube.transport.Address in project scalecube by scalecube.
the class ServiceRegistryImpl method loadMemberServices.
private void loadMemberServices(DiscoveryType type, Member member) {
member.metadata().entrySet().stream().filter(// filter service tags
entry -> "service".equals(entry.getValue())).forEach(entry -> {
Address serviceAddress = getServiceAddress(member);
ServiceInfo info = ServiceInfo.from(entry.getKey());
ServiceReference serviceRef = new ServiceReference(member.id(), info.getServiceName(), info.methods(), serviceAddress);
LOGGER.debug("Member: {} is {} : {}", member, type, serviceRef);
if (type.equals(DiscoveryType.ADDED) || type.equals(DiscoveryType.DISCOVERED)) {
if (!serviceInstances.containsKey(serviceRef)) {
serviceInstances.putIfAbsent(serviceRef, new RemoteServiceInstance(microservices.sender(), serviceRef, info.getTags()));
LOGGER.info("Service Reference was ADDED since new Member has joined the cluster {} : {}", member, serviceRef);
}
} else if (type.equals(DiscoveryType.REMOVED)) {
serviceInstances.remove(serviceRef);
LOGGER.info("Service Reference was REMOVED since Member have left the cluster {} : {}", member, serviceRef);
}
});
}
use of io.scalecube.transport.Address in project scalecube by scalecube.
the class MembershipProtocolTest method assertTrusted.
private void assertTrusted(MembershipProtocolImpl membership, Address... expected) {
List<Address> actual = getAddressesWithStatus(membership, MemberStatus.ALIVE);
assertEquals("Expected " + expected.length + " trusted members " + Arrays.toString(expected) + ", but actual: " + actual, expected.length, actual.size());
for (Address member : expected) {
assertTrue("Expected to trust " + member + ", but actual: " + actual, actual.contains(member));
}
}
Aggregations