Search in sources :

Example 1 with RingBufferBundlerLockless

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

the class RingBundlerTestLockless method testSendToMultipleDestinations.

public void testSendToMultipleDestinations() throws Exception {
    RingBufferBundlerLockless bundler = new RingBufferBundlerLockless(16);
    RingBundlerTest.MockTransport transport = new RingBundlerTest.MockTransport();
    bundler.init(transport);
    for (int i = 0; i < 6; i++) bundler.send(new EmptyMessage(null));
    int cnt = bundler.size();
    assert cnt == 6;
    bundler._readMessages();
    System.out.println("bundler = " + bundler);
    assert bundler.readIndex() == 6;
    assert bundler.writeIndex() == 6;
    assert bundler.size() == 0;
    assert transport.map.get(null) == 1;
    transport.map.clear();
    for (Message msg : create(10000, null, a, a, a, b, c, d, d, a, null, null, a)) bundler.send(msg);
    System.out.println("bundler = " + bundler);
    cnt = bundler.size();
    assert cnt == 12;
    assert bundler.readIndex() == 6;
    assert bundler.writeIndex() == 2;
    bundler._readMessages();
    assert bundler.readIndex() == 2;
    assert bundler.writeIndex() == 2;
    assert bundler.size() == 0;
    Stream.of(null, a, b, c, d).forEach(msg -> {
        assert transport.map.get(msg) == 1;
    });
}
Also used : BytesMessage(org.jgroups.BytesMessage) Message(org.jgroups.Message) EmptyMessage(org.jgroups.EmptyMessage) RingBufferBundlerLockless(org.jgroups.protocols.RingBufferBundlerLockless) EmptyMessage(org.jgroups.EmptyMessage)

Example 2 with RingBufferBundlerLockless

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

the class RingBundlerTestLockless method testSimpleSend.

public void testSimpleSend() throws Exception {
    RingBufferBundlerLockless bundler = new RingBufferBundlerLockless(16);
    RingBundlerTest.MockTransport transport = new RingBundlerTest.MockTransport();
    bundler.init(transport);
    final CountDownLatch latch = new CountDownLatch(1);
    Sender[] senders = new Sender[20];
    for (int i = 0; i < senders.length; i++) {
        senders[i] = new Sender(latch, bundler);
        senders[i].start();
    }
    latch.countDown();
    for (Sender sender : senders) sender.join();
    System.out.println("bundler = " + bundler);
    bundler._readMessages();
    System.out.println("bundler = " + bundler);
}
Also used : RingBufferBundlerLockless(org.jgroups.protocols.RingBufferBundlerLockless) CountDownLatch(java.util.concurrent.CountDownLatch)

Aggregations

RingBufferBundlerLockless (org.jgroups.protocols.RingBufferBundlerLockless)2 CountDownLatch (java.util.concurrent.CountDownLatch)1 BytesMessage (org.jgroups.BytesMessage)1 EmptyMessage (org.jgroups.EmptyMessage)1 Message (org.jgroups.Message)1