Search in sources :

Example 6 with Address

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

the class MembershipProtocolImpl method doSync.

private void doSync() {
    try {
        Address syncMember = selectSyncAddress();
        if (syncMember == null) {
            return;
        }
        Message syncMsg = prepareSyncDataMsg(SYNC, null);
        transport.send(syncMember, syncMsg);
        LOGGER.debug("Send Sync to {}: {}", syncMember, syncMsg);
    } catch (Exception cause) {
        LOGGER.error("Unhandled exception: {}", cause, cause);
    }
}
Also used : Address(io.scalecube.transport.Address) Message(io.scalecube.transport.Message)

Example 7 with Address

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

the class MembershipProtocolTest method testLongNetworkPartitionNoRecovery.

@Test
public void testLongNetworkPartitionNoRecovery() {
    Transport a = Transport.bindAwait(true);
    Transport b = Transport.bindAwait(true);
    Transport c = Transport.bindAwait(true);
    Transport d = Transport.bindAwait(true);
    List<Address> members = ImmutableList.of(a.address(), b.address(), c.address(), d.address());
    MembershipProtocolImpl cm_a = createMembership(a, members);
    MembershipProtocolImpl cm_b = createMembership(b, members);
    MembershipProtocolImpl cm_c = createMembership(c, members);
    MembershipProtocolImpl cm_d = createMembership(d, members);
    try {
        awaitSeconds(1);
        assertTrusted(cm_a, a.address(), b.address(), c.address(), d.address());
        assertTrusted(cm_b, a.address(), b.address(), c.address(), d.address());
        assertTrusted(cm_c, a.address(), b.address(), c.address(), d.address());
        assertTrusted(cm_d, a.address(), b.address(), c.address(), d.address());
        a.networkEmulator().block(Arrays.asList(c.address(), d.address()));
        b.networkEmulator().block(Arrays.asList(c.address(), d.address()));
        c.networkEmulator().block(Arrays.asList(a.address(), b.address()));
        d.networkEmulator().block(Arrays.asList(a.address(), b.address()));
        awaitSeconds(2);
        assertTrusted(cm_a, a.address(), b.address());
        assertSuspected(cm_a, c.address(), d.address());
        assertTrusted(cm_b, a.address(), b.address());
        assertSuspected(cm_b, c.address(), d.address());
        assertTrusted(cm_c, c.address(), d.address());
        assertSuspected(cm_c, a.address(), b.address());
        assertTrusted(cm_d, c.address(), d.address());
        assertSuspected(cm_d, a.address(), b.address());
        long suspicionTimeoutSec = ClusterMath.suspicionTimeout(ClusterConfig.DEFAULT_SUSPICION_MULT, 4, TEST_PING_INTERVAL) / 1000;
        // > max suspect time
        awaitSeconds(suspicionTimeoutSec + 1);
        assertTrusted(cm_a, a.address(), b.address());
        assertNoSuspected(cm_a);
        assertTrusted(cm_b, a.address(), b.address());
        assertNoSuspected(cm_b);
        assertTrusted(cm_c, c.address(), d.address());
        assertNoSuspected(cm_c);
        assertTrusted(cm_d, c.address(), d.address());
        assertNoSuspected(cm_d);
    } finally {
        stopAll(cm_a, cm_b, cm_c, cm_d);
    }
}
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 8 with Address

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

the class MembershipProtocolTest method testRestartFailedMembers.

@Test
public void testRestartFailedMembers() {
    Transport a = Transport.bindAwait(true);
    Transport b = Transport.bindAwait(true);
    Transport c = Transport.bindAwait(true);
    Transport d = Transport.bindAwait(true);
    List<Address> members = ImmutableList.of(a.address(), b.address(), c.address(), d.address());
    MembershipProtocolImpl cm_a = createMembership(a, members);
    MembershipProtocolImpl cm_b = createMembership(b, members);
    MembershipProtocolImpl cm_c = createMembership(c, members);
    MembershipProtocolImpl cm_d = createMembership(d, members);
    MembershipProtocolImpl cm_restartedC = null;
    MembershipProtocolImpl cm_restartedD = null;
    try {
        awaitSeconds(1);
        assertTrusted(cm_a, a.address(), b.address(), c.address(), d.address());
        assertTrusted(cm_b, a.address(), b.address(), c.address(), d.address());
        assertTrusted(cm_c, a.address(), b.address(), c.address(), d.address());
        assertTrusted(cm_d, a.address(), b.address(), c.address(), d.address());
        stop(cm_c);
        stop(cm_d);
        awaitSeconds(1);
        assertTrusted(cm_a, a.address(), b.address());
        assertSuspected(cm_a, c.address(), d.address());
        assertTrusted(cm_b, a.address(), b.address());
        assertSuspected(cm_b, c.address(), d.address());
        long suspicionTimeoutSec = ClusterMath.suspicionTimeout(ClusterConfig.DEFAULT_SUSPICION_MULT, 4, TEST_PING_INTERVAL) / 1000;
        // > max suspect time
        awaitSeconds(suspicionTimeoutSec + 1);
        assertTrusted(cm_a, a.address(), b.address());
        assertNoSuspected(cm_a);
        assertTrusted(cm_b, a.address(), b.address());
        assertNoSuspected(cm_b);
        c = Transport.bindAwait(true);
        d = Transport.bindAwait(true);
        cm_restartedC = createMembership(c, Arrays.asList(a.address(), b.address()));
        cm_restartedD = createMembership(d, Arrays.asList(a.address(), b.address()));
        awaitSeconds(1);
        assertTrusted(cm_restartedC, a.address(), b.address(), c.address(), d.address());
        assertNoSuspected(cm_restartedC);
        assertTrusted(cm_restartedD, a.address(), b.address(), c.address(), d.address());
        assertNoSuspected(cm_restartedD);
        assertTrusted(cm_a, a.address(), b.address(), c.address(), d.address());
        assertNoSuspected(cm_a);
        assertTrusted(cm_b, a.address(), b.address(), c.address(), d.address());
        assertNoSuspected(cm_b);
    } finally {
        stopAll(cm_a, cm_b, cm_restartedC, cm_restartedD);
    }
}
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 9 with Address

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

the class MembershipProtocolTest method testNetworkDisabledThenRecovered.

@Test
public void testNetworkDisabledThenRecovered() {
    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);
        a.networkEmulator().block(members);
        b.networkEmulator().block(members);
        c.networkEmulator().block(members);
        awaitSeconds(1);
        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, a.address(), b.address());
        a.networkEmulator().unblockAll();
        b.networkEmulator().unblockAll();
        c.networkEmulator().unblockAll();
        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 10 with Address

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

the class MembershipProtocolTest method assertSuspected.

private void assertSuspected(MembershipProtocolImpl membership, Address... expected) {
    List<Address> actual = getAddressesWithStatus(membership, MemberStatus.SUSPECT);
    assertEquals("Expected " + expected.length + " suspect members " + Arrays.toString(expected) + ", but actual: " + actual, expected.length, actual.size());
    for (Address member : expected) {
        assertTrue("Expected to suspect " + 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