Search in sources :

Example 1 with LedgerAllocatorPool

use of com.twitter.distributedlog.bk.LedgerAllocatorPool in project distributedlog by twitter.

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) DistributedLogNamespaceBuilder.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 = FutureUtils.result(dlm.openAsyncLogWriter());
        FutureUtils.result(writer.write(DLMTestUtil.getLogRecordInstance(1L)));
        fail("Should fail opening the writer");
    } catch (IOException ioe) {
    // expected
    } finally {
        FailpointUtils.removeFailpoint(FailpointUtils.FailPointName.FP_StartLogSegmentOnAssignLogSegmentSequenceNumber);
    }
    LedgerAllocator allocator = namespace.getLedgerAllocator();
    assertTrue(allocator instanceof LedgerAllocatorPool);
    LedgerAllocatorPool allocatorPool = (LedgerAllocatorPool) allocator;
    assertEquals(0, allocatorPool.obtainMapSize());
    AsyncLogWriter writer = FutureUtils.result(dlm.openAsyncLogWriter());
    writer.write(DLMTestUtil.getLogRecordInstance(1L));
    Utils.close(writer);
}
Also used : LedgerAllocatorPool(com.twitter.distributedlog.bk.LedgerAllocatorPool) LedgerAllocator(com.twitter.distributedlog.bk.LedgerAllocator) IOException(java.io.IOException) URI(java.net.URI) Test(org.junit.Test)

Aggregations

LedgerAllocator (com.twitter.distributedlog.bk.LedgerAllocator)1 LedgerAllocatorPool (com.twitter.distributedlog.bk.LedgerAllocatorPool)1 IOException (java.io.IOException)1 URI (java.net.URI)1 Test (org.junit.Test)1