@Test(timeout = 30000) public void testWriteLockExcludesWriters() throws Exception { final String testName = "testWriteLockExcludesWriters"; final ZKInterProcessReadWriteLock readWriteLock = getReadWriteLock(testName); List<Future<Void>> results = Lists.newArrayList(); for (int i = 0; i < NUM_THREADS; ++i) { final String threadDesc = testName + i; results.add(executor.submit(new Callable<Void>() { @Override public Void call() throws IOException { ZKInterProcessWriteLock writeLock = readWriteLock.writeLock(Bytes.toBytes(threadDesc)); try { writeLock.acquire(); try { assertTrue(isLockHeld.compareAndSet(false, true)); Thread.sleep(1000); assertTrue(isLockHeld.compareAndSet(true, false)); } finally { isLockHeld.set(false); writeLock.release(); } } catch (InterruptedException e) { LOG.warn(threadDesc + " interrupted", e); Thread.currentThread().interrupt(); throw new InterruptedIOException(); } return null; } })); } MultithreadedTestUtil.assertOnFutures(results); }
public ZKInterProcessWriteLock writeLock(byte[] metadata) { return new ZKInterProcessWriteLock(zkWatcher, znode, metadata, handler); }
ZKInterProcessReadWriteLock implements InterProcessReadWriteLock { public ZKInterProcessWriteLock writeLock(byte[] metadata) { return new ZKInterProcessWriteLock(zkWatcher, znode, metadata, handler); } }
ZKInterProcessReadWriteLock implements InterProcessReadWriteLock { public ZKInterProcessWriteLock writeLock(byte[] metadata) { return new ZKInterProcessWriteLock(zkWatcher, znode, metadata, handler); } ZKInterProcessReadWriteLock(ZooKeeperWatcher zkWatcher, String znode,
      MetadataHandler handler); }
ZKInterProcessReadWriteLock implements InterProcessReadWriteLock { public ZKInterProcessWriteLock writeLock(byte[] metadata) { return new ZKInterProcessWriteLock(zkWatcher, znode, metadata, handler); } ZKInterProcessReadWriteLock(ZooKeeperWatcher zkWatcher, String znode,
      MetadataHandler handler); ZKInterProcessReadLock readLock(byte[] metadata); ZKInterProcessWriteLock writeLock(byte[] metadata); }
ZKInterProcessReadWriteLock implements InterProcessReadWriteLock { public ZKInterProcessWriteLock writeLock(byte[] metadata) { return new ZKInterProcessWriteLock(zkWatcher, znode, metadata, handler); } ZKInterProcessReadWriteLock(ZooKeeperWatcher zkWatcher, String znode,
      MetadataHandler handler); ZKInterProcessReadLock readLock(byte[] metadata); ZKInterProcessWriteLock writeLock(byte[] metadata);  }