public boolean contains(int watcherBit) { if (watcherBits == null) { return false; } return watcherBits.contains(watcherBit); }
public File validate(File file) { if(warnForRelativePath) doWarnForRelativePath(file); if(failForNonExistingPath) doFailForNonExistingPath(file); return file; }
/** * Returns the current epoch of the leader. * * @return */ public long getEpoch(){ return ZxidUtils.getEpochFromZxid(lastProposed); }
@Test public void testForWarningOnRelativePath() { VerifyingFileFactory vff = new VerifyingFileFactory.Builder(log) .warnForRelativePath().build(); vff.create("a/relative/path"); // assertTrue(log.hasWarned); }
@Test(expected=IllegalArgumentException.class) public void testForFailForNonExistingPath() { VerifyingFileFactory vff = new VerifyingFileFactory.Builder(log) .failForNonExistingPath().build(); vff.create("/I/H0p3/this/path/d035/n0t/ex15t"); }
@Test public void testFileHasCorrectPath() { File file = new File("/some/path"); VerifyingFileFactory vff = new VerifyingFileFactory.Builder(log).build(); assertEquals(file, vff.create(file.getPath())); } }
/** * Used in the OpCode.checkWatches, which is a read operation, since read * and write requests are exclusively processed, we don't need to hold * lock here. * * Different from addWatch this method doesn't mutate any state, so we don't * need to hold read lock to avoid dead watcher (cnxn closed) being added * to the watcher manager. * * It's possible that before we lazily clean up the dead watcher, this will * return true, but since the cnxn is closed, the response will dropped as * well, so it doesn't matter. */ @Override public boolean containsWatcher(String path, Watcher watcher) { BitHashSet watchers = pathWatches.get(path); if (watchers == null || !watchers.contains(watcherBitIdMap.getBit(watcher))) { return false; } return true; }
/** * deserialize a snapshot from an input archive * @param ia the input archive you want to deserialize from * @throws IOException */ public void deserializeSnapshot(InputArchive ia) throws IOException { clear(); SerializeUtils.deserializeSnapshot(getDataTree(),ia,getSessionWithTimeOuts()); initialized = true; }
long getZxid(long epoch, long counter){ return ZxidUtils.makeZxid(epoch, counter); }
/** * serialize the snapshot * @param oa the output archive to which the snapshot needs to be serialized * @throws IOException * @throws InterruptedException */ public void serializeSnapshot(OutputArchive oa) throws IOException, InterruptedException { SerializeUtils.serializeSnapshot(getDataTree(), oa, getSessionWithTimeOuts()); }
public void shutdown() throws Exception { this.stopped = true; this.serverSocket.close(); this.join(); this.workerExecutor.shutdownNow(); for (PortForwardWorker worker: workers) { worker.shutdown(); } for (PortForwardWorker worker: workers) { if (!worker.waitForShutdown(5000)) { throw new Exception("Failed to stop forwarding within 5 seconds"); } } } }
public int size() { if (watchers != null) { return watchers.size(); } if (watcherBits != null) { return watcherBits.size(); } return 0; } }
@Test(expected = ConfigException.class) public void testGetHostAndPortWithoutBracket() throws ConfigException { String[] nsa = ConfigUtils.getHostAndPort("[2001:db8:85a3:8d3:1319:8a2e:370:7348"); }
public VerifyingFileFactory build() { return new VerifyingFileFactory(this); } }
public File create(String path) { File file = new File(path); return validate(file); }
public PortForwarder(int from, int to) throws IOException { this.to = to; serverSocket = new ServerSocket(from); serverSocket.setSoTimeout(30000); this.start(); }
@Test public void testForNoWarningOnIntendedRelativePath() { VerifyingFileFactory vff = new VerifyingFileFactory.Builder(log) .warnForRelativePath().build(); vff.create("./an/intended/relative/path"); // assertFalse(log.hasWarned); }
/** * Returns the current epoch of the leader. * * @return */ public long getEpoch(){ return ZxidUtils.getEpochFromZxid(lastProposed); }
@Override public int size() { int size = 0; for(BitHashSet watches : pathWatches.values()) { size += watches.size(); } return size; }
@Test(expected = ConfigException.class) public void testGetHostAndPortWithoutPortAfterColon() throws ConfigException { String[] nsa = ConfigUtils.getHostAndPort("[2001:db8:1::242:ac11:2]:"); }