Commit 2a559379 authored by hengwen's avatar hengwen
Browse files

Bugfix

parent a2d46a60
......@@ -99,8 +99,8 @@ public class Lock {
* @param path path of the lock. Example: /resource/locks/lock-00000001
* @return sequence string of the this lock
*/
private String getLockSequenceFromPath(String path) {
return path.split("-", 2)[1];
String getLockSequenceFromPath(String path) {
return path.substring(path.lastIndexOf("-")).split("-", 2)[1];
}
/**
......
......@@ -10,6 +10,14 @@ import static org.junit.Assert.*;
public class LockTest {
@Test
public void getLockSequenceFromPath() {
ZkClient zk = new ZkClient("localhost:2181");
Lock lock = new Lock("/resource", zk);
assertEquals("0001", lock.getLockSequenceFromPath("/ak-path-example/lock-0001"));
assertEquals("0001", lock.getLockSequenceFromPath("lock-0001"));
}
private class AcquireAndRelease implements Runnable{
private Lock lock;
private long releaseAfterMs;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment