assertTrue("Ledger " + lh.getId() + " should not be closed", readLh.isClosed()); assertEquals("Only one entry is written for ledger " + lh.getId(), 0L, lh.getLastAddPushed()); assertEquals("Only one entry is written for ledger " + lh.getId(), 0L, readLh.getLastAddConfirmed());
/** * Non durable write should fail if writer is marked as end of stream. * * @throws Exception */ @Test(timeout = 60000) public void testNondurableWrite() 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); assertEquals(DLSN.InvalidDLSN, Await.result(writer.asyncWrite(DLMTestUtil.getLogRecordInstance(2)))); assertEquals(-1L, ((BKLogSegmentEntryWriter) writer.getEntryWriter()) .getLedgerHandle().getLastAddPushed()); closeWriterAndLock(writer, lock); } }
@Override public void close() throws LogNotAvailableException { LedgerHandle _out = out; if (_out == null) { return; } try { LOGGER.log(Level.SEVERE, "Closing ledger " + _out.getId() + ", with LastAddConfirmed=" + _out.getLastAddConfirmed() + ", LastAddPushed=" + _out.getLastAddPushed() + " length=" + _out.getLength() + ", errorOccurred:" + errorOccurredDuringWrite); _out.close(); } catch (InterruptedException | BKException err) { throw new LogNotAvailableException(err); } finally { out = null; } }