Search in sources :

Example 16 with Address

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

the class FailureDetectorTest method testMemberStatusChangeAfterNetworkRecovery.

@Test
public void testMemberStatusChangeAfterNetworkRecovery() throws Exception {
    // Create transports
    Transport a = Transport.bindAwait(true);
    Transport b = Transport.bindAwait(true);
    List<Address> members = Arrays.asList(a.address(), b.address());
    // Create failure detectors
    FailureDetectorImpl fd_a = createFD(a, members);
    FailureDetectorImpl fd_b = createFD(b, members);
    List<FailureDetectorImpl> fdetectors = Arrays.asList(fd_a, fd_b);
    // Traffic is blocked initially on both sides: A--X-->B, B--X-->A
    a.networkEmulator().block(b.address());
    b.networkEmulator().block(a.address());
    Future<List<FailureDetectorEvent>> list_a = listenNextEventFor(fd_a, members);
    Future<List<FailureDetectorEvent>> list_b = listenNextEventFor(fd_b, members);
    try {
        start(fdetectors);
        assertStatus(a.address(), SUSPECT, awaitEvents(list_a), b.address());
        assertStatus(b.address(), SUSPECT, awaitEvents(list_b), a.address());
        // Unblock A and B members: A-->B, B-->A
        a.networkEmulator().unblockAll();
        b.networkEmulator().unblockAll();
        TimeUnit.SECONDS.sleep(2);
        // Check that members recover
        list_a = listenNextEventFor(fd_a, members);
        list_b = listenNextEventFor(fd_b, members);
        assertStatus(a.address(), ALIVE, awaitEvents(list_a), b.address());
        assertStatus(b.address(), ALIVE, awaitEvents(list_b), a.address());
    } finally {
        stop(fdetectors);
    }
}
Also used : Address(io.scalecube.transport.Address) ArrayList(java.util.ArrayList) List(java.util.List) Transport(io.scalecube.transport.Transport) Test(org.junit.Test) BaseTest(io.scalecube.testlib.BaseTest)

Example 17 with Address

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

the class FailureDetectorTest method testStatusChangeAfterMemberRestart.

@Test
public void testStatusChangeAfterMemberRestart() throws Exception {
    // Create transports
    Transport a = Transport.bindAwait(true);
    Transport b = Transport.bindAwait(true);
    Transport x = Transport.bindAwait(true);
    List<Address> members = Arrays.asList(a.address(), b.address(), x.address());
    // Create failure detectors
    FailureDetectorImpl fd_a = createFD(a, members);
    FailureDetectorImpl fd_b = createFD(b, members);
    FailureDetectorImpl fd_x = createFD(x, members);
    List<FailureDetectorImpl> fdetectors = Arrays.asList(fd_a, fd_b, fd_x);
    Future<List<FailureDetectorEvent>> list_a = listenNextEventFor(fd_a, members);
    Future<List<FailureDetectorEvent>> list_b = listenNextEventFor(fd_b, members);
    Future<List<FailureDetectorEvent>> list_x = listenNextEventFor(fd_x, members);
    // Restarted member attributes are not initialized
    Transport xx;
    FailureDetectorImpl fd_xx;
    try {
        start(fdetectors);
        assertStatus(a.address(), ALIVE, awaitEvents(list_a), b.address(), x.address());
        assertStatus(b.address(), ALIVE, awaitEvents(list_b), a.address(), x.address());
        assertStatus(x.address(), ALIVE, awaitEvents(list_x), a.address(), b.address());
        // stop node X
        stop(Lists.newArrayList(fd_x));
        TimeUnit.SECONDS.sleep(2);
        // restart node X as XX
        xx = Transport.bindAwait(TransportConfig.builder().port(x.address().port()).portAutoIncrement(false).useNetworkEmulator(true).build());
        assertEquals(x.address(), xx.address());
        fdetectors = Arrays.asList(fd_a, fd_b, fd_xx = createFD(xx, members));
        // actual restart here
        fd_xx.start();
        TimeUnit.SECONDS.sleep(2);
        list_a = listenNextEventFor(fd_a, members);
        list_b = listenNextEventFor(fd_b, members);
        Future<List<FailureDetectorEvent>> list_xx = listenNextEventFor(fd_xx, members);
        // TODO [AK]: It would be more correct to consider restarted member as a new member, so x is still suspected!
        assertStatus(a.address(), ALIVE, awaitEvents(list_a), b.address(), xx.address());
        assertStatus(b.address(), ALIVE, awaitEvents(list_b), a.address(), xx.address());
        assertStatus(xx.address(), ALIVE, awaitEvents(list_xx), a.address(), b.address());
    } finally {
        stop(fdetectors);
    }
}
Also used : Address(io.scalecube.transport.Address) ArrayList(java.util.ArrayList) List(java.util.List) Transport(io.scalecube.transport.Transport) Test(org.junit.Test) BaseTest(io.scalecube.testlib.BaseTest)

Example 18 with Address

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

the class FailureDetectorTest method testTrusted.

