Search in sources :

Example 1 with ZooReaderWriter

use of org.apache.accumulo.fate.zookeeper.ZooReaderWriter in project accumulo by apache.

the class ZooLockTest method testDeleteParent.

@Test(timeout = 10000)
public void testDeleteParent() throws Exception {
    String parent = "/zltest-" + this.hashCode() + "-l" + pdCount.incrementAndGet();
    ZooLock zl = new ZooLock(accumulo.getZooKeepers(), 30000, "digest", "secret".getBytes(), parent);
    Assert.assertFalse(zl.isLocked());
    ZooReaderWriter zk = ZooReaderWriter.getInstance(accumulo.getZooKeepers(), 30000, "digest", "secret".getBytes());
    // intentionally created parent after lock
    zk.mkdirs(parent);
    zk.delete(parent, -1);
    zk.mkdirs(parent);
    TestALW lw = new TestALW();
    zl.lockAsync(lw, "test1".getBytes());
    lw.waitForChanges(1);
    Assert.assertTrue(lw.locked);
    Assert.assertTrue(zl.isLocked());
    Assert.assertNull(lw.exception);
    Assert.assertNull(lw.reason);
    zl.unlock();
}
Also used : ZooReaderWriter(org.apache.accumulo.fate.zookeeper.ZooReaderWriter) ZooLock(org.apache.accumulo.fate.zookeeper.ZooLock) Test(org.junit.Test)

Example 2 with ZooReaderWriter

use of org.apache.accumulo.fate.zookeeper.ZooReaderWriter in project accumulo by apache.

the class FateCommand method getZooReaderWriter.

protected synchronized IZooReaderWriter getZooReaderWriter(Instance instance, String secret) {
    if (secret == null) {
        AccumuloConfiguration conf = SiteConfiguration.getInstance();
        secret = conf.get(Property.INSTANCE_SECRET);
    }
    return new ZooReaderWriter(instance.getZooKeepers(), instance.getZooKeepersSessionTimeOut(), SCHEME, (USER + ":" + secret).getBytes());
}
Also used : ZooReaderWriter(org.apache.accumulo.fate.zookeeper.ZooReaderWriter) IZooReaderWriter(org.apache.accumulo.fate.zookeeper.IZooReaderWriter) AccumuloConfiguration(org.apache.accumulo.core.conf.AccumuloConfiguration)

Example 3 with ZooReaderWriter

use of org.apache.accumulo.fate.zookeeper.ZooReaderWriter in project accumulo by apache.

the class ZooLockTest method testDeleteLock.

@Test(timeout = 10000)
public void testDeleteLock() throws Exception {
    String parent = "/zltest-" + this.hashCode() + "-l" + pdCount.incrementAndGet();
    ZooReaderWriter zk = ZooReaderWriter.getInstance(accumulo.getZooKeepers(), 30000, "digest", "secret".getBytes());
    zk.mkdirs(parent);
    ZooLock zl = new ZooLock(accumulo.getZooKeepers(), 30000, "digest", "secret".getBytes(), parent);
    Assert.assertFalse(zl.isLocked());
    TestALW lw = new TestALW();
    zl.lockAsync(lw, "test1".getBytes());
    lw.waitForChanges(1);
    Assert.assertTrue(lw.locked);
    Assert.assertTrue(zl.isLocked());
    Assert.assertNull(lw.exception);
    Assert.assertNull(lw.reason);
    zk.delete(zl.getLockPath(), -1);
    lw.waitForChanges(2);
    Assert.assertEquals(LockLossReason.LOCK_DELETED, lw.reason);
    Assert.assertNull(lw.exception);
}
Also used : ZooReaderWriter(org.apache.accumulo.fate.zookeeper.ZooReaderWriter) ZooLock(org.apache.accumulo.fate.zookeeper.ZooLock) Test(org.junit.Test)

Example 4 with ZooReaderWriter

use of org.apache.accumulo.fate.zookeeper.ZooReaderWriter in project accumulo by apache.

the class ZooLockTest method testDeleteWaiting.

@Test(timeout = 10000)
public void testDeleteWaiting() throws Exception {
    String parent = "/zltest-" + this.hashCode() + "-l" + pdCount.incrementAndGet();
    ZooReaderWriter zk = ZooReaderWriter.getInstance(accumulo.getZooKeepers(), 30000, "digest", "secret".getBytes());
    zk.mkdirs(parent);
    ZooLock zl = new ZooLock(accumulo.getZooKeepers(), 30000, "digest", "secret".getBytes(), parent);
    Assert.assertFalse(zl.isLocked());
    TestALW lw = new TestALW();
    zl.lockAsync(lw, "test1".getBytes());
    lw.waitForChanges(1);
    Assert.assertTrue(lw.locked);
    Assert.assertTrue(zl.isLocked());
    Assert.assertNull(lw.exception);
    Assert.assertNull(lw.reason);
    ZooLock zl2 = new ZooLock(accumulo.getZooKeepers(), 30000, "digest", "secret".getBytes(), parent);
    TestALW lw2 = new TestALW();
    zl2.lockAsync(lw2, "test2".getBytes());
    Assert.assertFalse(lw2.locked);
    Assert.assertFalse(zl2.isLocked());
    ZooLock zl3 = new ZooLock(accumulo.getZooKeepers(), 30000, "digest", "secret".getBytes(), parent);
    TestALW lw3 = new TestALW();
    zl3.lockAsync(lw3, "test3".getBytes());
    List<String> children = zk.getChildren(parent);
    Collections.sort(children);
    zk.delete(parent + "/" + children.get(1), -1);
    lw2.waitForChanges(1);
    Assert.assertFalse(lw2.locked);
    Assert.assertNotNull(lw2.exception);
    Assert.assertNull(lw2.reason);
    zk.delete(parent + "/" + children.get(0), -1);
    lw.waitForChanges(2);
    Assert.assertEquals(LockLossReason.LOCK_DELETED, lw.reason);
    Assert.assertNull(lw.exception);
    lw3.waitForChanges(1);
    Assert.assertTrue(lw3.locked);
    Assert.assertTrue(zl3.isLocked());
    Assert.assertNull(lw3.exception);
    Assert.assertNull(lw3.reason);
    zl3.unlock();
}
Also used : ZooReaderWriter(org.apache.accumulo.fate.zookeeper.ZooReaderWriter) ZooLock(org.apache.accumulo.fate.zookeeper.ZooLock) Test(org.junit.Test)

Aggregations

ZooReaderWriter (org.apache.accumulo.fate.zookeeper.ZooReaderWriter)4 ZooLock (org.apache.accumulo.fate.zookeeper.ZooLock)3 Test (org.junit.Test)3 AccumuloConfiguration (org.apache.accumulo.core.conf.AccumuloConfiguration)1 IZooReaderWriter (org.apache.accumulo.fate.zookeeper.IZooReaderWriter)1