Search in sources :

Example 1 with FixedValueFeature

use of org.apache.bookkeeper.feature.FixedValueFeature in project distributedlog by twitter.

the class TestAsyncReaderWriter method writeRecordsWithOutstandingWriteLimit.

public void writeRecordsWithOutstandingWriteLimit(int stream, int global, boolean shouldFail) throws Exception {
    DistributedLogConfiguration confLocal = new DistributedLogConfiguration();
    confLocal.addConfiguration(testConf);
    confLocal.setOutputBufferSize(0);
    confLocal.setImmediateFlushEnabled(true);
    confLocal.setPerWriterOutstandingWriteLimit(stream);
    confLocal.setOutstandingWriteLimitDarkmode(false);
    DistributedLogManager dlm;
    if (global > -1) {
        dlm = createNewDLM(confLocal, runtime.getMethodName(), new SimplePermitLimiter(false, global, new NullStatsLogger(), true, new FixedValueFeature("", 0)));
    } else {
        dlm = createNewDLM(confLocal, runtime.getMethodName());
    }
    BKAsyncLogWriter writer = (BKAsyncLogWriter) (dlm.startAsyncLogSegmentNonPartitioned());
    ArrayList<Future<DLSN>> results = new ArrayList<Future<DLSN>>(1000);
    for (int i = 0; i < 1000; i++) {
        results.add(writer.write(DLMTestUtil.getLogRecordInstance(1L)));
    }
    for (Future<DLSN> result : results) {
        try {
            Await.result(result);
            if (shouldFail) {
                fail("should fail due to no outstanding writes permitted");
            }
        } catch (OverCapacityException ex) {
            assertTrue(shouldFail);
        }
    }
    writer.closeAndComplete();
    dlm.close();
}
Also used : FixedValueFeature(org.apache.bookkeeper.feature.FixedValueFeature) ArrayList(java.util.ArrayList) DynamicDistributedLogConfiguration(com.twitter.distributedlog.config.DynamicDistributedLogConfiguration) NullStatsLogger(org.apache.bookkeeper.stats.NullStatsLogger) Future(com.twitter.util.Future) SimplePermitLimiter(com.twitter.distributedlog.util.SimplePermitLimiter) OverCapacityException(com.twitter.distributedlog.exceptions.OverCapacityException)

Aggregations

DynamicDistributedLogConfiguration (com.twitter.distributedlog.config.DynamicDistributedLogConfiguration)1 OverCapacityException (com.twitter.distributedlog.exceptions.OverCapacityException)1 SimplePermitLimiter (com.twitter.distributedlog.util.SimplePermitLimiter)1 Future (com.twitter.util.Future)1 ArrayList (java.util.ArrayList)1 FixedValueFeature (org.apache.bookkeeper.feature.FixedValueFeature)1 NullStatsLogger (org.apache.bookkeeper.stats.NullStatsLogger)1