Search in sources :

Example 16 with GenericCallbackFuture

use of org.apache.bookkeeper.test.TestCallbacks.GenericCallbackFuture in project bookkeeper by apache.

the class AbstractZkLedgerManagerTest method testReadLedgerMetadataSuccess.

@Test
public void testReadLedgerMetadataSuccess() throws Exception {
    long ledgerId = System.currentTimeMillis();
    String ledgerStr = String.valueOf(ledgerId);
    metadata.setVersion(new LongVersion(1234L));
    Stat stat = mock(Stat.class);
    when(stat.getVersion()).thenReturn(1234);
    when(stat.getCtime()).thenReturn(metadata.getCtime());
    mockZkGetData(ledgerStr, false, KeeperException.Code.OK.intValue(), metadata.serialize(), stat);
    GenericCallbackFuture<LedgerMetadata> callbackFuture = new GenericCallbackFuture<>();
    ledgerManager.readLedgerMetadata(ledgerId, callbackFuture);
    LedgerMetadata readMetadata = result(callbackFuture);
    assertEquals(metadata, readMetadata);
    verify(mockZk, times(1)).getData(eq(ledgerStr), eq(null), any(DataCallback.class), any());
}
Also used : Stat(org.apache.zookeeper.data.Stat) LedgerMetadata(org.apache.bookkeeper.client.LedgerMetadata) LongVersion(org.apache.bookkeeper.versioning.LongVersion) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) DataCallback(org.apache.zookeeper.AsyncCallback.DataCallback) GenericCallbackFuture(org.apache.bookkeeper.test.TestCallbacks.GenericCallbackFuture) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

GenericCallbackFuture (org.apache.bookkeeper.test.TestCallbacks.GenericCallbackFuture)16 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)16 Test (org.junit.Test)15 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)15 BKException (org.apache.bookkeeper.client.BKException)10 LongVersion (org.apache.bookkeeper.versioning.LongVersion)10 LedgerMetadata (org.apache.bookkeeper.client.LedgerMetadata)5 DataCallback (org.apache.zookeeper.AsyncCallback.DataCallback)5 VoidCallback (org.apache.zookeeper.AsyncCallback.VoidCallback)5 StatCallback (org.apache.zookeeper.AsyncCallback.StatCallback)3 Stat (org.apache.zookeeper.data.Stat)3 KeeperException (org.apache.zookeeper.KeeperException)2