Search in sources :

Example 1 with LockClosedException

use of org.apache.distributedlog.lock.LockClosedException in project bookkeeper by apache.

the class TestAsyncReaderLock method testReaderLockFutureCancelledWhileWaiting.

@Test(timeout = 60000)
public void testReaderLockFutureCancelledWhileWaiting() 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);
    AsyncLogReader reader1 = Utils.ioResult(futureReader1);
    DistributedLogManager dlm2 = createNewDLM(conf, name);
    CompletableFuture<AsyncLogReader> futureReader2 = dlm2.getAsyncLogReaderWithLock(DLSN.InitialDLSN);
    try {
        futureReader2.cancel(true);
        Utils.ioResult(futureReader2);
        fail("Should fail getting log reader as it is cancelled");
    } catch (CancellationException ce) {
    } catch (LockClosedException ex) {
    } catch (LockCancelledException ex) {
    } catch (OwnershipAcquireFailedException oafe) {
    }
    futureReader2 = dlm2.getAsyncLogReaderWithLock(DLSN.InitialDLSN);
    Utils.close(reader1);
    Utils.ioResult(futureReader2);
    dlm0.close();
    dlm1.close();
    dlm2.close();
}
Also used : OwnershipAcquireFailedException(org.apache.distributedlog.exceptions.OwnershipAcquireFailedException) LockCancelledException(org.apache.distributedlog.exceptions.LockCancelledException) AsyncLogReader(org.apache.distributedlog.api.AsyncLogReader) CancellationException(java.util.concurrent.CancellationException) DistributedLogManager(org.apache.distributedlog.api.DistributedLogManager) LockClosedException(org.apache.distributedlog.lock.LockClosedException) Test(org.junit.Test)

Example 2 with LockClosedException

use of org.apache.distributedlog.lock.LockClosedException in project bookkeeper by apache.

the class TestAsyncReaderLock method testReaderLockDlmClosed.

@Test(timeout = 60000)
public void testReaderLockDlmClosed() 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);
    AsyncLogReader reader1 = Utils.ioResult(futureReader1);
    BKDistributedLogManager dlm2 = (BKDistributedLogManager) createNewDLM(conf, name);
    CompletableFuture<AsyncLogReader> futureReader2 = dlm2.getAsyncLogReaderWithLock(DLSN.InitialDLSN);
    dlm2.close();
    try {
        Utils.ioResult(futureReader2);
        fail("should have thrown exception!");
    } catch (CancellationException ce) {
    } catch (LockClosedException ex) {
    } catch (LockCancelledException ex) {
    }
    Utils.close(reader1);
    dlm0.close();
    dlm1.close();
}
Also used : LockCancelledException(org.apache.distributedlog.exceptions.LockCancelledException) AsyncLogReader(org.apache.distributedlog.api.AsyncLogReader) CancellationException(java.util.concurrent.CancellationException) DistributedLogManager(org.apache.distributedlog.api.DistributedLogManager) LockClosedException(org.apache.distributedlog.lock.LockClosedException) Test(org.junit.Test)

Aggregations

CancellationException (java.util.concurrent.CancellationException)2 AsyncLogReader (org.apache.distributedlog.api.AsyncLogReader)2 DistributedLogManager (org.apache.distributedlog.api.DistributedLogManager)2 LockCancelledException (org.apache.distributedlog.exceptions.LockCancelledException)2 LockClosedException (org.apache.distributedlog.lock.LockClosedException)2 Test (org.junit.Test)2 OwnershipAcquireFailedException (org.apache.distributedlog.exceptions.OwnershipAcquireFailedException)1