Search in sources :

Example 16 with LongVersion

use of org.apache.bookkeeper.versioning.LongVersion in project bookkeeper by apache.

the class TestZkRegistrationClient method testWatchBookiesSuccess.

@SuppressWarnings("unchecked")
private void testWatchBookiesSuccess(boolean isWritable) throws Exception {
    // 
    // 1. test watch bookies with a listener
    // 
    LinkedBlockingQueue<Versioned<Set<BookieSocketAddress>>> updates = spy(new LinkedBlockingQueue<>());
    RegistrationListener listener = bookies -> {
        try {
            updates.put(bookies);
        } catch (InterruptedException e) {
            log.warn("Interrupted on enqueue bookie updates", e);
        }
    };
    Set<BookieSocketAddress> addresses = prepareNBookies(10);
    List<String> children = Lists.newArrayList();
    for (BookieSocketAddress address : addresses) {
        children.add(address.toString());
    }
    Stat stat = mock(Stat.class);
    when(stat.getCversion()).thenReturn(1234);
    mockGetChildren(isWritable ? regPath : regReadonlyPath, true, Code.OK.intValue(), children, stat);
    if (isWritable) {
        result(zkRegistrationClient.watchWritableBookies(listener));
    } else {
        result(zkRegistrationClient.watchReadOnlyBookies(listener));
    }
    Versioned<Set<BookieSocketAddress>> update = updates.take();
    verify(updates, times(1)).put(any(Versioned.class));
    assertEquals(new LongVersion(1234), update.getVersion());
    assertSetEquals(addresses, update.getValue());
    verify(mockZk, times(1)).getChildren(anyString(), any(Watcher.class), any(Children2Callback.class), any());
    // 
    // 2. test watch bookies with a second listener. the second listener returns cached bookies
    // without calling `getChildren` again
    // 
    // register another listener
    LinkedBlockingQueue<Versioned<Set<BookieSocketAddress>>> secondUpdates = spy(new LinkedBlockingQueue<>());
    RegistrationListener secondListener = bookies -> {
        try {
            secondUpdates.put(bookies);
        } catch (InterruptedException e) {
            log.warn("Interrupted on enqueue bookie updates", e);
        }
    };
    if (isWritable) {
        result(zkRegistrationClient.watchWritableBookies(secondListener));
    } else {
        result(zkRegistrationClient.watchReadOnlyBookies(secondListener));
    }
    Versioned<Set<BookieSocketAddress>> secondListenerUpdate = secondUpdates.take();
    // first listener will not be notified with any update
    verify(updates, times(1)).put(any(Versioned.class));
    // second listener will receive same update as the first listener received before
    verify(secondUpdates, times(1)).put(any(Versioned.class));
    assertSame(update.getVersion(), secondListenerUpdate.getVersion());
    assertSame(update.getValue(), secondListenerUpdate.getValue());
    // the second listener will return the cached value without issuing another getChildren call
    verify(mockZk, times(1)).getChildren(anyString(), any(Watcher.class), any(Children2Callback.class), any());
    // 
    // 3. simulate session expire, it will trigger watcher to refetch bookies again.
    // but since there is no updates on bookies, the registered listeners will not be notified.
    // 
    notifyWatchedEvent(EventType.None, KeeperState.Expired, isWritable ? regPath : regReadonlyPath);
    // if session expires, the watcher task will get into backoff state
    controller.advance(Duration.ofMillis(ZK_CONNECT_BACKOFF_MS));
    // the same updates returns, the getChildren calls increase to 2
    // but since there is no updates, so no notification is sent.
    verify(mockZk, times(2)).getChildren(anyString(), any(Watcher.class), any(Children2Callback.class), any());
    assertNull(updates.poll());
    // both listener and secondListener will not receive any old update
    verify(updates, times(1)).put(any(Versioned.class));
    verify(secondUpdates, times(1)).put(any(Versioned.class));
    // 
    // 4. notify with new bookies. both listeners will be notified with new bookies.
    // 
    Set<BookieSocketAddress> newAddresses = prepareNBookies(20);
    List<String> newChildren = Lists.newArrayList();
    for (BookieSocketAddress address : newAddresses) {
        newChildren.add(address.toString());
    }
    Stat newStat = mock(Stat.class);
    when(newStat.getCversion()).thenReturn(1235);
    mockGetChildren(isWritable ? regPath : regReadonlyPath, true, Code.OK.intValue(), newChildren, newStat);
    // trigger watcher
    notifyWatchedEvent(EventType.NodeChildrenChanged, KeeperState.SyncConnected, isWritable ? regPath : regReadonlyPath);
    update = updates.take();
    assertEquals(new LongVersion(1235), update.getVersion());
    assertSetEquals(newAddresses, update.getValue());
    secondListenerUpdate = secondUpdates.take();
    assertSame(update.getVersion(), secondListenerUpdate.getVersion());
    assertSame(update.getValue(), secondListenerUpdate.getValue());
    verify(mockZk, times(3)).getChildren(anyString(), any(Watcher.class), any(Children2Callback.class), any());
    verify(updates, times(2)).put(any(Versioned.class));
    verify(secondUpdates, times(2)).put(any(Versioned.class));
    // 
    // 5. unwatch the second listener and notify with new bookies again. only first listener will
    // be notified with new bookies.
    // 
    newAddresses = prepareNBookies(25);
    newChildren.clear();
    newChildren = Lists.newArrayList();
    for (BookieSocketAddress address : newAddresses) {
        newChildren.add(address.toString());
    }
    newStat = mock(Stat.class);
    when(newStat.getCversion()).thenReturn(1236);
    mockGetChildren(isWritable ? regPath : regReadonlyPath, true, Code.OK.intValue(), newChildren, newStat);
    if (isWritable) {
        assertEquals(2, zkRegistrationClient.getWatchWritableBookiesTask().getNumListeners());
        zkRegistrationClient.unwatchWritableBookies(secondListener);
        assertEquals(1, zkRegistrationClient.getWatchWritableBookiesTask().getNumListeners());
    } else {
        assertEquals(2, zkRegistrationClient.getWatchReadOnlyBookiesTask().getNumListeners());
        zkRegistrationClient.unwatchReadOnlyBookies(secondListener);
        assertEquals(1, zkRegistrationClient.getWatchReadOnlyBookiesTask().getNumListeners());
    }
    // the watch task will not be closed since there is still a listener
    verify(mockZk, times(0)).removeWatches(eq(isWritable ? regPath : regReadonlyPath), same(isWritable ? zkRegistrationClient.getWatchWritableBookiesTask() : zkRegistrationClient.getWatchReadOnlyBookiesTask()), eq(WatcherType.Children), eq(true), any(VoidCallback.class), any());
    // trigger watcher
    notifyWatchedEvent(EventType.NodeChildrenChanged, KeeperState.SyncConnected, isWritable ? regPath : regReadonlyPath);
    update = updates.take();
    assertEquals(new LongVersion(1236), update.getVersion());
    assertSetEquals(newAddresses, update.getValue());
    secondListenerUpdate = secondUpdates.poll();
    assertNull(secondListenerUpdate);
    verify(mockZk, times(4)).getChildren(anyString(), any(Watcher.class), any(Children2Callback.class), any());
    verify(updates, times(3)).put(any(Versioned.class));
    verify(secondUpdates, times(2)).put(any(Versioned.class));
    // 
    // 6. unwatch the first listener. the watch task will be closed and zk watcher will be removed.
    // 
    // 
    WatchTask expectedWatcher;
    if (isWritable) {
        expectedWatcher = zkRegistrationClient.getWatchWritableBookiesTask();
        assertFalse(expectedWatcher.isClosed());
        zkRegistrationClient.unwatchWritableBookies(listener);
        assertNull(zkRegistrationClient.getWatchWritableBookiesTask());
    } else {
        expectedWatcher = zkRegistrationClient.getWatchReadOnlyBookiesTask();
        assertFalse(expectedWatcher.isClosed());
        zkRegistrationClient.unwatchReadOnlyBookies(listener);
        assertNull(zkRegistrationClient.getWatchReadOnlyBookiesTask());
    }
    // the watch task will not be closed since there is still a listener
    assertTrue(expectedWatcher.isClosed());
    verify(mockZk, times(1)).removeWatches(eq(isWritable ? regPath : regReadonlyPath), same(expectedWatcher), eq(WatcherType.Children), eq(true), any(VoidCallback.class), any());
}
Also used : WatchTask(org.apache.bookkeeper.discover.ZKRegistrationClient.WatchTask) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) ZKException(org.apache.bookkeeper.client.BKException.ZKException) VoidCallback(org.apache.zookeeper.AsyncCallback.VoidCallback) Stat(org.apache.zookeeper.data.Stat) RegistrationListener(org.apache.bookkeeper.discover.RegistrationClient.RegistrationListener) READONLY(org.apache.bookkeeper.util.BookKeeperConstants.READONLY) Duration(java.time.Duration) After(org.junit.After) KeeperState(org.apache.zookeeper.Watcher.Event.KeeperState) Assert.fail(org.junit.Assert.fail) Children2Callback(org.apache.zookeeper.AsyncCallback.Children2Callback) MockZooKeeperTestCase(org.apache.bookkeeper.zookeeper.MockZooKeeperTestCase) AVAILABLE_NODE(org.apache.bookkeeper.util.BookKeeperConstants.AVAILABLE_NODE) Set(java.util.Set) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) ZkUtils(org.apache.bookkeeper.util.ZkUtils) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) MockExecutorController(org.apache.bookkeeper.common.testing.executors.MockExecutorController) Assert.assertFalse(org.junit.Assert.assertFalse) MoreAsserts.assertSetEquals(org.apache.bookkeeper.common.testing.MoreAsserts.assertSetEquals) Mockito.mock(org.mockito.Mockito.mock) Code(org.apache.zookeeper.KeeperException.Code) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) LongVersion(org.apache.bookkeeper.versioning.LongVersion) RunWith(org.junit.runner.RunWith) CompletableFuture(java.util.concurrent.CompletableFuture) Mockito.spy(org.mockito.Mockito.spy) Assert.assertSame(org.junit.Assert.assertSame) HashSet(java.util.HashSet) Lists(com.google.common.collect.Lists) TestName(org.junit.rules.TestName) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) WatcherType(org.apache.zookeeper.Watcher.WatcherType) Versioned(org.apache.bookkeeper.versioning.Versioned) PowerMockRunner(org.powermock.modules.junit4.PowerMockRunner) Before(org.junit.Before) ZK_CONNECT_BACKOFF_MS(org.apache.bookkeeper.discover.ZKRegistrationClient.ZK_CONNECT_BACKOFF_MS) FutureUtils.collect(org.apache.bookkeeper.common.concurrent.FutureUtils.collect) Assert.assertNotNull(org.junit.Assert.assertNotNull) Watcher(org.apache.zookeeper.Watcher) Assert.assertTrue(org.junit.Assert.assertTrue) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) BookieSocketAddress(org.apache.bookkeeper.net.BookieSocketAddress) Assert.assertNull(org.junit.Assert.assertNull) Rule(org.junit.Rule) FutureUtils.result(org.apache.bookkeeper.common.concurrent.FutureUtils.result) EventType(org.apache.zookeeper.Watcher.Event.EventType) Assert.assertEquals(org.junit.Assert.assertEquals) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ArgumentMatchers.same(org.mockito.ArgumentMatchers.same) RegistrationListener(org.apache.bookkeeper.discover.RegistrationClient.RegistrationListener) Set(java.util.Set) HashSet(java.util.HashSet) WatchTask(org.apache.bookkeeper.discover.ZKRegistrationClient.WatchTask) Versioned(org.apache.bookkeeper.versioning.Versioned) Watcher(org.apache.zookeeper.Watcher) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) VoidCallback(org.apache.zookeeper.AsyncCallback.VoidCallback) Stat(org.apache.zookeeper.data.Stat) BookieSocketAddress(org.apache.bookkeeper.net.BookieSocketAddress) Children2Callback(org.apache.zookeeper.AsyncCallback.Children2Callback) LongVersion(org.apache.bookkeeper.versioning.LongVersion)