@Test
public void testTrusted() {
    // Create transports
    Transport a = Transport.bindAwait(true);
    Transport b = Transport.bindAwait(true);
    Transport c = Transport.bindAwait(true);
    List<Address> members = Arrays.asList(a.address(), b.address(), c.address());
    // Create failure detectors
    FailureDetectorImpl fd_a = createFD(a, members);
    FailureDetectorImpl fd_b = createFD(b, members);
    FailureDetectorImpl fd_c = createFD(c, members);
    List<FailureDetectorImpl> fdetectors = Arrays.asList(fd_a, fd_b, fd_c);
    try {
        start(fdetectors);
        Future<List<FailureDetectorEvent>> list_a = listenNextEventFor(fd_a, members);
        Future<List<FailureDetectorEvent>> list_b = listenNextEventFor(fd_b, members);
        Future<List<FailureDetectorEvent>> list_c = listenNextEventFor(fd_c, members);
        assertStatus(a.address(), ALIVE, awaitEvents(list_a), b.address(), c.address());
        assertStatus(b.address(), ALIVE, awaitEvents(list_b), a.address(), c.address());
        assertStatus(c.address(), ALIVE, awaitEvents(list_c), a.address(), b.address());
    } finally {
        stop(fdetectors);
    }
}
Also used : Address(io.scalecube.transport.Address) ArrayList(java.util.ArrayList) List(java.util.List) Transport(io.scalecube.transport.Transport) Test(org.junit.Test) BaseTest(io.scalecube.testlib.BaseTest)

Example 19 with Address

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

the class FailureDetectorTest method testSuspected.

@Test
public void testSuspected() {
    // Create transports
    Transport a = Transport.bindAwait(true);
    Transport b = Transport.bindAwait(true);
    Transport c = Transport.bindAwait(true);
    List<Address> members = Arrays.asList(a.address(), b.address(), c.address());
    // Create failure detectors
    FailureDetectorImpl fd_a = createFD(a, members);
    FailureDetectorImpl fd_b = createFD(b, members);
    FailureDetectorImpl fd_c = createFD(c, members);
    List<FailureDetectorImpl> fdetectors = Arrays.asList(fd_a, fd_b, fd_c);
    // block all traffic
    a.networkEmulator().block(members);
    b.networkEmulator().block(members);
    c.networkEmulator().block(members);
    try {
        start(fdetectors);
        Future<List<FailureDetectorEvent>> list_a = listenNextEventFor(fd_a, members);
        Future<List<FailureDetectorEvent>> list_b = listenNextEventFor(fd_b, members);
        Future<List<FailureDetectorEvent>> list_c = listenNextEventFor(fd_c, members);
        assertStatus(a.address(), SUSPECT, awaitEvents(list_a), b.address(), c.address());
        assertStatus(b.address(), SUSPECT, awaitEvents(list_b), a.address(), c.address());
        assertStatus(c.address(), SUSPECT, awaitEvents(list_c), a.address(), b.address());
    } finally {
        a.networkEmulator().unblockAll();
        b.networkEmulator().unblockAll();
        c.networkEmulator().unblockAll();
        stop(fdetectors);
    }
}
Also used : Address(io.scalecube.transport.Address) ArrayList(java.util.ArrayList) List(java.util.List) Transport(io.scalecube.transport.Transport) Test(org.junit.Test) BaseTest(io.scalecube.testlib.BaseTest)

Example 20 with Address

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

the class FailureDetectorTest method listenNextEventFor.

private Future<List<FailureDetectorEvent>> listenNextEventFor(FailureDetectorImpl fd, List<Address> addresses) {
    addresses = new ArrayList<>(addresses);
    // exclude self
    addresses.remove(fd.getTransport().address());
    checkArgument(!addresses.isEmpty());
    List<CompletableFuture<FailureDetectorEvent>> resultFuture = new ArrayList<>();
    for (final Address member : addresses) {
        final CompletableFuture<FailureDetectorEvent> future = new CompletableFuture<>();
        fd.listen().filter(event -> event.member().address() == member).subscribe(future::complete);
        resultFuture.add(future);
    }
    return allOf(resultFuture);
}
Also used : Arrays(java.util.Arrays) Address(io.scalecube.transport.Address) MembershipProtocol(io.scalecube.cluster.membership.MembershipProtocol) Collection(java.util.Collection) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) CompletableFuture(java.util.concurrent.CompletableFuture) MemberStatus(io.scalecube.cluster.membership.MemberStatus) SUSPECT(io.scalecube.cluster.membership.MemberStatus.SUSPECT) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) TimeUnit(java.util.concurrent.TimeUnit) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) ClusterConfig(io.scalecube.cluster.ClusterConfig) List(java.util.List) Future(java.util.concurrent.Future) Lists(com.google.common.collect.Lists) ALIVE(io.scalecube.cluster.membership.MemberStatus.ALIVE) Member(io.scalecube.cluster.Member) Transport(io.scalecube.transport.Transport) TransportConfig(io.scalecube.transport.TransportConfig) DummyMembershipProtocol(io.scalecube.cluster.membership.DummyMembershipProtocol) BaseTest(io.scalecube.testlib.BaseTest) Assert.assertEquals(org.junit.Assert.assertEquals) CompletableFuture(java.util.concurrent.CompletableFuture) Address(io.scalecube.transport.Address) ArrayList(java.util.ArrayList)

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