Search in sources :

Example 11 with DISCARD

use of org.jgroups.protocols.DISCARD in project JGroups by belaban.

the class DiscardTest method _testLosslessReception.

private void _testLosslessReception(boolean discard) throws Exception {
    long start, stop;
    a = createChannel().name("A");
    a.setReceiver(new MyReceiver(ch1_all_received, NUM_MSGS, "A"));
    b = createChannel().name("B");
    b.setReceiver(new MyReceiver(ch2_all_received, NUM_MSGS, "B"));
    makeUnique(a, b);
    a.connect(GROUP);
    b.connect(GROUP);
    Util.waitUntilAllChannelsHaveSameView(10000, 500, a, b);
    if (discard) {
        DISCARD discard_prot = new DISCARD();
        Properties properties = new Properties();
        properties.setProperty("down", "0.1");
        a.getProtocolStack().insertProtocol(discard_prot, ProtocolStack.Position.BELOW, MERGE3.class);
        discard_prot = new DISCARD();
        properties = new Properties();
        properties.setProperty("down", "0.1");
        b.getProtocolStack().insertProtocol(discard_prot, ProtocolStack.Position.BELOW, MERGE3.class);
    }
    System.out.printf("sending %d %d-byte messages to all members (including myself)\n", NUM_MSGS, MSG_SIZE);
    start = System.currentTimeMillis();
    for (int i = 0; i < NUM_MSGS; i++) {
        Message msg = createMessage(MSG_SIZE);
        a.send(msg);
        if (i % 1000 == 0)
            System.out.println("-- sent " + i + " messages");
    }
    System.out.println("-- waiting for ch1 and ch2 to receive " + NUM_MSGS + " messages");
    Long num_msgs;
    num_msgs = ch1_all_received.getResultWithTimeout(10000);
    System.out.println("-- received " + num_msgs + " messages on ch1");
    num_msgs = ch2_all_received.getResultWithTimeout(10000);
    stop = System.currentTimeMillis();
    System.out.println("-- received " + num_msgs + " messages on ch2");
    long diff = stop - start;
    double msgs_sec = NUM_MSGS / (diff / 1000.0);
    System.out.printf("== Sent and received %d in %d ms, %.2f msgs/sec\n", NUM_MSGS, diff, msgs_sec);
}
Also used : DISCARD(org.jgroups.protocols.DISCARD) Properties(java.util.Properties)

Aggregations

DISCARD (org.jgroups.protocols.DISCARD)11 ProtocolStack (org.jgroups.stack.ProtocolStack)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 GMS (org.jgroups.protocols.pbcast.GMS)4 SHARED_LOOPBACK (org.jgroups.protocols.SHARED_LOOPBACK)2 SHARED_LOOPBACK_PING (org.jgroups.protocols.SHARED_LOOPBACK_PING)2 UNICAST3 (org.jgroups.protocols.UNICAST3)2 NAKACK2 (org.jgroups.protocols.pbcast.NAKACK2)2 STABLE (org.jgroups.protocols.pbcast.STABLE)2 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 Properties (java.util.Properties)1 ServletException (javax.servlet.ServletException)1 Event (org.jgroups.Event)1 View (org.jgroups.View)1 MergeId (org.jgroups.util.MergeId)1 Test (org.testng.annotations.Test)1