Java Code Examples for org.apache.distributedlog.api.DistributedLogManager#getAsyncLogReaderWithLock()
The following examples show how to use
org.apache.distributedlog.api.DistributedLogManager#getAsyncLogReaderWithLock() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestAsyncReaderLock.java From distributedlog with Apache License 2.0 | 6 votes |
@Test(timeout = 60000) public void testReaderLockCloseInAcquireCallback() throws Exception { final String name = runtime.getMethodName(); DistributedLogManager dlm = createNewDLM(conf, name); BKAsyncLogWriter writer = (BKAsyncLogWriter) (dlm.startAsyncLogSegmentNonPartitioned()); writer.write(DLMTestUtil.getLogRecordInstance(1L)); writer.closeAndComplete(); final CountDownLatch latch = new CountDownLatch(1); CompletableFuture<AsyncLogReader> futureReader1 = dlm.getAsyncLogReaderWithLock(DLSN.InitialDLSN); futureReader1 .thenCompose( reader -> reader.asyncClose() .thenApply(result -> { latch.countDown(); return null; })); latch.await(); dlm.close(); }
Example 2
Source File: TestAsyncReaderLock.java From distributedlog with Apache License 2.0 | 6 votes |
@Test(timeout = 60000) public void testReaderLockFutureCancelledWhileLocked() throws Exception { String name = runtime.getMethodName(); DistributedLogManager dlm0 = createNewDLM(conf, name); BKAsyncLogWriter writer = (BKAsyncLogWriter) (dlm0.startAsyncLogSegmentNonPartitioned()); writer.write(DLMTestUtil.getLogRecordInstance(1L)); writer.write(DLMTestUtil.getLogRecordInstance(2L)); writer.closeAndComplete(); DistributedLogManager dlm1 = createNewDLM(conf, name); CompletableFuture<AsyncLogReader> futureReader1 = dlm1.getAsyncLogReaderWithLock(DLSN.InitialDLSN); // Must not throw or cancel or do anything bad, future already completed. Utils.ioResult(futureReader1); futureReader1.cancel(true); AsyncLogReader reader1 = Utils.ioResult(futureReader1); Utils.ioResult(reader1.readNext()); dlm0.close(); dlm1.close(); }
Example 3
Source File: TestAsyncReaderLock.java From distributedlog with Apache License 2.0 | 6 votes |
@Test(timeout = 60000) public void testReaderLockSharedDlmDoesNotConflict() throws Exception { String name = runtime.getMethodName(); DistributedLogManager dlm0 = createNewDLM(conf, name); BKAsyncLogWriter writer = (BKAsyncLogWriter) (dlm0.startAsyncLogSegmentNonPartitioned()); writer.write(DLMTestUtil.getLogRecordInstance(1L)); writer.write(DLMTestUtil.getLogRecordInstance(2L)); writer.closeAndComplete(); DistributedLogManager dlm1 = createNewDLM(conf, name); CompletableFuture<AsyncLogReader> futureReader1 = dlm1.getAsyncLogReaderWithLock(DLSN.InitialDLSN); CompletableFuture<AsyncLogReader> futureReader2 = dlm1.getAsyncLogReaderWithLock(DLSN.InitialDLSN); // Both use the same client id, so there's no lock conflict. Not necessarily ideal, but how the // system currently works. Utils.ioResult(futureReader1); Utils.ioResult(futureReader2); dlm0.close(); dlm1.close(); }
Example 4
Source File: TestAsyncReaderLock.java From distributedlog with Apache License 2.0 | 5 votes |
@Test(timeout = 60000) public void testReaderLockIfLockPathDoesntExist() throws Exception { final String name = runtime.getMethodName(); DistributedLogManager dlm = createNewDLM(conf, name); BKAsyncLogWriter writer = (BKAsyncLogWriter) (dlm.startAsyncLogSegmentNonPartitioned()); writer.write(DLMTestUtil.getLogRecordInstance(1L)); writer.closeAndComplete(); CompletableFuture<AsyncLogReader> futureReader1 = dlm.getAsyncLogReaderWithLock(DLSN.InitialDLSN); BKAsyncLogReader reader1 = (BKAsyncLogReader) Utils.ioResult(futureReader1); LogRecordWithDLSN record = Utils.ioResult(reader1.readNext()); assertEquals(1L, record.getTransactionId()); assertEquals(0L, record.getSequenceId()); DLMTestUtil.verifyLogRecord(record); String readLockPath = reader1.readHandler.getReadLockPath(); Utils.close(reader1); // simulate a old stream created without readlock path NamespaceDriver driver = dlm.getNamespaceDriver(); ((BKNamespaceDriver) driver).getWriterZKC().get().delete(readLockPath, -1); CompletableFuture<AsyncLogReader> futureReader2 = dlm.getAsyncLogReaderWithLock(DLSN.InitialDLSN); AsyncLogReader reader2 = Utils.ioResult(futureReader2); record = Utils.ioResult(reader2.readNext()); assertEquals(1L, record.getTransactionId()); assertEquals(0L, record.getSequenceId()); DLMTestUtil.verifyLogRecord(record); }
Example 5
Source File: TestAsyncReaderLock.java From distributedlog with Apache License 2.0 | 4 votes |
@Test(timeout = 60000) public void testReaderLockSessionExpires() throws Exception { String name = runtime.getMethodName(); URI uri = createDLMURI("/" + name); ensureURICreated(uri); Namespace ns0 = NamespaceBuilder.newBuilder() .conf(conf) .uri(uri) .build(); DistributedLogManager dlm0 = ns0.openLog(name); BKAsyncLogWriter writer = (BKAsyncLogWriter) (dlm0.startAsyncLogSegmentNonPartitioned()); writer.write(DLMTestUtil.getLogRecordInstance(1L)); writer.write(DLMTestUtil.getLogRecordInstance(2L)); writer.closeAndComplete(); Namespace ns1 = NamespaceBuilder.newBuilder() .conf(conf) .uri(uri) .build(); DistributedLogManager dlm1 = ns1.openLog(name); CompletableFuture<AsyncLogReader> futureReader1 = dlm1.getAsyncLogReaderWithLock(DLSN.InitialDLSN); AsyncLogReader reader1 = Utils.ioResult(futureReader1); ZooKeeperClientUtils.expireSession(((BKNamespaceDriver) ns1.getNamespaceDriver()).getWriterZKC(), zkServers, 1000); // The result of expireSession is somewhat non-deterministic with this lock. // It may fail with LockingException or it may succesfully reacquire, so for // the moment rather than make it deterministic we accept either result. boolean success = false; try { Utils.ioResult(reader1.readNext()); success = true; } catch (LockingException ex) { } if (success) { Utils.ioResult(reader1.readNext()); } Utils.close(reader1); dlm0.close(); ns0.close(); dlm1.close(); ns1.close(); }