Search in sources :

Example 1 with MemberStatus

use of io.scalecube.cluster.membership.MemberStatus in project scalecube by scalecube.

the class FailureDetectorTest method assertStatus.

/**
 * @param address target member to expect on
 * @param status expected listen status
 * @param events events collection of failure detector events
 * @param expected expected members of the given listenStatus
 */
private void assertStatus(Address address, MemberStatus status, Collection<FailureDetectorEvent> events, Address... expected) {
    List<Address> actual = events.stream().filter(event -> event.status() == status).map(FailureDetectorEvent::member).map(Member::address).collect(Collectors.toList());
    String msg1 = String.format("Node %s expected %s %s members %s, but was: %s", address, expected.length, status, Arrays.toString(expected), events);
    assertEquals(msg1, expected.length, actual.size());
    for (Address member : expected) {
        String msg2 = String.format("Node %s expected as %s %s, but was: %s", address, status, member, events);
        assertTrue(msg2, actual.contains(member));
    }
}
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) Address(io.scalecube.transport.Address)

Aggregations

Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Lists (com.google.common.collect.Lists)1 ClusterConfig (io.scalecube.cluster.ClusterConfig)1 Member (io.scalecube.cluster.Member)1 DummyMembershipProtocol (io.scalecube.cluster.membership.DummyMembershipProtocol)1 MemberStatus (io.scalecube.cluster.membership.MemberStatus)1 ALIVE (io.scalecube.cluster.membership.MemberStatus.ALIVE)1 SUSPECT (io.scalecube.cluster.membership.MemberStatus.SUSPECT)1 MembershipProtocol (io.scalecube.cluster.membership.MembershipProtocol)1 BaseTest (io.scalecube.testlib.BaseTest)1 Address (io.scalecube.transport.Address)1 Transport (io.scalecube.transport.Transport)1 TransportConfig (io.scalecube.transport.TransportConfig)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 List (java.util.List)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 Future (java.util.concurrent.Future)1 TimeUnit (java.util.concurrent.TimeUnit)1