use of org.apache.bookkeeper.test.TestCallbacks.GenericCallbackFuture in project bookkeeper by apache.
the class AbstractZkLedgerManagerTest method testReadLedgerMetadataException.
@Test
public void testReadLedgerMetadataException() throws Exception {
long ledgerId = System.currentTimeMillis();
String ledgerStr = String.valueOf(ledgerId);
mockZkGetData(ledgerStr, false, KeeperException.Code.CONNECTIONLOSS.intValue(), null, null);
GenericCallbackFuture<LedgerMetadata> callbackFuture = new GenericCallbackFuture<>();
ledgerManager.readLedgerMetadata(ledgerId, callbackFuture);
try {
result(callbackFuture);
fail("Should fail on reading ledger metadata if a ledger doesn't exist");
} catch (BKException bke) {
assertEquals(Code.ZKException, bke.getCode());
}
verify(mockZk, times(1)).getData(eq(ledgerStr), eq(null), any(DataCallback.class), any());
}
use of org.apache.bookkeeper.test.TestCallbacks.GenericCallbackFuture in project bookkeeper by apache.
the class AbstractZkLedgerManagerTest method testCreateLedgerMetadataSuccess.
@Test
public void testCreateLedgerMetadataSuccess() throws Exception {
long ledgerId = System.currentTimeMillis();
String ledgerStr = String.valueOf(ledgerId);
mockZkUtilsAsyncCreateFullPathOptimistic(ledgerStr, CreateMode.PERSISTENT, KeeperException.Code.OK.intValue(), ledgerStr);
assertEquals(Version.NEW, metadata.getVersion());
GenericCallbackFuture<Void> callbackFuture = new GenericCallbackFuture<>();
ledgerManager.createLedgerMetadata(ledgerId, metadata, callbackFuture);
callbackFuture.get();
assertEquals(new LongVersion(0), metadata.getVersion());
}
use of org.apache.bookkeeper.test.TestCallbacks.GenericCallbackFuture in project bookkeeper by apache.
the class AbstractZkLedgerManagerTest method testRemoveLedgerMetadataSuccess.
@Test
public void testRemoveLedgerMetadataSuccess() throws Exception {
long ledgerId = System.currentTimeMillis();
String ledgerStr = String.valueOf(ledgerId);
LongVersion version = new LongVersion(1234L);
mockZkDelete(ledgerStr, (int) version.getLongVersion(), KeeperException.Code.OK.intValue());
GenericCallbackFuture<Void> callbackFuture = new GenericCallbackFuture<>();
ledgerManager.removeLedgerMetadata(ledgerId, version, callbackFuture);
result(callbackFuture);
verify(mockZk, times(1)).delete(eq(ledgerStr), eq(1234), any(VoidCallback.class), eq(null));
}
use of org.apache.bookkeeper.test.TestCallbacks.GenericCallbackFuture in project bookkeeper by apache.
the class AbstractZkLedgerManagerTest method testReadLedgerMetadataStatMissing.
@Test
public void testReadLedgerMetadataStatMissing() throws Exception {
long ledgerId = System.currentTimeMillis();
String ledgerStr = String.valueOf(ledgerId);
mockZkGetData(ledgerStr, false, KeeperException.Code.OK.intValue(), metadata.serialize(), null);
GenericCallbackFuture<LedgerMetadata> callbackFuture = new GenericCallbackFuture<>();
ledgerManager.readLedgerMetadata(ledgerId, callbackFuture);
try {
result(callbackFuture);
fail("Should fail on reading ledger metadata if a ledger doesn't exist");
} catch (BKException bke) {
assertEquals(Code.ZKException, bke.getCode());
}
verify(mockZk, times(1)).getData(eq(ledgerStr), eq(null), any(DataCallback.class), any());
}
use of org.apache.bookkeeper.test.TestCallbacks.GenericCallbackFuture in project bookkeeper by apache.
the class AbstractZkLedgerManagerTest method testWriteLedgerMetadataBadVersion.
@Test
public void testWriteLedgerMetadataBadVersion() throws Exception {
long ledgerId = System.currentTimeMillis();
String ledgerStr = String.valueOf(ledgerId);
metadata.setVersion(new LongVersion(1234L));
mockZkSetData(ledgerStr, metadata.serialize(), 1234, KeeperException.Code.BADVERSION.intValue(), null);
assertEquals(new LongVersion(1234L), metadata.getVersion());
GenericCallbackFuture<Void> callbackFuture = new GenericCallbackFuture<>();
ledgerManager.writeLedgerMetadata(ledgerId, metadata, callbackFuture);
try {
result(callbackFuture);
fail("Should fail on writing ledger metadata if encountering bad version");
} catch (BKException bke) {
assertEquals(Code.MetadataVersionException, bke.getCode());
}
// version remain unchanged
assertEquals(new LongVersion(1234L), metadata.getVersion());
verify(mockZk, times(1)).setData(eq(ledgerStr), any(byte[].class), eq(1234), any(StatCallback.class), any());
}
Aggregations