use of org.redisson.api.RCountDownLatch in project redisson by redisson.
the class RedissonTwoLockedThread method testCountDown.
@Test(timeout = 3000)
public void testCountDown() throws InterruptedException {
final String countDownName = getClass().getName() + ":countDown#1";
final CountDownLatch startSignal = new CountDownLatch(1);
final CountDownLatch testSignal = new CountDownLatch(1);
final CountDownLatch completeSignal = new CountDownLatch(2);
System.out.println("configure");
final long millis = System.currentTimeMillis();
new Thread() {
@Override
public void run() {
try {
startSignal.await();
RCountDownLatch countDownLatch = redisson.getCountDownLatch(countDownName);
System.out.println("1. getCountDownLatch " + countDownLatch.getName() + " - " + Thread.currentThread().getId());
countDownLatch.trySetCount(1);
System.out.println("1. trySetCount " + countDownLatch.getName() + " - " + Thread.currentThread().getId());
Thread.sleep(500);
testSignal.countDown();
Thread.sleep(500);
System.out.println("1. sleep " + countDownLatch.getName() + " - " + Thread.currentThread().getId());
countDownLatch.countDown();
System.out.println("1. countDown " + countDownLatch.getName() + " - " + Thread.currentThread().getId());
} catch (InterruptedException e) {
e.printStackTrace();
}
completeSignal.countDown();
}
}.start();
new Thread() {
@Override
public void run() {
try {
testSignal.await();
RCountDownLatch countDownLatch = redisson.getCountDownLatch(countDownName);
System.out.println("2. getCountDownLatch " + countDownLatch.getName() + " - " + Thread.currentThread().getId());
countDownLatch.await();
System.out.println("2. await " + countDownLatch.getName() + " - " + Thread.currentThread().getId());
long current = System.currentTimeMillis();
Assert.assertTrue("current=" + current + ", millis=" + millis, (current - millis) >= 1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
completeSignal.countDown();
}
}.start();
System.out.println("start");
startSignal.countDown();
completeSignal.await();
System.out.println("complete");
}
use of org.redisson.api.RCountDownLatch in project redisson by redisson.
the class RedissonCountDownLatchTest method testTrySetCount.
@Test
public void testTrySetCount() throws Exception {
RCountDownLatch latch = redisson.getCountDownLatch("latch");
assertThat(latch.trySetCount(1)).isTrue();
assertThat(latch.trySetCount(2)).isFalse();
}
use of org.redisson.api.RCountDownLatch in project redisson by redisson.
the class RedissonCountDownLatchTest method testCountDown.
@Test
public void testCountDown() throws InterruptedException {
RCountDownLatch latch = redisson.getCountDownLatch("latch");
latch.trySetCount(2);
Assertions.assertEquals(2, latch.getCount());
latch.countDown();
Assertions.assertEquals(1, latch.getCount());
latch.countDown();
Assertions.assertEquals(0, latch.getCount());
latch.await();
latch.countDown();
Assertions.assertEquals(0, latch.getCount());
latch.await();
latch.countDown();
Assertions.assertEquals(0, latch.getCount());
latch.await();
RCountDownLatch latch1 = redisson.getCountDownLatch("latch1");
latch1.trySetCount(1);
latch1.countDown();
Assertions.assertEquals(0, latch.getCount());
latch1.countDown();
Assertions.assertEquals(0, latch.getCount());
latch1.await();
RCountDownLatch latch2 = redisson.getCountDownLatch("latch2");
latch2.trySetCount(1);
latch2.countDown();
latch2.await();
latch2.await();
RCountDownLatch latch3 = redisson.getCountDownLatch("latch3");
Assertions.assertEquals(0, latch.getCount());
latch3.await();
RCountDownLatch latch4 = redisson.getCountDownLatch("latch4");
Assertions.assertEquals(0, latch.getCount());
latch4.countDown();
Assertions.assertEquals(0, latch.getCount());
latch4.await();
}
use of org.redisson.api.RCountDownLatch in project redisson by redisson.
the class RedissonCountDownLatchTest method testDelete.
@Test
public void testDelete() throws Exception {
RCountDownLatch latch = redisson.getCountDownLatch("latch");
latch.trySetCount(1);
Assertions.assertTrue(latch.delete());
}
use of org.redisson.api.RCountDownLatch in project redisson by redisson.
the class RedissonCountDownLatchTest method testDeleteFailed.
@Test
public void testDeleteFailed() throws Exception {
RCountDownLatch latch = redisson.getCountDownLatch("latch");
Assertions.assertFalse(latch.delete());
}
Aggregations