Search in sources :

Example 1 with ConcurrentConstConfiguration

use of com.twitter.distributedlog.config.ConcurrentConstConfiguration in project distributedlog by twitter.

the class TestAsyncReaderWriter method testCreateLogStreamWithDifferentReplicationFactor.

@Test(timeout = 60000)
public void testCreateLogStreamWithDifferentReplicationFactor() throws Exception {
    String name = runtime.getMethodName();
    DistributedLogConfiguration confLocal = new DistributedLogConfiguration();
    confLocal.addConfiguration(testConf);
    confLocal.setOutputBufferSize(0);
    confLocal.setImmediateFlushEnabled(false);
    confLocal.setPeriodicFlushFrequencyMilliSeconds(0);
    ConcurrentBaseConfiguration baseConf = new ConcurrentConstConfiguration(confLocal);
    DynamicDistributedLogConfiguration dynConf = new DynamicDistributedLogConfiguration(baseConf);
    dynConf.setProperty(DistributedLogConfiguration.BKDL_BOOKKEEPER_ENSEMBLE_SIZE, DistributedLogConfiguration.BKDL_BOOKKEEPER_ENSEMBLE_SIZE_DEFAULT - 1);
    URI uri = createDLMURI("/" + name);
    ensureURICreated(uri);
    DistributedLogNamespace namespace = DistributedLogNamespaceBuilder.newBuilder().conf(confLocal).uri(uri).build();
    // use the pool
    DistributedLogManager dlm = namespace.openLog(name + "-pool");
    AsyncLogWriter writer = dlm.startAsyncLogSegmentNonPartitioned();
    FutureUtils.result(writer.write(DLMTestUtil.getLogRecordInstance(1L)));
    List<LogSegmentMetadata> segments = dlm.getLogSegments();
    assertEquals(1, segments.size());
    long ledgerId = segments.get(0).getLedgerId();
    LedgerHandle lh = ((BKDistributedLogNamespace) namespace).getReaderBKC().get().openLedgerNoRecovery(ledgerId, BookKeeper.DigestType.CRC32, confLocal.getBKDigestPW().getBytes(UTF_8));
    LedgerMetadata metadata = BookKeeperAccessor.getLedgerMetadata(lh);
    assertEquals(DistributedLogConfiguration.BKDL_BOOKKEEPER_ENSEMBLE_SIZE_DEFAULT, metadata.getEnsembleSize());
    lh.close();
    Utils.close(writer);
    dlm.close();
    // use customized configuration
    dlm = namespace.openLog(name + "-custom", Optional.<DistributedLogConfiguration>absent(), Optional.of(dynConf));
    writer = dlm.startAsyncLogSegmentNonPartitioned();
    FutureUtils.result(writer.write(DLMTestUtil.getLogRecordInstance(1L)));
    segments = dlm.getLogSegments();
    assertEquals(1, segments.size());
    ledgerId = segments.get(0).getLedgerId();
    lh = ((BKDistributedLogNamespace) namespace).getReaderBKC().get().openLedgerNoRecovery(ledgerId, BookKeeper.DigestType.CRC32, confLocal.getBKDigestPW().getBytes(UTF_8));
    metadata = BookKeeperAccessor.getLedgerMetadata(lh);
    assertEquals(DistributedLogConfiguration.BKDL_BOOKKEEPER_ENSEMBLE_SIZE_DEFAULT - 1, metadata.getEnsembleSize());
    lh.close();
    Utils.close(writer);
    dlm.close();
    namespace.close();
}
Also used : LedgerHandle(org.apache.bookkeeper.client.LedgerHandle) DistributedLogNamespace(com.twitter.distributedlog.namespace.DistributedLogNamespace) ConcurrentConstConfiguration(com.twitter.distributedlog.config.ConcurrentConstConfiguration) DynamicDistributedLogConfiguration(com.twitter.distributedlog.config.DynamicDistributedLogConfiguration) URI(java.net.URI) ConcurrentBaseConfiguration(com.twitter.distributedlog.config.ConcurrentBaseConfiguration) DynamicDistributedLogConfiguration(com.twitter.distributedlog.config.DynamicDistributedLogConfiguration) LedgerMetadata(org.apache.bookkeeper.client.LedgerMetadata) Test(org.junit.Test)

Example 2 with ConcurrentConstConfiguration

use of com.twitter.distributedlog.config.ConcurrentConstConfiguration in project distributedlog by twitter.

the class TestServiceRequestLimiter method testDynamicLimiter.

@Test(timeout = 60000)
public void testDynamicLimiter() throws Exception {
    final AtomicInteger id = new AtomicInteger(0);
    final DynamicDistributedLogConfiguration dynConf = new DynamicDistributedLogConfiguration(new ConcurrentConstConfiguration(new DistributedLogConfiguration()));
    DynamicRequestLimiter<MockRequest> limiter = new DynamicRequestLimiter<MockRequest>(dynConf, NullStatsLogger.INSTANCE, new SettableFeature("", 0)) {

        @Override
        public RequestLimiter<MockRequest> build() {
            id.getAndIncrement();
            return new MockRequestLimiter();
        }
    };
    limiter.initialize();
    assertEquals(1, id.get());
    dynConf.setProperty("test1", 1);
    assertEquals(2, id.get());
    dynConf.setProperty("test2", 2);
    assertEquals(3, id.get());
}
Also used : DistributedLogConfiguration(com.twitter.distributedlog.DistributedLogConfiguration) DynamicDistributedLogConfiguration(com.twitter.distributedlog.config.DynamicDistributedLogConfiguration) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ConcurrentConstConfiguration(com.twitter.distributedlog.config.ConcurrentConstConfiguration) DynamicDistributedLogConfiguration(com.twitter.distributedlog.config.DynamicDistributedLogConfiguration) SettableFeature(org.apache.bookkeeper.feature.SettableFeature) Test(org.junit.Test)

