use of org.jgroups.util.MutableDigest in project JGroups by belaban.
the class NAKACK_StressTest method start.
private static void start(final int num_threads, final int num_msgs, boolean oob) {
final NAKACK2 nak = new NAKACK2();
final AtomicInteger counter = new AtomicInteger(num_msgs);
final AtomicLong seqno = new AtomicLong(1);
final AtomicInteger delivered_msgs = new AtomicInteger(0);
final Lock lock = new ReentrantLock();
final Condition all_msgs_delivered = lock.newCondition();
final ConcurrentLinkedQueue<Long> delivered_msg_list = new ConcurrentLinkedQueue<>();
final Address local_addr = Util.createRandomAddress("A");
final Address sender = Util.createRandomAddress("B");
nak.setDownProtocol(new Protocol() {
public Object down(Event evt) {
return null;
}
});
nak.setUpProtocol(new Protocol() {
public Object up(Message msg) {
delivered_msgs.incrementAndGet();
NakAckHeader2 hdr = msg.getHeader(NAKACK_ID);
if (hdr != null)
delivered_msg_list.add(hdr.getSeqno());
if (delivered_msgs.get() >= num_msgs) {
lock.lock();
try {
all_msgs_delivered.signalAll();
} finally {
lock.unlock();
}
}
return null;
}
public void up(MessageBatch batch) {
for (Message msg : batch) {
delivered_msgs.incrementAndGet();
NakAckHeader2 hdr = (NakAckHeader2) msg.getHeader(NAKACK_ID);
if (hdr != null)
delivered_msg_list.add(hdr.getSeqno());
if (delivered_msgs.get() >= num_msgs) {
lock.lock();
try {
all_msgs_delivered.signalAll();
} finally {
lock.unlock();
}
}
}
}
});
nak.setDiscardDeliveredMsgs(true);
nak.down(new Event(Event.SET_LOCAL_ADDRESS, local_addr));
nak.down(new Event(Event.BECOME_SERVER));
View view = View.create(local_addr, 1, local_addr, sender);
nak.down(new Event(Event.VIEW_CHANGE, view));
MutableDigest digest = new MutableDigest(view.getMembersRaw());
digest.set(local_addr, 0, 0);
digest.set(sender, 0, 0);
nak.down(new Event(Event.SET_DIGEST, digest));
final CountDownLatch latch = new CountDownLatch(1);
Sender[] adders = new Sender[num_threads];
for (int i = 0; i < adders.length; i++) {
adders[i] = new Sender(nak, latch, counter, seqno, oob, sender);
adders[i].start();
}
long start = System.currentTimeMillis();
// starts all adders
latch.countDown();
int max_tries = 30;
lock.lock();
try {
while (delivered_msgs.get() < num_msgs && max_tries-- > 0) {
try {
all_msgs_delivered.await(1000, TimeUnit.MILLISECONDS);
System.out.println("received " + delivered_msgs.get() + " msgs");
} catch (InterruptedException e) {
e.printStackTrace();
}
}
} finally {
lock.unlock();
}
long time = System.currentTimeMillis() - start;
double requests_sec = num_msgs / (time / 1000.0);
System.out.printf("\nTime: %d ms, %.2f requests / sec\n", time, requests_sec);
System.out.println("Delivered messages: " + delivered_msg_list.size());
if (delivered_msg_list.size() < 100)
System.out.println("Elements: " + delivered_msg_list);
nak.stop();
List<Long> results = new ArrayList<>(delivered_msg_list);
if (oob)
Collections.sort(results);
assert results.size() == num_msgs : "expected " + num_msgs + ", but got " + results.size();
System.out.println("Checking results consistency");
int i = 1;
for (Long num : results) {
if (num != i) {
assert i == num : "expected " + i + " but got " + num;
return;
}
i++;
}
System.out.println("OK");
}
use of org.jgroups.util.MutableDigest in project JGroups by belaban.
the class MergeTest3 method createPartition.
protected void createPartition(JChannel... channels) {
// find the highest view-id +1
long view_id = 1;
for (JChannel ch : channels) view_id = Math.max(ch.getView().getViewId().getId(), view_id);
view_id++;
List<Address> members = getMembers(channels);
Collections.sort(members);
Address coord = members.get(0);
View view = new View(coord, view_id, members);
MutableDigest digest = new MutableDigest(view.getMembersRaw());
for (JChannel ch : channels) {
NAKACK2 nakack = (NAKACK2) ch.getProtocolStack().findProtocol(NAKACK2.class);
digest.merge(nakack.getDigest(ch.getAddress()));
}
for (JChannel ch : channels) {
GMS gms = (GMS) ch.getProtocolStack().findProtocol(GMS.class);
gms.installView(view, digest);
}
}
use of org.jgroups.util.MutableDigest in project JGroups by belaban.
the class DigestTest method testIncrementHighSeqno.
public void testIncrementHighSeqno() {
md = new MutableDigest(members);
md.set(a1, 1, 100).set(a2, 3, 300).set(a3, 7, 700);
long tmp = md.get(a1)[0];
md.set(a1, tmp + 1, tmp + 1);
Assert.assertEquals(md.get(a1)[0], tmp + 1);
tmp = md.get(a2)[0];
md.set(a2, tmp + 1, tmp + 1);
Assert.assertEquals(md.get(a2)[0], tmp + 1);
tmp = md.get(a3)[0];
md.set(a3, tmp + 1, tmp + 1);
Assert.assertEquals(md.get(a3)[0], tmp + 1);
}
use of org.jgroups.util.MutableDigest in project JGroups by belaban.
the class DigestTest method testMerge.
public void testMerge() {
MutableDigest digest = new MutableDigest(members).set(a1, 499, 502).set(a2, 26, 27).set(a3, 26, 35);
System.out.println("d: " + d);
System.out.println("digest: " + digest);
digest.merge(d);
System.out.println("merged digest: " + digest);
Assert.assertEquals(d.capacity(), 3);
Assert.assertEquals(digest.capacity(), 3);
Assert.assertEquals(digest.get(a1)[0], 500);
Assert.assertEquals(digest.get(a1)[1], 502);
Assert.assertEquals(digest.get(a2)[0], 26);
Assert.assertEquals(digest.get(a2)[1], 27);
Assert.assertEquals(digest.get(a3)[0], 26);
Assert.assertEquals(digest.get(a3)[1], 35);
}
use of org.jgroups.util.MutableDigest in project JGroups by belaban.
the class DigestTest method testConstructor1.
public void testConstructor1() {
Digest dd = new MutableDigest(members);
Assert.assertEquals(dd.capacity(), members.length);
}
Aggregations