Search in sources :

Example 11 with ZKDistributedLock

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

the class TestBKLogSegmentWriter method testNondurableWriteAfterWriterIsClosed.

/**
 * Non durable write should fail if writer is closed.
 *
 * @throws Exception
 */
@Test(timeout = 60000)
public void testNondurableWriteAfterWriterIsClosed() throws Exception {
    DistributedLogConfiguration confLocal = newLocalConf();
    confLocal.setImmediateFlushEnabled(false);
    confLocal.setOutputBufferSize(Integer.MAX_VALUE);
    confLocal.setPeriodicFlushFrequencyMilliSeconds(0);
    confLocal.setDurableWriteEnabled(false);
    ZKDistributedLock lock = createLock("/test/lock-" + runtime.getMethodName(), zkc, true);
    BKLogSegmentWriter writer = createLogSegmentWriter(confLocal, 0L, -1L, lock);
    // close the writer
    closeWriterAndLock(writer, lock);
    Utils.ioResult(writer.asyncClose());
    try {
        Utils.ioResult(writer.asyncWrite(DLMTestUtil.getLogRecordInstance(1)));
        fail("Should fail the write if the writer is closed");
    } catch (WriteException we) {
    // expected
    }
}
Also used : WriteException(org.apache.distributedlog.exceptions.WriteException) ZKDistributedLock(org.apache.distributedlog.lock.ZKDistributedLock) Test(org.junit.Test)

Aggregations

ZKDistributedLock (org.apache.distributedlog.lock.ZKDistributedLock)11 Test (org.junit.Test)9 ArrayList (java.util.ArrayList)6 CompletableFuture (java.util.concurrent.CompletableFuture)6 LedgerHandle (org.apache.bookkeeper.client.LedgerHandle)5 BKTransmitException (org.apache.distributedlog.exceptions.BKTransmitException)4 WriteCancelledException (org.apache.distributedlog.exceptions.WriteCancelledException)3 WriteException (org.apache.distributedlog.exceptions.WriteException)2 CountDownLatch (java.util.concurrent.CountDownLatch)1 EndOfStreamException (org.apache.distributedlog.exceptions.EndOfStreamException)1 ZKException (org.apache.distributedlog.exceptions.ZKException)1 BKLogSegmentEntryWriter (org.apache.distributedlog.impl.logsegment.BKLogSegmentEntryWriter)1 SessionLockFactory (org.apache.distributedlog.lock.SessionLockFactory)1 ZKSessionLockFactory (org.apache.distributedlog.lock.ZKSessionLockFactory)1