Example 3 with ConcurrentConstConfiguration

use of com.twitter.distributedlog.config.ConcurrentConstConfiguration in project distributedlog by twitter.

the class TestServiceRequestLimiter method testDynamicLimiterWithException.

@Test(timeout = 60000)
public void testDynamicLimiterWithException() throws Exception {
    final AtomicInteger id = new AtomicInteger(0);
    final DynamicDistributedLogConfiguration dynConf = new DynamicDistributedLogConfiguration(new ConcurrentConstConfiguration(new DistributedLogConfiguration()));
    DynamicRequestLimiter<MockRequest> limiter = new DynamicRequestLimiter<MockRequest>(dynConf, NullStatsLogger.INSTANCE, new SettableFeature("", 0)) {

        @Override
        public RequestLimiter<MockRequest> build() {
            if (id.incrementAndGet() >= 2) {
                throw new RuntimeException("exception in dynamic limiter build()");
            }
            return new MockRequestLimiter();
        }
    };
    limiter.initialize();
    assertEquals(1, id.get());
    try {
        dynConf.setProperty("test1", 1);
        fail("should have thrown on config failure");
    } catch (RuntimeException ex) {
    }
    assertEquals(2, id.get());
}
Also used : DistributedLogConfiguration(com.twitter.distributedlog.DistributedLogConfiguration) DynamicDistributedLogConfiguration(com.twitter.distributedlog.config.DynamicDistributedLogConfiguration) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ConcurrentConstConfiguration(com.twitter.distributedlog.config.ConcurrentConstConfiguration) DynamicDistributedLogConfiguration(com.twitter.distributedlog.config.DynamicDistributedLogConfiguration) SettableFeature(org.apache.bookkeeper.feature.SettableFeature) Test(org.junit.Test)

Example 4 with ConcurrentConstConfiguration

use of com.twitter.distributedlog.config.ConcurrentConstConfiguration in project distributedlog by twitter.

the class TestServiceRequestLimiter method testDynamicLimiterWithDisabledFeature.

@Test(timeout = 60000)
public void testDynamicLimiterWithDisabledFeature() throws Exception {
    final DynamicDistributedLogConfiguration dynConf = new DynamicDistributedLogConfiguration(new ConcurrentConstConfiguration(new DistributedLogConfiguration()));
    final MockSoftRequestLimiter rateLimiter = new MockSoftRequestLimiter(0);
    final SettableFeature disabledFeature = new SettableFeature("", 0);
    DynamicRequestLimiter<MockRequest> limiter = new DynamicRequestLimiter<MockRequest>(dynConf, NullStatsLogger.INSTANCE, disabledFeature) {

        @Override
        public RequestLimiter<MockRequest> build() {
            return rateLimiter;
        }
    };
    limiter.initialize();
    assertEquals(0, rateLimiter.getLimitHitCount());
    // Not disabled, rate limiter was invoked
    limiter.apply(new MockRequest(Integer.MAX_VALUE));
    assertEquals(1, rateLimiter.getLimitHitCount());
    // Disabled, rate limiter not invoked
    disabledFeature.set(1);
    limiter.apply(new MockRequest(Integer.MAX_VALUE));
    assertEquals(1, rateLimiter.getLimitHitCount());
}
Also used : DistributedLogConfiguration(com.twitter.distributedlog.DistributedLogConfiguration) DynamicDistributedLogConfiguration(com.twitter.distributedlog.config.DynamicDistributedLogConfiguration) ConcurrentConstConfiguration(com.twitter.distributedlog.config.ConcurrentConstConfiguration) DynamicDistributedLogConfiguration(com.twitter.distributedlog.config.DynamicDistributedLogConfiguration) SettableFeature(org.apache.bookkeeper.feature.SettableFeature) Test(org.junit.Test)

Aggregations

ConcurrentConstConfiguration (com.twitter.distributedlog.config.ConcurrentConstConfiguration)4 DynamicDistributedLogConfiguration (com.twitter.distributedlog.config.DynamicDistributedLogConfiguration)4 Test (org.junit.Test)4 DistributedLogConfiguration (com.twitter.distributedlog.DistributedLogConfiguration)3 SettableFeature (org.apache.bookkeeper.feature.SettableFeature)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 ConcurrentBaseConfiguration (com.twitter.distributedlog.config.ConcurrentBaseConfiguration)1 DistributedLogNamespace (com.twitter.distributedlog.namespace.DistributedLogNamespace)1 URI (java.net.URI)1 LedgerHandle (org.apache.bookkeeper.client.LedgerHandle)1 LedgerMetadata (org.apache.bookkeeper.client.LedgerMetadata)1