@Test void deleteNonExistingML() throws Exception { MetaStore store = new MetaStoreImplZookeeper(zkc, executor); AtomicReference<MetaStoreException> exception = new AtomicReference<>(); CountDownLatch counter = new CountDownLatch(1); store.removeManagedLedger("non-existing", new MetaStoreCallback<Void>() { @Override public void operationComplete(Void result, Stat version) { counter.countDown(); } @Override public void operationFailed(MetaStoreException e) { exception.set(e); counter.countDown(); } }); counter.await(); assertNotNull(exception.get()); }
@Test void getMLList() throws Exception { MetaStore store = new MetaStoreImplZookeeper(zkc, executor); zkc.failNow(Code.CONNECTIONLOSS); try { store.getManagedLedgers(); fail("should fail in getting the list"); } catch (MetaStoreException e) { // ok } }
@Test(timeOut = 20000) void failInCreatingMLnode() throws Exception { MetaStore store = new MetaStoreImplZookeeper(zkc, executor); final CountDownLatch latch = new CountDownLatch(1); zkc.failAfter(1, Code.CONNECTIONLOSS); store.getManagedLedgerInfo("my_test", false, new MetaStoreCallback<MLDataFormats.ManagedLedgerInfo>() { public void operationFailed(MetaStoreException e) { // Ok latch.countDown(); } public void operationComplete(ManagedLedgerInfo result, Stat version) { fail("Operation should have failed"); } }); latch.await(); }
@Test(timeOut = 20000) void readMalformedML() throws Exception { MetaStore store = new MetaStoreImplZookeeper(zkc, executor); zkc.create("/managed-ledgers/my_test", "non-valid".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); final CountDownLatch latch = new CountDownLatch(1); store.getManagedLedgerInfo("my_test", false, new MetaStoreCallback<MLDataFormats.ManagedLedgerInfo>() { public void operationFailed(MetaStoreException e) { // Ok latch.countDown(); } public void operationComplete(ManagedLedgerInfo result, Stat version) { fail("Operation should have failed"); } }); latch.await(); }
@Test(timeOut = 20000) void updatingMLNode() throws Exception { final MetaStore store = new MetaStoreImplZookeeper(zkc, executor); zkc.create("/managed-ledgers/my_test", "".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); final CountDownLatch latch = new CountDownLatch(1); store.getManagedLedgerInfo("my_test", false, new MetaStoreCallback<ManagedLedgerInfo>() { public void operationFailed(MetaStoreException e) { fail("should have succeeded"); } public void operationComplete(ManagedLedgerInfo mlInfo, Stat version) { // Update again using the version zkc.failNow(Code.BADVERSION); store.asyncUpdateLedgerIds("my_test", mlInfo, version, new MetaStoreCallback<Void>() { public void operationFailed(MetaStoreException e) { // ok latch.countDown(); } @Override public void operationComplete(Void result, Stat version) { fail("should have failed"); } }); } }); latch.await(); }
@Test(timeOut = 20000) void readMalformedCursorNode() throws Exception { MetaStore store = new MetaStoreImplZookeeper(zkc, executor); zkc.create("/managed-ledgers/my_test", "".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); zkc.create("/managed-ledgers/my_test/c1", "non-valid".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); final CountDownLatch latch = new CountDownLatch(1); store.asyncGetCursorInfo("my_test", "c1", new MetaStoreCallback<MLDataFormats.ManagedCursorInfo>() { public void operationFailed(MetaStoreException e) { // Ok latch.countDown(); } public void operationComplete(ManagedCursorInfo result, Stat version) { fail("Operation should have failed"); } }); latch.await(); }
@Test(timeOut = 20000) void updatingCursorNode() throws Exception { final MetaStore store = new MetaStoreImplZookeeper(zkc, executor); zkc.create("/managed-ledgers/my_test", "".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); final CountDownLatch latch = new CountDownLatch(1); ManagedCursorInfo info = ManagedCursorInfo.newBuilder().setCursorsLedgerId(1).build(); store.asyncUpdateCursorInfo("my_test", "c1", info, null, new MetaStoreCallback<Void>() { public void operationFailed(MetaStoreException e) { fail("should have succeeded"); } public void operationComplete(Void result, Stat version) { // Update again using the version zkc.failNow(Code.CONNECTIONLOSS); ManagedCursorInfo info = ManagedCursorInfo.newBuilder().setCursorsLedgerId(2).build(); store.asyncUpdateCursorInfo("my_test", "c1", info, version, new MetaStoreCallback<Void>() { public void operationFailed(MetaStoreException e) { // ok latch.countDown(); } @Override public void operationComplete(Void result, Stat version) { fail("should have failed"); } }); } }); latch.await(); }
private ManagedLedgerFactoryImpl(BookKeeper bookKeeper, boolean isBookkeeperManaged, ZooKeeper zooKeeper, ManagedLedgerFactoryConfig config) throws Exception { scheduledExecutor = OrderedScheduler.newSchedulerBuilder() .numThreads(config.getNumManagedLedgerSchedulerThreads()) .name("bookkeeper-ml-scheduler") .build(); orderedExecutor = OrderedExecutor.newBuilder() .numThreads(config.getNumManagedLedgerWorkerThreads()) .name("bookkeeper-ml-workers") .build(); this.bookKeeper = bookKeeper; this.isBookkeeperManaged = isBookkeeperManaged; this.zookeeper = isBookkeeperManaged ? zooKeeper : null; this.store = new MetaStoreImplZookeeper(zooKeeper, orderedExecutor); this.config = config; this.mbean = new ManagedLedgerFactoryMBeanImpl(this); this.entryCacheManager = new EntryCacheManager(this); this.statsTask = scheduledExecutor.scheduleAtFixedRate(() -> refreshStats(), 0, StatsPeriodSeconds, TimeUnit.SECONDS); }
ml.close(); MetaStore store = new MetaStoreImplZookeeper(zkc, executor); CountDownLatch l1 = new CountDownLatch(1);
public ManagedLedgerFactoryImpl(BookKeeper bookKeeper, ZooKeeper zooKeeper, ManagedLedgerFactoryConfig config) throws Exception { this.bookKeeper = bookKeeper; this.isBookkeeperManaged = false; this.zookeeper = null; this.store = new MetaStoreImplZookeeper(zooKeeper, orderedExecutor); this.config = config; this.mbean = new ManagedLedgerFactoryMBeanImpl(this); this.entryCacheManager = new EntryCacheManager(this); this.statsTask = executor.scheduleAtFixedRate(() -> refreshStats(), 0, StatsPeriodSeconds, TimeUnit.SECONDS); }
public ManagedLedgerFactoryImpl(ClientConfiguration bkClientConfiguration, ManagedLedgerFactoryConfig config) throws Exception { final CountDownLatch counter = new CountDownLatch(1); final String zookeeperQuorum = checkNotNull(bkClientConfiguration.getZkServers()); zookeeper = new ZooKeeper(zookeeperQuorum, bkClientConfiguration.getZkTimeout(), event -> { if (event.getState().equals(Watcher.Event.KeeperState.SyncConnected)) { log.info("Connected to zookeeper"); counter.countDown(); } else { log.error("Error connecting to zookeeper {}", event); } }); if (!counter.await(bkClientConfiguration.getZkTimeout(), TimeUnit.MILLISECONDS) || zookeeper.getState() != States.CONNECTED) { throw new ManagedLedgerException("Error connecting to ZooKeeper at '" + zookeeperQuorum + "'"); } this.bookKeeper = new BookKeeper(bkClientConfiguration, zookeeper); this.isBookkeeperManaged = true; this.store = new MetaStoreImplZookeeper(zookeeper, orderedExecutor); this.config = config; this.mbean = new ManagedLedgerFactoryMBeanImpl(this); this.entryCacheManager = new EntryCacheManager(this); this.statsTask = executor.scheduleAtFixedRate(() -> refreshStats(), 0, StatsPeriodSeconds, TimeUnit.SECONDS); }
private ManagedLedgerFactoryImpl(BookKeeper bookKeeper, boolean isBookkeeperManaged, ZooKeeper zooKeeper, ManagedLedgerFactoryConfig config) throws Exception { scheduledExecutor = OrderedScheduler.newSchedulerBuilder() .numThreads(config.getNumManagedLedgerSchedulerThreads()) .name("bookkeeper-ml-scheduler") .build(); orderedExecutor = OrderedExecutor.newBuilder() .numThreads(config.getNumManagedLedgerWorkerThreads()) .name("bookkeeper-ml-workers") .build(); this.bookKeeper = bookKeeper; this.isBookkeeperManaged = isBookkeeperManaged; this.zookeeper = isBookkeeperManaged ? zooKeeper : null; this.store = new MetaStoreImplZookeeper(zooKeeper, orderedExecutor); this.config = config; this.mbean = new ManagedLedgerFactoryMBeanImpl(this); this.entryCacheManager = new EntryCacheManager(this); this.statsTask = scheduledExecutor.scheduleAtFixedRate(() -> refreshStats(), 0, StatsPeriodSeconds, TimeUnit.SECONDS); }