Example 17 with LongVersion

use of org.apache.bookkeeper.versioning.LongVersion in project bookkeeper by apache.

the class TestZkRegistrationClient method testGetWritableBookies.

@Test
public void testGetWritableBookies() throws Exception {
    Set<BookieSocketAddress> addresses = prepareNBookies(10);
    List<String> children = Lists.newArrayList();
    for (BookieSocketAddress address : addresses) {
        children.add(address.toString());
    }
    Stat stat = mock(Stat.class);
    when(stat.getCversion()).thenReturn(1234);
    mockGetChildren(regPath, false, Code.OK.intValue(), children, stat);
    Versioned<Set<BookieSocketAddress>> result = result(zkRegistrationClient.getWritableBookies());
    assertEquals(new LongVersion(1234), result.getVersion());
    assertSetEquals(addresses, result.getValue());
}
Also used : Stat(org.apache.zookeeper.data.Stat) Set(java.util.Set) HashSet(java.util.HashSet) BookieSocketAddress(org.apache.bookkeeper.net.BookieSocketAddress) LongVersion(org.apache.bookkeeper.versioning.LongVersion) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 18 with LongVersion

use of org.apache.bookkeeper.versioning.LongVersion in project bookkeeper by apache.

the class AbstractZkLedgerManagerTest method testLedgerMetadataListener.

