Search in sources :

Example 1 with Address

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

the class AddressTest method testParseUnknownHostPort.

@Test
public void testParseUnknownHostPort() throws Exception {
    Address address = Address.from("host:1111");
    assertEquals(1111, address.port());
    assertEquals("host", address.host());
}
Also used : Address(io.scalecube.transport.Address) Test(org.junit.Test) BaseTest(io.scalecube.testlib.BaseTest)

Example 2 with Address

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

the class ServiceInstanceTest method test_localService_instance.

@Test
public void test_localService_instance() {
    Address address = Address.create("localhost", 4000);
    ServiceConfig conf = new ServiceConfig(new GreetingServiceImpl());
    LocalServiceInstance instance = new LocalServiceInstance(conf, address, "a", "b", new HashMap<>());
    assertEquals(instance.toString(), "LocalServiceInstance [serviceObject=GreetingServiceImpl [], memberId=a]");
    assertTrue(instance.tags().isEmpty());
    assertEquals(instance.memberId(), "a");
    assertEquals(instance.serviceName(), "b");
    try {
        new LocalServiceInstance(null, address, "a", "b", new HashMap<>());
    } catch (Exception ex) {
        assertEquals(ex.toString(), "java.lang.IllegalArgumentException: serviceConfig can't be null");
    }
    try {
        new LocalServiceInstance(conf, null, "a", "b", new HashMap<>());
    } catch (Exception ex) {
        assertEquals(ex.toString(), "java.lang.IllegalArgumentException: address can't be null");
    }
    try {
        new LocalServiceInstance(conf, address, null, "b", new HashMap<>());
    } catch (Exception ex) {
        assertEquals(ex.toString(), "java.lang.IllegalArgumentException: memberId can't be null");
    }
    try {
        new LocalServiceInstance(conf, address, "a", null, new HashMap<>());
    } catch (Exception ex) {
        assertEquals(ex.toString(), "java.lang.IllegalArgumentException: serviceName can't be null");
    }
    try {
        new LocalServiceInstance(conf, address, "a", "b", null);
    } catch (Exception ex) {
        assertEquals(ex.toString(), "java.lang.IllegalArgumentException: methods can't be null");
    }
    try {
        new LocalServiceInstance(conf, address, "a", "b", new HashMap<>()).invoke(null);
    } catch (Exception ex) {
        assertEquals(ex.toString(), "java.lang.IllegalArgumentException: message can't be null");
    }
}
Also used : Address(io.scalecube.transport.Address) ServiceConfig(io.scalecube.services.ServicesConfig.Builder.ServiceConfig) HashMap(java.util.HashMap) Test(org.junit.Test) BaseTest(io.scalecube.testlib.BaseTest)

Example 3 with Address

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

the class FailureDetectorTest method testSuspectedMemberWithNormalNetworkGetsPartitioned.

