Search in sources :

Example 31 with Address

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());
}
Also used : Address(io.scalecube.transport.Address) Test(org.junit.Test)

Example 32 with Address

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)));
}
Also used : Address(io.scalecube.transport.Address) Test(org.junit.Test)

Example 33 with Address

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)));
}
Also used : Address(io.scalecube.transport.Address) Test(org.junit.Test)

Example 34 with Address

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);
        }
    });
}
Also used : Logger(org.slf4j.Logger) Address(io.scalecube.transport.Address) Collection(java.util.Collection) LoggerFactory(org.slf4j.LoggerFactory) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Collectors(java.util.stream.Collectors) ConcurrentMap(java.util.concurrent.ConcurrentMap) TimeUnit(java.util.concurrent.TimeUnit) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Metrics(io.scalecube.services.metrics.Metrics) List(java.util.List) ServiceConfig(io.scalecube.services.ServicesConfig.Builder.ServiceConfig) Member(io.scalecube.cluster.Member) Map(java.util.Map) Optional(java.util.Optional) Collections(java.util.Collections) Address(io.scalecube.transport.Address)

Example 35 with Address

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));
    }
}
Also used : Address(io.scalecube.transport.Address) InetAddress(java.net.InetAddress)

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