@Test
public void testLedgerMetadataListener() throws Exception {
    long ledgerId = System.currentTimeMillis();
    String ledgerStr = String.valueOf(ledgerId);
    LinkedBlockingQueue<LedgerMetadata> changes = new LinkedBlockingQueue<>();
    LedgerMetadataListener listener = (ledgerId1, metadata) -> changes.add(metadata);
    metadata.setVersion(new LongVersion(1234L));
    Stat stat = mock(Stat.class);
    when(stat.getVersion()).thenReturn(1234);
    when(stat.getCtime()).thenReturn(metadata.getCtime());
    mockZkGetData(ledgerStr, true, KeeperException.Code.OK.intValue(), metadata.serialize(), stat);
    ledgerManager.registerLedgerMetadataListener(ledgerId, listener);
    // the listener will be notified with first get
    LedgerMetadata change1 = changes.take();
    assertEquals(metadata, change1);
    verify(mockZk, times(1)).getData(anyString(), any(Watcher.class), any(DataCallback.class), any());
    // the watcher is registered for receiving watched event
    assertTrue(watchers.containsKey(ledgerStr));
    Set<Watcher> watcherSet1 = watchers.get(ledgerStr);
    assertEquals(1, watcherSet1.size());
    Watcher registeredWatcher1 = watcherSet1.stream().findFirst().get();
    // mock get data to return an updated metadata
    metadata.setVersion(new LongVersion(1235L));
    when(stat.getVersion()).thenReturn(1235);
    mockZkGetData(ledgerStr, true, KeeperException.Code.OK.intValue(), metadata.serialize(), stat);
    // notify the watcher event
    notifyWatchedEvent(EventType.NodeDataChanged, KeeperState.SyncConnected, ledgerStr);
    // the listener should receive an updated metadata
    LedgerMetadata change2 = changes.take();
    assertEquals(metadata, change2);
    verify(mockZk, times(2)).getData(anyString(), any(Watcher.class), any(DataCallback.class), any());
    // after the listener receive an updated metadata, a new watcher should be registered
    // for subsequent changes again.
    assertTrue(watchers.containsKey(ledgerStr));
    Set<Watcher> watcherSet2 = watchers.get(ledgerStr);
    assertEquals(1, watcherSet2.size());
    Watcher registeredWatcher2 = watcherSet2.stream().findFirst().get();
    // zookeeper watchers are same, since there is only one giant watcher per ledger manager.
    assertSame(registeredWatcher1, registeredWatcher2);
    // verify scheduler
    verify(scheduler, times(2)).submit(any(Runnable.class));
    verify(scheduler, times(0)).schedule(any(Runnable.class), anyLong(), any(TimeUnit.class));
}
Also used : CreateMode(org.apache.zookeeper.CreateMode) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) VoidCallback(org.apache.zookeeper.AsyncCallback.VoidCallback) Stat(org.apache.zookeeper.data.Stat) Code(org.apache.bookkeeper.client.BKException.Code) CALLS_REAL_METHODS(org.mockito.Mockito.CALLS_REAL_METHODS) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Duration(java.time.Duration) After(org.junit.After) KeeperState(org.apache.zookeeper.Watcher.Event.KeeperState) Assert.fail(org.junit.Assert.fail) MockZooKeeperTestCase(org.apache.bookkeeper.zookeeper.MockZooKeeperTestCase) DigestType(org.apache.bookkeeper.client.BookKeeper.DigestType) LedgerMetadataListener(org.apache.bookkeeper.proto.BookkeeperInternalCallbacks.LedgerMetadataListener) Set(java.util.Set) StatCallback(org.apache.zookeeper.AsyncCallback.StatCallback) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Executors(java.util.concurrent.Executors) BKException(org.apache.bookkeeper.client.BKException) ZkUtils(org.apache.bookkeeper.util.ZkUtils) MockExecutorController(org.apache.bookkeeper.common.testing.executors.MockExecutorController) Assert.assertFalse(org.junit.Assert.assertFalse) Optional(java.util.Optional) Mockito.withSettings(org.mockito.Mockito.withSettings) Version(org.apache.bookkeeper.versioning.Version) Mockito.mock(org.mockito.Mockito.mock) GenericCallbackFuture(org.apache.bookkeeper.test.TestCallbacks.GenericCallbackFuture) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) LongVersion(org.apache.bookkeeper.versioning.LongVersion) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) RunWith(org.junit.runner.RunWith) LedgerMetadata(org.apache.bookkeeper.client.LedgerMetadata) Assert.assertSame(org.junit.Assert.assertSame) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) DataCallback(org.apache.zookeeper.AsyncCallback.DataCallback) PowerMockRunner(org.powermock.modules.junit4.PowerMockRunner) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) PowerMockito(org.powermock.api.mockito.PowerMockito) Before(org.junit.Before) ZK_CONNECT_BACKOFF_MS(org.apache.bookkeeper.meta.AbstractZkLedgerManager.ZK_CONNECT_BACKOFF_MS) KeeperException(org.apache.zookeeper.KeeperException) Watcher(org.apache.zookeeper.Watcher) Assert.assertTrue(org.junit.Assert.assertTrue) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) TimeUnit(java.util.concurrent.TimeUnit) Assert.assertNull(org.junit.Assert.assertNull) FutureUtils.result(org.apache.bookkeeper.common.concurrent.FutureUtils.result) ClientConfiguration(org.apache.bookkeeper.conf.ClientConfiguration) EventType(org.apache.zookeeper.Watcher.Event.EventType) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Watcher(org.apache.zookeeper.Watcher) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) DataCallback(org.apache.zookeeper.AsyncCallback.DataCallback) Stat(org.apache.zookeeper.data.Stat) LedgerMetadata(org.apache.bookkeeper.client.LedgerMetadata) LongVersion(org.apache.bookkeeper.versioning.LongVersion) TimeUnit(java.util.concurrent.TimeUnit) LedgerMetadataListener(org.apache.bookkeeper.proto.BookkeeperInternalCallbacks.LedgerMetadataListener) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 19 with LongVersion

