Java Code Examples for org.redisson.api.RSemaphore#release()

The following examples show how to use org.redisson.api.RSemaphore#release() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RedissonLockHeavyTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void lockUnlockRLock() throws Exception {
    for (int i = 0; i < threads; i++) {

        Runnable worker = new Runnable() {

            @Override
            public void run() {
                for (int j = 0; j < loops; j++) {
                    RLock lock = redisson.getLock("RLOCK_" + j);
                    lock.lock();
                    try {
                        RBucket<String> bucket = redisson.getBucket("RBUCKET_" + j);
                        bucket.set("TEST", 30, TimeUnit.SECONDS);
                        RSemaphore semaphore = redisson.getSemaphore("SEMAPHORE_" + j);
                        semaphore.release();
                        try {
                            semaphore.acquire();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    } finally {
                        lock.unlock();
                    }
                }
            }
        };
        executor.execute(worker);
    }
    executor.shutdown();
    executor.awaitTermination(threads * loops, TimeUnit.SECONDS);

}
 
Example 2
Source File: RedissonSemaphoreTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testZero() throws InterruptedException {
    RSemaphore s = redisson.getSemaphore("test");
    assertThat(s.tryAcquire(0, 10, TimeUnit.MINUTES)).isTrue();
    s.release(0);
    assertThat(s.availablePermits()).isZero();
}
 
Example 3
Source File: RedissonSemaphoreTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testAcquireWithoutSetPermits() throws InterruptedException {
    RSemaphore s = redisson.getSemaphore("test");
    s.release();
    s.release();
    s.acquire(2);
}
 
Example 4
Source File: RedissonSemaphoreTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testReducePermits() throws InterruptedException {
    RSemaphore s = redisson.getSemaphore("test");
    s.trySetPermits(10);
    
    s.acquire(10);
    s.reducePermits(5);
    assertThat(s.availablePermits()).isEqualTo(-5);
    s.release(10);
    assertThat(s.availablePermits()).isEqualTo(5);
    s.acquire(5);
    assertThat(s.availablePermits()).isEqualTo(0);
}
 
Example 5
Source File: RedissonSemaphoreTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testReleaseWithoutPermits() {
    RSemaphore s = redisson.getSemaphore("test");
    s.release();

    assertThat(s.availablePermits()).isEqualTo(1);
}
 
Example 6
Source File: RedissonSemaphoreTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testReleaseAcquire() throws InterruptedException {
    RSemaphore s = redisson.getSemaphore("test");
    s.trySetPermits(10);
    s.acquire();
    assertThat(s.availablePermits()).isEqualTo(9);
    s.release();
    assertThat(s.availablePermits()).isEqualTo(10);
    s.acquire(5);
    assertThat(s.availablePermits()).isEqualTo(5);
    s.release(5);
    assertThat(s.availablePermits()).isEqualTo(10);
}
 
Example 7
Source File: RedisPeakLimiter.java    From Limiter with Apache License 2.0 4 votes vote down vote up
@Override
public void release(Object key, int max) {
    RSemaphore rSemaphore = redisson.getSemaphore(key.toString());
    rSemaphore.release();
}