Search in sources :

Example 1 with ClusterProbeImpl

use of suite.net.cluster.impl.ClusterProbeImpl in project suite by stupidsing.

the class ClusterProbeTest method test.

@Test
public void test() throws IOException {
    var nNodes = 3;
    var peers = forInt(nNodes).map2(i -> "NODE" + i, i -> new InetSocketAddress(localHost, 3000 + i)).toMap();
    var probes = // 
    Read.from2(// 
    peers).keys().<String, ClusterProbe>map2(name -> name, // 
    name -> ex(() -> new ClusterProbeImpl(name, peers))).toMap();
    for (var probe : probes.values()) probe.start();
    Sleep.quietly(10 * 1000);
    System.out.println("=== CLUSTER FORMED (" + LocalDateTime.now() + ") ===\n");
    dumpActivePeers(probes);
    assertActiveNodesSize(nNodes, probes);
    for (var probe : probes.values()) probe.stop();
    Sleep.quietly(5 * 1000);
    System.out.println("=== CLUSTER STOPPED (" + LocalDateTime.now() + ") ===\n");
    dumpActivePeers(probes);
    assertActiveNodesSize(0, probes);
}
Also used : LocalDateTime(java.time.LocalDateTime) IOException(java.io.IOException) InetSocketAddress(java.net.InetSocketAddress) Read(primal.MoreVerbs.Read) Streamlet_.forInt(suite.util.Streamlet_.forInt) InetAddress(java.net.InetAddress) Test(org.junit.jupiter.api.Test) Rethrow.ex(primal.statics.Rethrow.ex) Map(java.util.Map) Rethrow(primal.statics.Rethrow) ClusterProbeImpl(suite.net.cluster.impl.ClusterProbeImpl) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Sleep(primal.Verbs.Sleep) InetSocketAddress(java.net.InetSocketAddress) ClusterProbeImpl(suite.net.cluster.impl.ClusterProbeImpl) Test(org.junit.jupiter.api.Test)

Aggregations

IOException (java.io.IOException)1 InetAddress (java.net.InetAddress)1 InetSocketAddress (java.net.InetSocketAddress)1 LocalDateTime (java.time.LocalDateTime)1 Map (java.util.Map)1 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)1 Test (org.junit.jupiter.api.Test)1 Read (primal.MoreVerbs.Read)1 Sleep (primal.Verbs.Sleep)1 Rethrow (primal.statics.Rethrow)1 Rethrow.ex (primal.statics.Rethrow.ex)1 ClusterProbeImpl (suite.net.cluster.impl.ClusterProbeImpl)1 Streamlet_.forInt (suite.util.Streamlet_.forInt)1