diff options
author | Jon Marius Venstad <jvenstad@yahoo-inc.com> | 2019-02-22 16:29:53 +0100 |
---|---|---|
committer | Jon Marius Venstad <venstad@gmail.com> | 2019-02-26 10:29:59 +0100 |
commit | fd0283264184ceabbd6834bd0919f7923851bdfb (patch) | |
tree | 709a0a0d3f1e51dd9b6fbea1e5394d8b3c1429e4 /zkfacade | |
parent | d01ed036f6a654ee8bd371cdbf269f760b7c17e0 (diff) |
Replace CuratorLock with Lock
Diffstat (limited to 'zkfacade')
3 files changed, 1 insertions, 132 deletions
diff --git a/zkfacade/src/main/java/com/yahoo/vespa/curator/Curator.java b/zkfacade/src/main/java/com/yahoo/vespa/curator/Curator.java index 91140fcf713..bc47a02ea19 100644 --- a/zkfacade/src/main/java/com/yahoo/vespa/curator/Curator.java +++ b/zkfacade/src/main/java/com/yahoo/vespa/curator/Curator.java @@ -163,7 +163,7 @@ public class Curator implements AutoCloseable { return new DistributedAtomicLong(curatorFramework, path, new ExponentialBackoffRetry(BASE_SLEEP_TIME, MAX_RETRIES)); } - /** For internal use; prefer creating a {@link com.yahoo.vespa.curator.recipes.CuratorLock} */ + /** For internal use; prefer creating a {@link com.yahoo.vespa.curator.Lock} */ public InterProcessLock createMutex(String lockPath) { return new InterProcessMutex(curatorFramework, lockPath); } diff --git a/zkfacade/src/main/java/com/yahoo/vespa/curator/recipes/CuratorLock.java b/zkfacade/src/main/java/com/yahoo/vespa/curator/recipes/CuratorLock.java deleted file mode 100644 index 89460e7916d..00000000000 --- a/zkfacade/src/main/java/com/yahoo/vespa/curator/recipes/CuratorLock.java +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.vespa.curator.recipes; - -import com.yahoo.vespa.curator.Curator; -import org.apache.curator.framework.recipes.locks.InterProcessLock; - -import java.util.concurrent.TimeUnit; -import java.util.concurrent.locks.Condition; -import java.util.concurrent.locks.Lock; - -/** - * @author Ulf Lilleengen - * @since 5.1 - */ -public class CuratorLock implements Lock { - - private final InterProcessLock mutex; - - public CuratorLock(Curator curator, String lockPath) { - this.mutex = curator.createMutex(lockPath); - } - - public boolean hasLock() { - return mutex.isAcquiredInThisProcess(); - } - - @Override - public void lock() { - try { - mutex.acquire(); - } catch (Exception e) { - throw new CuratorLockException(e); - } - } - - @Override - public void lockInterruptibly() throws InterruptedException { - throw new UnsupportedOperationException(); - } - - @Override - public boolean tryLock() { - try { - return tryLock(0, TimeUnit.MILLISECONDS); - } catch (InterruptedException e) { - throw new CuratorLockException(e); - } - } - - @Override - public boolean tryLock(long time, TimeUnit unit) throws InterruptedException { - try { - return mutex.acquire(time, unit); - } catch (InterruptedException e) { - throw e; - } catch (Exception e) { - throw new CuratorLockException(e); - } - } - - @Override - public void unlock() { - try { - mutex.release(); - } catch (Exception e) { - throw new CuratorLockException(e); - } - } - - @Override - public Condition newCondition() { - throw new UnsupportedOperationException(); - } - - - @Override - public String toString() { - return mutex.toString(); - } -} diff --git a/zkfacade/src/test/java/com/yahoo/vespa/curator/CuratorLockTest.java b/zkfacade/src/test/java/com/yahoo/vespa/curator/CuratorLockTest.java deleted file mode 100644 index 53d2df2441b..00000000000 --- a/zkfacade/src/test/java/com/yahoo/vespa/curator/CuratorLockTest.java +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.vespa.curator; - -import com.yahoo.vespa.curator.mock.MockCurator; -import com.yahoo.vespa.curator.recipes.CuratorLock; -import com.yahoo.vespa.curator.recipes.CuratorLockException; -import org.junit.Before; -import org.junit.Test; - -import java.util.concurrent.TimeUnit; - -import static org.junit.Assert.assertFalse; - -/** - * @author Ulf Lilleengen - * @since 5.1 - */ -public class CuratorLockTest { - - private MockCurator curator; - private CuratorLock curatorLock; - - @Before - public void setupLock() { - curator = new MockCurator(); - curatorLock = new CuratorLock(curator, "/foo"); - } - - @Test - public void testAcquireNormal() { - curator.timeoutOnLock = false; - curator.throwExceptionOnLock = false; - curatorLock.lock(); - curatorLock.unlock(); - } - - @Test - public void testLockTimeout() throws InterruptedException { - curator.timeoutOnLock = true; - assertFalse(curatorLock.tryLock(0, TimeUnit.MILLISECONDS)); - curatorLock.unlock(); - } - - @Test(expected = CuratorLockException.class) - public void testLockError() { - curator.throwExceptionOnLock = true; - curatorLock.lock(); - curatorLock.unlock(); - } - -} |