Search in sources :

Example 11 with ZooKeeperClient

use of org.apache.distributedlog.ZooKeeperClient in project bookkeeper by apache.

the class TestZKTransaction method testAbortTransaction.

@Test(timeout = 60000)
public void testAbortTransaction() throws Exception {
    ZooKeeperClient zkc = mock(ZooKeeperClient.class);
    ZKTransaction transaction = new ZKTransaction(zkc);
    int numOps = 3;
    final CountDownLatch commitLatch = new CountDownLatch(numOps);
    final CountDownLatch abortLatch = new CountDownLatch(numOps);
    for (int i = 0; i < numOps; i++) {
        transaction.addOp(new CountDownZKOp(commitLatch, abortLatch));
    }
    transaction.abort(new DLIllegalStateException("Illegal State"));
    abortLatch.await();
    assertEquals(0, abortLatch.getCount());
    assertEquals(numOps, commitLatch.getCount());
}
Also used : ZooKeeperClient(org.apache.distributedlog.ZooKeeperClient) DLIllegalStateException(org.apache.distributedlog.exceptions.DLIllegalStateException) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 12 with ZooKeeperClient

use of org.apache.distributedlog.ZooKeeperClient in project bookkeeper by apache.

the class TestZKTransaction method testProcessNullResults.

@Test(timeout = 60000)
public void testProcessNullResults() throws Exception {
    ZooKeeperClient zkc = mock(ZooKeeperClient.class);
    ZKTransaction transaction = new ZKTransaction(zkc);
    int numOps = 3;
    final CountDownLatch commitLatch = new CountDownLatch(numOps);
    final CountDownLatch abortLatch = new CountDownLatch(numOps);
    for (int i = 0; i < numOps; i++) {
        transaction.addOp(new CountDownZKOp(commitLatch, abortLatch));
    }
    transaction.processResult(KeeperException.Code.CONNECTIONLOSS.intValue(), "test-path", null, null);
    abortLatch.await();
    assertEquals(0, abortLatch.getCount());
    assertEquals(numOps, commitLatch.getCount());
}
Also used : ZooKeeperClient(org.apache.distributedlog.ZooKeeperClient) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 13 with ZooKeeperClient

use of org.apache.distributedlog.ZooKeeperClient in project bookkeeper by apache.

the class TestZKLogStreamMetadataStore method testGetLogSegmentsZKExceptions.

@Test(timeout = 60000)
public void testGetLogSegmentsZKExceptions() throws Exception {
    String logName = testName.getMethodName();
    String logIdentifier = "<default>";
    ZooKeeper mockZk = mock(ZooKeeper.class);
    ZooKeeperClient mockZkc = mock(ZooKeeperClient.class);
    when(mockZkc.get()).thenReturn(mockZk);
    doAnswer(invocationOnMock -> {
        String path = (String) invocationOnMock.getArguments()[0];
        Children2Callback callback = (Children2Callback) invocationOnMock.getArguments()[2];
        callback.processResult(Code.BADVERSION.intValue(), path, null, null, null);
        return null;
    }).when(mockZk).getChildren(anyString(), anyBoolean(), any(Children2Callback.class), any());
    String logSegmentsPath = LogMetadata.getLogSegmentsPath(uri, logName, logIdentifier);
    try {
        FutureUtils.result(getLogSegments(mockZkc, logSegmentsPath));
        fail("Should fail to get log segments when encountering zk exceptions");
    } catch (ZKException zke) {
        assertEquals(Code.BADVERSION, zke.getKeeperExceptionCode());
    }
}
Also used : ZKException(org.apache.distributedlog.exceptions.ZKException) ZooKeeper(org.apache.zookeeper.ZooKeeper) ZooKeeperClient(org.apache.distributedlog.ZooKeeperClient) Children2Callback(org.apache.zookeeper.AsyncCallback.Children2Callback) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 14 with ZooKeeperClient

use of org.apache.distributedlog.ZooKeeperClient in project bookkeeper by apache.

the class TestZKLogStreamMetadataStore method testGetMissingPathsFailure.

