Search in sources :

Example 6 with LockService

use of org.jgroups.blocks.locking.LockService in project JGroups by belaban.

the class LockServiceTest method testConcurrentLockRequestsFromDifferentMembers.

public void testConcurrentLockRequestsFromDifferentMembers() throws Exception {
    int NUM = 10;
    final CyclicBarrier barrier = new CyclicBarrier(NUM + 1);
    TryLocker[] lockers = new TryLocker[NUM];
    LockService[] services = { s1, s2, s3 };
    for (int i = 0; i < lockers.length; i++) {
        Lock mylock = services[i % services.length].getLock(LOCK);
        lockers[i] = new TryLocker(mylock, barrier);
        lockers[i].start();
    }
    barrier.await();
    for (TryLocker locker : lockers) locker.join();
    int num_acquired = 0;
    for (TryLocker locker : lockers) {
        if (locker.acquired) {
            num_acquired++;
        }
    }
    System.out.println("num_acquired = " + num_acquired);
    assert num_acquired == 1 : "expected 1 but got " + num_acquired;
}
Also used : LockService(org.jgroups.blocks.locking.LockService) Lock(java.util.concurrent.locks.Lock)

Example 7 with LockService

use of org.jgroups.blocks.locking.LockService in project JGroups by belaban.

the class LockService_JGRP_2234_Test method init.

@BeforeMethod
protected void init() throws Exception {
    a = createChannel("A");
    s1 = new LockService(a);
    a.connect("LockServiceTest");
    b = createChannel("B");
    s2 = new LockService(b);
    b.connect("LockServiceTest");
    c = createChannel("C");
    s3 = new LockService(c);
    c.connect("LockServiceTest");
    d = createChannel("D");
    s4 = new LockService(d);
    d.connect("LockServiceTest");
    Util.waitUntilAllChannelsHaveSameView(10000, 1000, a, b, c, d);
}
Also used : LockService(org.jgroups.blocks.locking.LockService) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

LockService (org.jgroups.blocks.locking.LockService)7 JChannel (org.jgroups.JChannel)3 BeforeMethod (org.testng.annotations.BeforeMethod)3 CENTRAL_LOCK (org.jgroups.protocols.CENTRAL_LOCK)2 Lock (java.util.concurrent.locks.Lock)1 Protocol (org.jgroups.stack.Protocol)1 BeforeClass (org.testng.annotations.BeforeClass)1