use of org.apache.distributedlog.io.AsyncCloseable in project bookkeeper by apache.
the class TestDistributedLogBase method createNewDLM.
public BKDistributedLogManager createNewDLM(DistributedLogConfiguration conf, String name, PermitLimiter writeLimiter) throws Exception {
URI uri = createDLMURI("/" + name);
ensureURICreated(uri);
final Namespace namespace = NamespaceBuilder.newBuilder().uri(uri).conf(conf).build();
final OrderedScheduler scheduler = OrderedScheduler.newSchedulerBuilder().numThreads(1).name("test-scheduler").build();
AsyncCloseable resourcesCloseable = new AsyncCloseable() {
@Override
public CompletableFuture<Void> asyncClose() {
LOG.info("Shutting down the scheduler");
SchedulerUtils.shutdownScheduler(scheduler, 1, TimeUnit.SECONDS);
LOG.info("Shut down the scheduler");
LOG.info("Closing the namespace");
namespace.close();
LOG.info("Closed the namespace");
return FutureUtils.Void();
}
};
AsyncFailureInjector failureInjector = AsyncRandomFailureInjector.newBuilder().injectDelays(conf.getEIInjectReadAheadDelay(), conf.getEIInjectReadAheadDelayPercent(), conf.getEIInjectMaxReadAheadDelayMs()).injectErrors(false, 10).injectStops(conf.getEIInjectReadAheadStall(), 10).injectCorruption(conf.getEIInjectReadAheadBrokenEntries()).build();
return new BKDistributedLogManager(name, conf, ConfUtils.getConstDynConf(conf), uri, namespace.getNamespaceDriver(), new LogSegmentMetadataCache(conf, Ticker.systemTicker()), scheduler, DistributedLogConstants.UNKNOWN_CLIENT_ID, DistributedLogConstants.LOCAL_REGION_ID, writeLimiter, new SettableFeatureProvider("", 0), failureInjector, NullStatsLogger.INSTANCE, NullStatsLogger.INSTANCE, Optional.of(resourcesCloseable));
}
Aggregations