Search in sources :

Example 36 with Address

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

the class MicroservicesExample method main.

public static void main(String[] args) throws Exception {
    Address providerAddress = onProvider();
    onConsumer(providerAddress);
}
Also used : Address(io.scalecube.transport.Address)

Example 37 with Address

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

the class MembershipProtocolTest method testInitialPhaseOk.

@Test
public void testInitialPhaseOk() {
    Transport a = Transport.bindAwait(true);
    Transport b = Transport.bindAwait(true);
    Transport c = Transport.bindAwait(true);
    List<Address> members = ImmutableList.of(a.address(), b.address(), c.address());
    MembershipProtocolImpl cm_a = createMembership(a, members);
    MembershipProtocolImpl cm_b = createMembership(b, members);
    MembershipProtocolImpl cm_c = createMembership(c, members);
    try {
        awaitSeconds(1);
        assertTrusted(cm_a, a.address(), b.address(), c.address());
        assertNoSuspected(cm_a);
        assertTrusted(cm_b, a.address(), b.address(), c.address());
        assertNoSuspected(cm_b);
        assertTrusted(cm_c, a.address(), b.address(), c.address());
        assertNoSuspected(cm_c);
    } finally {
        stopAll(cm_a, cm_b, cm_c);
    }
}
Also used : Address(io.scalecube.transport.Address) InetAddress(java.net.InetAddress) Transport(io.scalecube.transport.Transport) Test(org.junit.Test) BaseTest(io.scalecube.testlib.BaseTest)

Example 38 with Address

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

the class MembershipProtocolTest method testDoublePartitionThenRecover.

@Test
public void testDoublePartitionThenRecover() {
    Transport a = Transport.bindAwait(true);
    Transport b = Transport.bindAwait(true);
    Transport c = Transport.bindAwait(true);
    List<Address> members = ImmutableList.of(a.address(), b.address(), c.address());
    MembershipProtocolImpl cm_a = createMembership(a, members);
    MembershipProtocolImpl cm_b = createMembership(b, members);
    MembershipProtocolImpl cm_c = createMembership(c, members);
    try {
        awaitSeconds(1);
        // Check all trusted
        assertTrusted(cm_a, a.address(), b.address(), c.address());
        assertNoSuspected(cm_a);
        assertTrusted(cm_b, a.address(), b.address(), c.address());
        assertNoSuspected(cm_b);
        assertTrusted(cm_c, a.address(), b.address(), c.address());
        assertNoSuspected(cm_c);
        // Node b lost network
        b.networkEmulator().block(Arrays.asList(a.address(), c.address()));
        a.networkEmulator().block(b.address());
        c.networkEmulator().block(b.address());
        awaitSeconds(1);
        // Check partition: {b}, {a, c}
        assertTrusted(cm_a, a.address(), c.address());
        assertSuspected(cm_a, b.address());
        assertTrusted(cm_b, b.address());
        assertSuspected(cm_b, a.address(), c.address());
        assertTrusted(cm_c, a.address(), c.address());
        assertSuspected(cm_c, b.address());
        // Node a and c lost network
        a.networkEmulator().block(c.address());
        c.networkEmulator().block(a.address());
        awaitSeconds(1);
        // Check partition: {a}, {b}, {c}
        assertTrusted(cm_a, a.address());
        assertSuspected(cm_a, b.address(), c.address());
        assertTrusted(cm_b, b.address());
        assertSuspected(cm_b, a.address(), c.address());
        assertTrusted(cm_c, c.address());
        assertSuspected(cm_c, b.address(), a.address());
        // Recover network
        a.networkEmulator().unblockAll();
        b.networkEmulator().unblockAll();
        c.networkEmulator().unblockAll();
        awaitSeconds(1);
        // Check all trusted again
        assertTrusted(cm_a, a.address(), b.address(), c.address());
        assertNoSuspected(cm_a);
        assertTrusted(cm_b, a.address(), b.address(), c.address());
        assertNoSuspected(cm_b);
        assertTrusted(cm_c, a.address(), b.address(), c.address());
        assertNoSuspected(cm_c);
    } finally {
        stopAll(cm_a, cm_b, cm_c);
    }
}
Also used : Address(io.scalecube.transport.Address) InetAddress(java.net.InetAddress) Transport(io.scalecube.transport.Transport) Test(org.junit.Test) BaseTest(io.scalecube.testlib.BaseTest)

Example 39 with Address

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

the class MembershipProtocolTest method testMemberLostNetworkThenRecover.

@Test
public void testMemberLostNetworkThenRecover() {
    Transport a = Transport.bindAwait(true);
    Transport b = Transport.bindAwait(true);
    Transport c = Transport.bindAwait(true);
    List<Address> members = ImmutableList.of(a.address(), b.address(), c.address());
    MembershipProtocolImpl cm_a = createMembership(a, members);
    MembershipProtocolImpl cm_b = createMembership(b, members);
    MembershipProtocolImpl cm_c = createMembership(c, members);
    try {
        awaitSeconds(1);
        // Check all trusted
        assertTrusted(cm_a, a.address(), b.address(), c.address());
        assertNoSuspected(cm_a);
        assertTrusted(cm_b, a.address(), b.address(), c.address());
        assertNoSuspected(cm_b);
        assertTrusted(cm_c, a.address(), b.address(), c.address());
        assertNoSuspected(cm_c);
        // Node b lost network
        b.networkEmulator().block(Arrays.asList(a.address(), c.address()));
        a.networkEmulator().block(b.address());
        c.networkEmulator().block(b.address());
        awaitSeconds(1);
        // Check partition: {b}, {a, c}
        assertTrusted(cm_a, a.address(), c.address());
        assertSuspected(cm_a, b.address());
        assertTrusted(cm_b, b.address());
        assertSuspected(cm_b, a.address(), c.address());
        assertTrusted(cm_c, a.address(), c.address());
        assertSuspected(cm_c, b.address());
        // Node b recover network
        a.networkEmulator().unblockAll();
        b.networkEmulator().unblockAll();
        c.networkEmulator().unblockAll();
        awaitSeconds(1);
        // Check all trusted again
        assertTrusted(cm_a, a.address(), b.address(), c.address());
        assertNoSuspected(cm_a);
        assertTrusted(cm_b, a.address(), b.address(), c.address());
        assertNoSuspected(cm_b);
        assertTrusted(cm_c, a.address(), b.address(), c.address());
        assertNoSuspected(cm_c);
    } finally {
        stopAll(cm_a, cm_b, cm_c);
    }
}
Also used : Address(io.scalecube.transport.Address) InetAddress(java.net.InetAddress) Transport(io.scalecube.transport.Transport) Test(org.junit.Test) BaseTest(io.scalecube.testlib.BaseTest)

Example 40 with Address

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

the class ListeningServerStream method bind.

/**
 * Binds asynchronously according to config object that is present at the moment of bind operation.
 *
 * @return listening server address
 */
public CompletableFuture<Address> bind() {
    CompletableFuture<Address> promise = new CompletableFuture<>();
    NettyServerTransport serverTransport = new NettyServerTransport(config, serverStream::subscribe);
    serverTransport.bind().whenComplete((serverTransport1, throwable) -> {
        if (serverTransport1 != null) {
            // register cleanup process upfront
            serverStream.listenClose(aVoid -> serverTransport1.unbind());
            // complete promise
            serverTransport1.getServerAddress().ifPresent(promise::complete);
        }
        if (throwable != null) {
            promise.completeExceptionally(throwable);
        }
    });
    return promise;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) Address(io.scalecube.transport.Address) NettyServerTransport(io.scalecube.streams.netty.NettyServerTransport)

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