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());
}
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());
}
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());
}
}
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());
}
}
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);
}
Aggregations