Package org.kiji.schema.layout.impl

Examples of org.kiji.schema.layout.impl.ZooKeeperClient


  @Test
  public void testZooKeeperLockIsExclusiveWithZKMZooKeeperLock() throws Exception {
    final File path = new File("/lock/is/exclusive/zkm");
    CuratorFramework zkClient1 = ZooKeeperUtils.getZooKeeperClient(getZKAddress());
    try {
      ZooKeeperClient zkClient2 = ZooKeeperClient.getZooKeeperClient(getZKAddress());
      try {
        ZooKeeperLock lock1 = new ZooKeeperLock(zkClient1, path);
        try {
          org.kiji.schema.util.ZooKeeperLock lock2 =
              new org.kiji.schema.util.ZooKeeperLock(zkClient2, path);
          try {
            Assert.assertTrue(lock1.lock(1.0));
            Assert.assertFalse(lock2.lock(1.0));
            lock1.unlock();

            Assert.assertTrue(lock2.lock(1.0));
            Assert.assertFalse(lock1.lock(1.0));
            lock2.unlock();
          } finally {
            lock2.close();
          }
        } finally {
          lock1.close();
        }
      } finally {
        zkClient2.release();
      }
    } finally {
      zkClient1.close();
    }
  }
View Full Code Here


  /** Overly basic test for ZooKeeper locks. */
  @Test
  public void testZooKeeperLock() throws Exception {
    final File lockDir = new File("/lock");
    final ZooKeeperClient zkClient = ZooKeeperClient.getZooKeeperClient(getZKAddress());
    try {
      final CyclicBarrier barrier = new CyclicBarrier(2);
      final ZooKeeperLock lock1 = new ZooKeeperLock(zkClient, lockDir);
      final ZooKeeperLock lock2 = new ZooKeeperLock(zkClient, lockDir);
      lock1.lock();

      final Thread thread = new Thread() {
        /** {@inheritDoc} */
        @Override
        public void run() {
          try {
            assertFalse(lock2.lock(0.1));
            barrier.await();
            lock2.lock();
            lock2.unlock();

            lock2.lock();
            lock2.unlock();
            lock2.close();
            barrier.await();
          } catch (Exception e) {
            LOG.warn("Exception caught in locking thread: {}", e.getMessage());
          }
        }
      };
      thread.start();

      barrier.await(5, TimeUnit.SECONDS); // Eventually fail

      lock1.unlock();
      lock1.close();

      barrier.await(5, TimeUnit.SECONDS); // Eventually fail
    } finally {
      zkClient.release();
    }
  }
View Full Code Here

TOP

Related Classes of org.kiji.schema.layout.impl.ZooKeeperClient

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.