use of org.apache.bookkeeper.versioning.LongVersion in project bookkeeper by apache.

the class AbstractZkLedgerManagerTest method testRemoveLedgerMetadataException.

@Test
public void testRemoveLedgerMetadataException() throws Exception {
    long ledgerId = System.currentTimeMillis();
    String ledgerStr = String.valueOf(ledgerId);
    LongVersion version = new LongVersion(1234L);
    mockZkDelete(ledgerStr, (int) version.getLongVersion(), KeeperException.Code.CONNECTIONLOSS.intValue());
    GenericCallbackFuture<Void> callbackFuture = new GenericCallbackFuture<>();
    ledgerManager.removeLedgerMetadata(ledgerId, version, callbackFuture);
    try {
        result(callbackFuture);
        fail("Should fail to remove metadata if no such ledger exists");
    } catch (BKException bke) {
        assertEquals(Code.ZKException, bke.getCode());
    }
    verify(mockZk, times(1)).delete(eq(ledgerStr), eq(1234), any(VoidCallback.class), eq(null));
}
Also used : VoidCallback(org.apache.zookeeper.AsyncCallback.VoidCallback) LongVersion(org.apache.bookkeeper.versioning.LongVersion) BKException(org.apache.bookkeeper.client.BKException) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) GenericCallbackFuture(org.apache.bookkeeper.test.TestCallbacks.GenericCallbackFuture) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 20 with LongVersion