@Test(timeout = 60000)
public void testGetMissingPathsFailure() throws Exception {
    ZooKeeper mockZk = mock(ZooKeeper.class);
    ZooKeeperClient mockZkc = mock(ZooKeeperClient.class);
    when(mockZkc.get()).thenReturn(mockZk);
    doAnswer(invocationOnMock -> {
        String path = (String) invocationOnMock.getArguments()[0];
        StatCallback callback = (StatCallback) invocationOnMock.getArguments()[2];
        callback.processResult(Code.BADVERSION.intValue(), path, null, null);
        return null;
    }).when(mockZk).exists(anyString(), anyBoolean(), any(StatCallback.class), any());
    try {
        FutureUtils.result(getMissingPaths(mockZkc, uri, "path_failure/to/log_failure"));
        fail("Should fail on getting missing paths on zookeeper exceptions.");
    } catch (ZKException zke) {
        assertEquals(Code.BADVERSION, zke.getKeeperExceptionCode());
    }
}
Also used : ZKException(org.apache.distributedlog.exceptions.ZKException) ZooKeeper(org.apache.zookeeper.ZooKeeper) ZooKeeperClient(org.apache.distributedlog.ZooKeeperClient) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) StatCallback(org.apache.zookeeper.AsyncCallback.StatCallback) Test(org.junit.Test)

Example 15 with ZooKeeperClient

use of org.apache.distributedlog.ZooKeeperClient in project bookkeeper by apache.

the class TestFederatedZKLogMetadataStore method testZooKeeperSessionExpired.

@Test(timeout = 60000)
public void testZooKeeperSessionExpired() throws Exception {
    Set<String> allLogs = createLogs(2 * maxLogsPerSubnamespace, "test-zookeeper-session-expired-");
    TestNamespaceListenerWithExpectedSize listener = new TestNamespaceListenerWithExpectedSize(2 * maxLogsPerSubnamespace + 1);
    metadataStore.registerNamespaceListener(listener);
    ZooKeeperClientUtils.expireSession(zkc, BKNamespaceDriver.getZKServersFromDLUri(uri), zkSessionTimeoutMs);
    String testLogName = "test-log-name";
    allLogs.add(testLogName);
    DistributedLogConfiguration anotherConf = new DistributedLogConfiguration();
    anotherConf.addConfiguration(baseConf);
    ZooKeeperClient anotherZkc = TestZooKeeperClientBuilder.newBuilder().uri(uri).sessionTimeoutMs(zkSessionTimeoutMs).build();
    FederatedZKLogMetadataStore anotherMetadataStore = new FederatedZKLogMetadataStore(anotherConf, uri, anotherZkc, scheduler);
    Utils.ioResult(anotherMetadataStore.createLog(testLogName));
    listener.waitForDone();
    Set<String> receivedLogs = listener.getResult();
    assertEquals(2 * maxLogsPerSubnamespace + 1, receivedLogs.size());
    assertEquals(allLogs, receivedLogs);
}
Also used : DistributedLogConfiguration(org.apache.distributedlog.DistributedLogConfiguration) ZooKeeperClient(org.apache.distributedlog.ZooKeeperClient) Test(org.junit.Test)

Aggregations

ZooKeeperClient (org.apache.distributedlog.ZooKeeperClient)16 DistributedLogConfiguration (org.apache.distributedlog.DistributedLogConfiguration)6 Test (org.junit.Test)6 KeeperException (org.apache.zookeeper.KeeperException)5 ZooKeeper (org.apache.zookeeper.ZooKeeper)5 IOException (java.io.IOException)4 CompletableFuture (java.util.concurrent.CompletableFuture)4 ZKException (org.apache.distributedlog.exceptions.ZKException)4 URI (java.net.URI)3 DLInterruptedException (org.apache.distributedlog.exceptions.DLInterruptedException)3 AsyncCallback (org.apache.zookeeper.AsyncCallback)3 Stat (org.apache.zookeeper.data.Stat)3 CancellationException (java.util.concurrent.CancellationException)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 ExecutorService (java.util.concurrent.ExecutorService)2 LongVersion (org.apache.bookkeeper.versioning.LongVersion)2 Versioned (org.apache.bookkeeper.versioning.Versioned)2 BoundExponentialBackoffRetryPolicy (org.apache.bookkeeper.zookeeper.BoundExponentialBackoffRetryPolicy)2 RetryPolicy (org.apache.bookkeeper.zookeeper.RetryPolicy)2 BookKeeperClient (org.apache.distributedlog.BookKeeperClient)2