ZKLogMetadataForWriter extends ZKLogMetadata { static Future<List<Versioned<byte[]>>> checkLogMetadataPaths(ZooKeeper zk, String logRootPath, boolean ownAllocator) { final String logRootParentPath = new File(logRootPath).getParent(); final String logSegmentsPath = logRootPath + LOGSEGMENTS_PATH; final String maxTxIdPath = logRootPath + MAX_TXID_PATH; final String lockPath = logRootPath + LOCK_PATH; final String readLockPath = logRootPath + READ_LOCK_PATH; final String versionPath = logRootPath + VERSION_PATH; final String allocationPath = logRootPath + ALLOCATION_PATH; int numPaths = ownAllocator ? MetadataIndex.ALLOCATION + 1 : MetadataIndex.LOGSEGMENTS + 1; List<Future<Versioned<byte[]>>> checkFutures = Lists.newArrayListWithExpectedSize(numPaths); checkFutures.add(Utils.zkGetData(zk, logRootParentPath, false)); checkFutures.add(Utils.zkGetData(zk, logRootPath, false)); checkFutures.add(Utils.zkGetData(zk, maxTxIdPath, false)); checkFutures.add(Utils.zkGetData(zk, versionPath, false)); checkFutures.add(Utils.zkGetData(zk, lockPath, false)); checkFutures.add(Utils.zkGetData(zk, readLockPath, false)); checkFutures.add(Utils.zkGetData(zk, logSegmentsPath, false)); if (ownAllocator) { checkFutures.add(Utils.zkGetData(zk, allocationPath, false)); } return Future.collect(checkFutures); } private  ZKLogMetadataForWriter(URI uri,
                                   String logName,
                                   String logIdentifier,
                                   Versioned<byte[]> maxLSSNData,
                                   Versioned<byte[]> maxTxIdData,
                                   Versioned<byte[]> allocationData); static Future<ZKLogMetadataForWriter> of(
            final URI uri,
            final String logName,
            final String logIdentifier,
            final ZooKeeper zk,
            final List<ACL> acl,
            final boolean ownAllocator,
            final boolean createIfNotExists); Versioned<byte[]> getMaxLSSNData(); Versioned<byte[]> getMaxTxIdData(); Versioned<byte[]> getAllocationData();  }
@Test(timeout = 60000) public void testCheckLogMetadataPathsWithAllocator() throws Exception { String logRootPath = "/" + testName.getMethodName(); List<Versioned<byte[]>> metadatas = FutureUtils.result(ZKLogMetadataForWriter.checkLogMetadataPaths( zkc.get(), logRootPath, true)); assertEquals("Should have 8 paths", 8, metadatas.size()); for (Versioned<byte[]> path : metadatas.subList(2, metadatas.size())) { assertNull(path.getValue()); assertNull(path.getVersion()); } }
@Test(timeout = 60000) public void testCheckLogMetadataPathsWithoutAllocator() throws Exception { String logRootPath = "/" + testName.getMethodName(); List<Versioned<byte[]>> metadatas = FutureUtils.result(ZKLogMetadataForWriter.checkLogMetadataPaths( zkc.get(), logRootPath, false)); assertEquals("Should have 7 paths", 7, metadatas.size()); for (Versioned<byte[]> path : metadatas.subList(2, metadatas.size())) { assertNull(path.getValue()); assertNull(path.getVersion()); } }