Search in sources :

Example 1 with GenericCallbackFuture

use of org.apache.bookkeeper.test.TestCallbacks.GenericCallbackFuture 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 2 with GenericCallbackFuture

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

the class AbstractZkLedgerManagerTest method testReadLedgerMetadataNoNode.

@Test
public void testReadLedgerMetadataNoNode() throws Exception {
    long ledgerId = System.currentTimeMillis();
    String ledgerStr = String.valueOf(ledgerId);
    mockZkGetData(ledgerStr, false, KeeperException.Code.NONODE.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.NoSuchLedgerExistsException, bke.getCode());
    }
    verify(mockZk, times(1)).getData(eq(ledgerStr), eq(null), any(DataCallback.class), any());
}
Also used : LedgerMetadata(org.apache.bookkeeper.client.LedgerMetadata) BKException(org.apache.bookkeeper.client.BKException) 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)

Example 3 with GenericCallbackFuture

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

the class AbstractZkLedgerManagerTest method testCreateLedgerMetadataNodeExists.

@Test
public void testCreateLedgerMetadataNodeExists() throws Exception {
    long ledgerId = System.currentTimeMillis();
    String ledgerStr = String.valueOf(ledgerId);
    mockZkUtilsAsyncCreateFullPathOptimistic(ledgerStr, CreateMode.PERSISTENT, KeeperException.Code.NODEEXISTS.intValue(), null);
    assertEquals(Version.NEW, metadata.getVersion());
    GenericCallbackFuture<Void> callbackFuture = new GenericCallbackFuture<>();
    ledgerManager.createLedgerMetadata(ledgerId, metadata, callbackFuture);
    try {
        result(callbackFuture);
        fail("Should fail to create ledger metadata if the ledger already exists");
    } catch (Exception e) {
        assertTrue(e instanceof BKException);
        BKException bke = (BKException) e;
        assertEquals(Code.LedgerExistException, bke.getCode());
    }
    // creation failed, so metadata should not be modified
    assertEquals(Version.NEW, metadata.getVersion());
}
Also used : BKException(org.apache.bookkeeper.client.BKException) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) BKException(org.apache.bookkeeper.client.BKException) KeeperException(org.apache.zookeeper.KeeperException) GenericCallbackFuture(org.apache.bookkeeper.test.TestCallbacks.GenericCallbackFuture) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 4 with GenericCallbackFuture

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

the class AbstractZkLedgerManagerTest method testCreateLedgerMetadataException.

@Test
public void testCreateLedgerMetadataException() throws Exception {
    long ledgerId = System.currentTimeMillis();
    String ledgerStr = String.valueOf(ledgerId);
    mockZkUtilsAsyncCreateFullPathOptimistic(ledgerStr, CreateMode.PERSISTENT, KeeperException.Code.CONNECTIONLOSS.intValue(), null);
    assertEquals(Version.NEW, metadata.getVersion());
    GenericCallbackFuture<Void> callbackFuture = new GenericCallbackFuture<>();
    ledgerManager.createLedgerMetadata(ledgerId, metadata, callbackFuture);
    try {
        result(callbackFuture);
        fail("Should fail to create ledger metadata when encountering zookeeper exception");
    } catch (Exception e) {
        assertTrue(e instanceof BKException);
        BKException bke = (BKException) e;
        assertEquals(Code.ZKException, bke.getCode());
    }
    // creation failed, so metadata should not be modified
    assertEquals(Version.NEW, metadata.getVersion());
}
Also used : BKException(org.apache.bookkeeper.client.BKException) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) BKException(org.apache.bookkeeper.client.BKException) KeeperException(org.apache.zookeeper.KeeperException) GenericCallbackFuture(org.apache.bookkeeper.test.TestCallbacks.GenericCallbackFuture) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 5 with GenericCallbackFuture

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

the class AbstractZkLedgerManagerTest method testRemoveLedgerMetadataVersionAny.

@Test
public void testRemoveLedgerMetadataVersionAny() throws Exception {
    long ledgerId = System.currentTimeMillis();
    String ledgerStr = String.valueOf(ledgerId);
    mockZkDelete(ledgerStr, -1, KeeperException.Code.OK.intValue());
    GenericCallbackFuture<Void> callbackFuture = new GenericCallbackFuture<>();
    ledgerManager.removeLedgerMetadata(ledgerId, Version.ANY, callbackFuture);
    result(callbackFuture);
    verify(mockZk, times(1)).delete(eq(ledgerStr), eq(-1), any(VoidCallback.class), eq(null));
}
Also used : VoidCallback(org.apache.zookeeper.AsyncCallback.VoidCallback) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) 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