/** * Creates a new instance of the BookKeeper log class. * * @param containerId The Id of the Container whose BookKeeperLog to open. * @param zkClient A reference to the CuratorFramework client to use. * @param bookKeeper A reference to the BookKeeper client to use. * @param config Configuration to use. * @param executorService An Executor to use for async operations. */ BookKeeperLog(int containerId, CuratorFramework zkClient, BookKeeper bookKeeper, BookKeeperConfig config, ScheduledExecutorService executorService) { Preconditions.checkArgument(containerId >= 0, "containerId must be a non-negative integer."); this.zkClient = Preconditions.checkNotNull(zkClient, "zkClient"); this.bookKeeper = Preconditions.checkNotNull(bookKeeper, "bookKeeper"); this.config = Preconditions.checkNotNull(config, "config"); this.executorService = Preconditions.checkNotNull(executorService, "executorService"); this.closed = new AtomicBoolean(); this.logNodePath = HierarchyUtils.getPath(containerId, this.config.getZkHierarchyDepth()); this.traceObjectId = String.format("Log[%d]", containerId); this.writes = new WriteQueue(); val retry = createRetryPolicy(this.config.getMaxWriteAttempts(), this.config.getBkWriteTimeoutMillis()); this.writeProcessor = new SequentialAsyncProcessor(this::processWritesSync, retry, this::handleWriteProcessorFailures, this.executorService); this.rolloverProcessor = new SequentialAsyncProcessor(this::rollover, retry, this::handleRolloverFailure, this.executorService); this.metrics = new BookKeeperMetrics.BookKeeperLog(containerId); this.metricReporter = this.executorService.scheduleWithFixedDelay(this::reportMetrics, REPORT_INTERVAL, REPORT_INTERVAL, TimeUnit.MILLISECONDS); }
/** * Tests the GetPath method. */ @Test(timeout = 5000) public void testGetPath() { // Flat hierarchy. Assert.assertEquals("/1234", HierarchyUtils.getPath(1234, 0)); Assert.assertEquals("/0", HierarchyUtils.getPath(0, 0)); // Sub-length hierarchy. Assert.assertEquals("/4/1234", HierarchyUtils.getPath(1234, 1)); Assert.assertEquals("/4/3/1234", HierarchyUtils.getPath(1234, 2)); Assert.assertEquals("/4/3/2/1234", HierarchyUtils.getPath(1234, 3)); Assert.assertEquals("/4/3/2/1/1234", HierarchyUtils.getPath(1234, 4)); // Above-length hierarchy. Assert.assertEquals("/4/3/2/1/0/1234", HierarchyUtils.getPath(1234, 5)); Assert.assertEquals("/4/3/2/1/0/0/1234", HierarchyUtils.getPath(1234, 6)); } }