@Test
public void testSuspectedMemberWithNormalNetworkGetsPartitioned() throws Exception {
    // Create transports
    Transport a = Transport.bindAwait(true);
    Transport b = Transport.bindAwait(true);
    Transport c = Transport.bindAwait(true);
    Transport d = Transport.bindAwait(true);
    List<Address> members = Arrays.asList(a.address(), b.address(), c.address(), d.address());
    // Create failure detectors
    FailureDetectorImpl fd_a = createFD(a, members);
    FailureDetectorImpl fd_b = createFD(b, members);
    FailureDetectorImpl fd_c = createFD(c, members);
    FailureDetectorImpl fd_d = createFD(d, members);
    List<FailureDetectorImpl> fdetectors = Arrays.asList(fd_a, fd_b, fd_c, fd_d);
    // Block traffic to node D on other members
    a.networkEmulator().block(d.address());
    b.networkEmulator().block(d.address());
    c.networkEmulator().block(d.address());
    try {
        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);
        Future<List<FailureDetectorEvent>> list_d = listenNextEventFor(fd_d, members);
        start(fdetectors);
        assertStatus(a.address(), SUSPECT, awaitEvents(list_a), d.address());
        assertStatus(b.address(), SUSPECT, awaitEvents(list_b), d.address());
        assertStatus(c.address(), SUSPECT, awaitEvents(list_c), d.address());
        // node D
        assertStatus(d.address(), SUSPECT, awaitEvents(list_d), a.address(), b.address(), c.address());
        // partitioned
        // Unblock traffic to member D on other members
        a.networkEmulator().unblockAll();
        b.networkEmulator().unblockAll();
        c.networkEmulator().unblockAll();
        TimeUnit.SECONDS.sleep(4);
        list_a = listenNextEventFor(fd_a, members);
        list_b = listenNextEventFor(fd_b, members);
        list_c = listenNextEventFor(fd_c, members);
        list_d = listenNextEventFor(fd_d, members);
        // Check member D recovers
        assertStatus(a.address(), ALIVE, awaitEvents(list_a), b.address(), c.address(), d.address());
        assertStatus(b.address(), ALIVE, awaitEvents(list_b), a.address(), c.address(), d.address());
        assertStatus(c.address(), ALIVE, awaitEvents(list_c), a.address(), b.address(), d.address());
        assertStatus(d.address(), ALIVE, awaitEvents(list_d), a.address(), b.address(), c.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 4 with Address

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

the class FailureDetectorTest method testTrustedDespiteBadNetwork.

@Test
public void testTrustedDespiteBadNetwork() throws Exception {
    // 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);
    // Traffic issue at connection A -> B
    a.networkEmulator().block(b.address());
    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);
    try {
        start(fdetectors);
        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 5 with Address

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

the class FailureDetectorTest method testSuspectedMemberWithBadNetworkGetsPartitioned.

@Test
public void testSuspectedMemberWithBadNetworkGetsPartitioned() throws Exception {
    // Create transports
    Transport a = Transport.bindAwait(true);
    Transport b = Transport.bindAwait(true);
    Transport c = Transport.bindAwait(true);
    Transport d = Transport.bindAwait(true);
    List<Address> members = Arrays.asList(a.address(), b.address(), c.address(), d.address());
    // Create failure detectors
    FailureDetectorImpl fd_a = createFD(a, members);
    FailureDetectorImpl fd_b = createFD(b, members);
    FailureDetectorImpl fd_c = createFD(c, members);
    FailureDetectorImpl fd_d = createFD(d, members);
    List<FailureDetectorImpl> fdetectors = Arrays.asList(fd_a, fd_b, fd_c, fd_d);
    // Block traffic on member A to all cluster members
    a.networkEmulator().block(members);
    try {
        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);
        Future<List<FailureDetectorEvent>> list_d = listenNextEventFor(fd_d, members);
        start(fdetectors);
        // node A
        assertStatus(a.address(), SUSPECT, awaitEvents(list_a), b.address(), c.address(), d.address());
        // partitioned
        assertStatus(b.address(), SUSPECT, awaitEvents(list_b), a.address());
        assertStatus(c.address(), SUSPECT, awaitEvents(list_c), a.address());
        assertStatus(d.address(), SUSPECT, awaitEvents(list_d), a.address());
        // Unblock traffic on member A
        a.networkEmulator().unblockAll();
        TimeUnit.SECONDS.sleep(4);
        list_a = listenNextEventFor(fd_a, members);
        list_b = listenNextEventFor(fd_b, members);
        list_c = listenNextEventFor(fd_c, members);
        list_d = listenNextEventFor(fd_d, members);
        // Check member A recovers
        assertStatus(a.address(), ALIVE, awaitEvents(list_a), b.address(), c.address(), d.address());
        assertStatus(b.address(), ALIVE, awaitEvents(list_b), a.address(), c.address(), d.address());
        assertStatus(c.address(), ALIVE, awaitEvents(list_c), a.address(), b.address(), d.address());
        assertStatus(d.address(), ALIVE, awaitEvents(list_d), a.address(), b.address(), c.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)

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