use of com.baidu.hugegraph.concurrent.KeyLock in project hugegraph-common by hugegraph.
the class KeyLockTest method testLockUnlockAll.
@Test
public void testLockUnlockAll() {
KeyLock locks = new KeyLock();
List<Lock> ls = locks.lockAll("1", 2);
locks.unlockAll(ls);
runWithThreads(1, () -> {
List<Lock> ls2 = locks.lockAll("1", 3);
locks.unlockAll(ls2);
});
List<Lock> ls3 = locks.lockAll("1", 2, 3);
locks.unlockAll(ls3);
Assert.assertThrows(IllegalArgumentException.class, () -> {
locks.lockAll("1", null);
}, e -> {
Assert.assertContains("Lock key can't be null", e.getMessage());
});
Assert.assertThrows(IllegalArgumentException.class, () -> {
locks.lockAll(null, "1");
}, e -> {
Assert.assertContains("Lock key can't be null", e.getMessage());
});
Assert.assertThrows(IllegalArgumentException.class, () -> {
locks.lockAll(Arrays.asList("1", null, 2).toArray());
}, e -> {
Assert.assertContains("Lock key can't be null", e.getMessage());
});
Assert.assertThrows(IllegalArgumentException.class, () -> {
locks.lockAll(Arrays.asList().toArray());
}, e -> {
Assert.assertContains("Lock keys can't be null or empty", e.getMessage());
});
Assert.assertThrows(IllegalArgumentException.class, () -> {
locks.lockAll((Object[]) null);
}, e -> {
Assert.assertContains("Lock keys can't be null or empty", e.getMessage());
});
Assert.assertThrows(IllegalArgumentException.class, () -> {
locks.unlockAll(null);
}, e -> {
Assert.assertContains("Unlock locks can't be null", e.getMessage());
});
}
use of com.baidu.hugegraph.concurrent.KeyLock in project hugegraph-common by hugegraph.
the class KeyLockTest method testLockUnlock.
@Test
public void testLockUnlock() {
KeyLock locks = new KeyLock();
locks.lock("1");
try {
// lock again is OK
locks.lock("1");
// lock in other threads
runWithThreads(1, () -> {
locks.lock("2");
});
locks.unlock("1");
} finally {
locks.unlock("1");
}
Assert.assertThrows(IllegalMonitorStateException.class, () -> {
locks.unlock("2");
});
Assert.assertThrows(IllegalMonitorStateException.class, () -> {
locks.unlock("3");
});
Assert.assertThrows(IllegalArgumentException.class, () -> {
locks.lock(null);
}, e -> {
Assert.assertContains("Lock key can't be null", e.getMessage());
});
Assert.assertThrows(IllegalArgumentException.class, () -> {
locks.unlock(null);
}, e -> {
Assert.assertContains("Unlock key can't be null", e.getMessage());
});
}
use of com.baidu.hugegraph.concurrent.KeyLock in project hugegraph-common by hugegraph.
the class LockGroupTest method testKeyLockWithSize.
@Test
public void testKeyLockWithSize() {
KeyLock lock = this.group.keyLock("lock", 10);
Assert.assertNotNull(lock);
KeyLock lock1 = this.group.keyLock("lock");
Assert.assertSame(lock, lock1);
}
use of com.baidu.hugegraph.concurrent.KeyLock in project hugegraph-common by hugegraph.
the class LockGroupTest method testKeyLock.
@Test
public void testKeyLock() {
KeyLock lock = this.group.keyLock("lock");
Assert.assertNotNull(lock);
KeyLock lock1 = this.group.keyLock("lock");
Assert.assertSame(lock, lock1);
}
Aggregations