use of org.apache.bookkeeper.versioning.LongVersion in project bookkeeper by apache.

the class AbstractZkLedgerManagerTest method testUnregisterLedgerMetadataListener.

@Test
public void testUnregisterLedgerMetadataListener() throws Exception {
    long ledgerId = System.currentTimeMillis();
    String ledgerStr = String.valueOf(ledgerId);
    LinkedBlockingQueue<LedgerMetadata> changes = new LinkedBlockingQueue<>();
    LedgerMetadataListener listener = (ledgerId1, metadata) -> changes.add(metadata);
    metadata.setVersion(new LongVersion(1234L));
    Stat stat = mock(Stat.class);
    when(stat.getVersion()).thenReturn(1234);
    when(stat.getCtime()).thenReturn(metadata.getCtime());
    mockZkGetData(ledgerStr, true, KeeperException.Code.OK.intValue(), metadata.serialize(), stat);
    ledgerManager.registerLedgerMetadataListener(ledgerId, listener);
    assertTrue(ledgerManager.listeners.containsKey(ledgerId));
    // the listener will be notified with first get
    LedgerMetadata change1 = changes.take();
    assertEquals(metadata, change1);
    verify(mockZk, times(1)).getData(anyString(), any(Watcher.class), any(DataCallback.class), any());
    // the watcher is registered for receiving watched event
    assertTrue(watchers.containsKey(ledgerStr));
    Set<Watcher> watcherSet1 = watchers.get(ledgerStr);
    assertEquals(1, watcherSet1.size());
    Watcher registeredWatcher1 = watcherSet1.stream().findFirst().get();
    // mock get data to return an updated metadata
    metadata.setVersion(new LongVersion(1235L));
    when(stat.getVersion()).thenReturn(1235);
    mockZkGetData(ledgerStr, true, KeeperException.Code.OK.intValue(), metadata.serialize(), stat);
    // unregister the listener
    ledgerManager.unregisterLedgerMetadataListener(ledgerId, listener);
    assertFalse(ledgerManager.listeners.containsKey(ledgerId));
    // notify the watcher event
    notifyWatchedEvent(EventType.NodeDataChanged, KeeperState.SyncConnected, ledgerStr);
    // since listener is already unregistered so no more `getData` is issued.
    assertNull(changes.poll());
    verify(mockZk, times(1)).getData(anyString(), any(Watcher.class), any(DataCallback.class), any());
}
Also used : CreateMode(org.apache.zookeeper.CreateMode) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) VoidCallback(org.apache.zookeeper.AsyncCallback.VoidCallback) Stat(org.apache.zookeeper.data.Stat) Code(org.apache.bookkeeper.client.BKException.Code) CALLS_REAL_METHODS(org.mockito.Mockito.CALLS_REAL_METHODS) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Duration(java.time.Duration) After(org.junit.After) KeeperState(org.apache.zookeeper.Watcher.Event.KeeperState) Assert.fail(org.junit.Assert.fail) MockZooKeeperTestCase(org.apache.bookkeeper.zookeeper.MockZooKeeperTestCase) DigestType(org.apache.bookkeeper.client.BookKeeper.DigestType) LedgerMetadataListener(org.apache.bookkeeper.proto.BookkeeperInternalCallbacks.LedgerMetadataListener) Set(java.util.Set) StatCallback(org.apache.zookeeper.AsyncCallback.StatCallback) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Executors(java.util.concurrent.Executors) BKException(org.apache.bookkeeper.client.BKException) ZkUtils(org.apache.bookkeeper.util.ZkUtils) MockExecutorController(org.apache.bookkeeper.common.testing.executors.MockExecutorController) Assert.assertFalse(org.junit.Assert.assertFalse) Optional(java.util.Optional) Mockito.withSettings(org.mockito.Mockito.withSettings) Version(org.apache.bookkeeper.versioning.Version) Mockito.mock(org.mockito.Mockito.mock) GenericCallbackFuture(org.apache.bookkeeper.test.TestCallbacks.GenericCallbackFuture) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) LongVersion(org.apache.bookkeeper.versioning.LongVersion) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) RunWith(org.junit.runner.RunWith) LedgerMetadata(org.apache.bookkeeper.client.LedgerMetadata) Assert.assertSame(org.junit.Assert.assertSame) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) DataCallback(org.apache.zookeeper.AsyncCallback.DataCallback) PowerMockRunner(org.powermock.modules.junit4.PowerMockRunner) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) PowerMockito(org.powermock.api.mockito.PowerMockito) Before(org.junit.Before) ZK_CONNECT_BACKOFF_MS(org.apache.bookkeeper.meta.AbstractZkLedgerManager.ZK_CONNECT_BACKOFF_MS) KeeperException(org.apache.zookeeper.KeeperException) Watcher(org.apache.zookeeper.Watcher) Assert.assertTrue(org.junit.Assert.assertTrue) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) TimeUnit(java.util.concurrent.TimeUnit) Assert.assertNull(org.junit.Assert.assertNull) FutureUtils.result(org.apache.bookkeeper.common.concurrent.FutureUtils.result) ClientConfiguration(org.apache.bookkeeper.conf.ClientConfiguration) EventType(org.apache.zookeeper.Watcher.Event.EventType) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Stat(org.apache.zookeeper.data.Stat) LedgerMetadata(org.apache.bookkeeper.client.LedgerMetadata) LongVersion(org.apache.bookkeeper.versioning.LongVersion) Watcher(org.apache.zookeeper.Watcher) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) DataCallback(org.apache.zookeeper.AsyncCallback.DataCallback) LedgerMetadataListener(org.apache.bookkeeper.proto.BookkeeperInternalCallbacks.LedgerMetadataListener) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

LongVersion (org.apache.bookkeeper.versioning.LongVersion)56 Test (org.junit.Test)37 Versioned (org.apache.bookkeeper.versioning.Versioned)29 Stat (org.apache.zookeeper.data.Stat)25 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)21 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)20 Version (org.apache.bookkeeper.versioning.Version)18 GenericCallbackFuture (org.apache.bookkeeper.test.TestCallbacks.GenericCallbackFuture)16 BKException (org.apache.bookkeeper.client.BKException)12 VoidCallback (org.apache.zookeeper.AsyncCallback.VoidCallback)12 Set (java.util.Set)11 LedgerMetadata (org.apache.bookkeeper.client.LedgerMetadata)10 StatCallback (org.apache.zookeeper.AsyncCallback.StatCallback)10 DataCallback (org.apache.zookeeper.AsyncCallback.DataCallback)9 Before (org.junit.Before)9 URI (java.net.URI)8 ZKException (org.apache.distributedlog.exceptions.ZKException)8 KeeperException (org.apache.zookeeper.KeeperException)8 Assert.assertEquals (org.junit.Assert.assertEquals)8 Assert.fail (org.junit.Assert.fail)8