use of com.baidu.hugegraph.concurrent.RowLock in project hugegraph-common by hugegraph.
the class RowLockTest method testRowLockWithMultiThreadsWithRandomKey.
@Test
public void testRowLockWithMultiThreadsWithRandomKey() {
RowLock<Integer> lock = new RowLock<>();
Set<String> names = new HashSet<>(THREADS_NUM);
Assert.assertEquals(0, names.size());
runWithThreads(THREADS_NUM, () -> {
List<Integer> keys = new ArrayList<>(5);
Random random = new Random();
for (int i = 0; i < 5; i++) {
keys.add(random.nextInt(THREADS_NUM));
}
lock.lockAll(new HashSet<>(keys));
names.add(Thread.currentThread().getName());
lock.unlockAll(new HashSet<>(keys));
});
Assert.assertEquals(THREADS_NUM, names.size());
}
use of com.baidu.hugegraph.concurrent.RowLock in project hugegraph-common by hugegraph.
the class RowLockTest method testRowLockWithMultiThreads.
@Test
public void testRowLockWithMultiThreads() {
RowLock<Integer> lock = new RowLock<>();
Set<String> names = new HashSet<>(THREADS_NUM);
List<Integer> keys = new ArrayList<>(5);
Random random = new Random();
for (int i = 0; i < 5; i++) {
keys.add(random.nextInt(THREADS_NUM));
}
Assert.assertEquals(0, names.size());
runWithThreads(THREADS_NUM, () -> {
lock.lockAll(new HashSet<>(keys));
names.add(Thread.currentThread().getName());
lock.unlockAll(new HashSet<>(keys));
});
Assert.assertEquals(THREADS_NUM, names.size());
}