Search in sources :

Example 1 with LedgerAllocatorPool

use of org.apache.distributedlog.bk.LedgerAllocatorPool in project bookkeeper by apache.

the class TestBKLogWriteHandler method testAbortTransactionOnStartLogSegment.

/**
 * Testcase: when write handler encounters exceptions on starting log segment
 * it should abort the transaction and return the ledger to the pool.
 */
@Test(timeout = 60000)
public void testAbortTransactionOnStartLogSegment() throws Exception {
    URI uri = createDLMURI("/" + runtime.getMethodName());
    ensureURICreated(zkc, uri);
    DistributedLogConfiguration confLocal = new DistributedLogConfiguration();
    confLocal.addConfiguration(conf);
    confLocal.setOutputBufferSize(0);
    confLocal.setEnableLedgerAllocatorPool(true);
    confLocal.setLedgerAllocatorPoolCoreSize(1);
    confLocal.setLedgerAllocatorPoolName("test-allocator-pool");
    BKDistributedLogNamespace namespace = (BKDistributedLogNamespace) NamespaceBuilder.newBuilder().conf(confLocal).uri(uri).build();
    DistributedLogManager dlm = namespace.openLog("test-stream");
    FailpointUtils.setFailpoint(FailpointUtils.FailPointName.FP_StartLogSegmentOnAssignLogSegmentSequenceNumber, FailpointUtils.FailPointActions.FailPointAction_Throw);
    try {
        AsyncLogWriter writer = Utils.ioResult(dlm.openAsyncLogWriter());
        Utils.ioResult(writer.write(DLMTestUtil.getLogRecordInstance(1L)));
        fail("Should fail opening the writer");
    } catch (IOException ioe) {
    // expected
    } finally {
        FailpointUtils.removeFailpoint(FailpointUtils.FailPointName.FP_StartLogSegmentOnAssignLogSegmentSequenceNumber);
    }
    LedgerAllocator allocator = ((BKNamespaceDriver) namespace.getNamespaceDriver()).getLedgerAllocator();
    assertTrue(allocator instanceof LedgerAllocatorPool);
    LedgerAllocatorPool allocatorPool = (LedgerAllocatorPool) allocator;
    assertEquals(0, allocatorPool.obtainMapSize());
    AsyncLogWriter writer = Utils.ioResult(dlm.openAsyncLogWriter());
    writer.write(DLMTestUtil.getLogRecordInstance(1L));
    Utils.close(writer);
}
Also used : LedgerAllocatorPool(org.apache.distributedlog.bk.LedgerAllocatorPool) LedgerAllocator(org.apache.distributedlog.bk.LedgerAllocator) DistributedLogManager(org.apache.distributedlog.api.DistributedLogManager) BKNamespaceDriver(org.apache.distributedlog.impl.BKNamespaceDriver) AsyncLogWriter(org.apache.distributedlog.api.AsyncLogWriter) IOException(java.io.IOException) URI(java.net.URI) Test(org.junit.Test)

Aggregations

IOException (java.io.IOException)1 URI (java.net.URI)1 AsyncLogWriter (org.apache.distributedlog.api.AsyncLogWriter)1 DistributedLogManager (org.apache.distributedlog.api.DistributedLogManager)1 LedgerAllocator (org.apache.distributedlog.bk.LedgerAllocator)1 LedgerAllocatorPool (org.apache.distributedlog.bk.LedgerAllocatorPool)1 BKNamespaceDriver (org.apache.distributedlog.impl.BKNamespaceDriver)1 Test (org.junit.Test)1