Search in sources :

Example 1 with ConcurrentBaseConfiguration

use of com.twitter.distributedlog.config.ConcurrentBaseConfiguration 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 ConcurrentBaseConfiguration

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

the class TestConfigurationFeatureProvider method testConfigurationFeatureProvider.

@Test(timeout = 60000)
public void testConfigurationFeatureProvider() throws Exception {
    String rootScope = "dl";
    ConcurrentBaseConfiguration featureConf = new ConcurrentBaseConfiguration();
    ConcurrentMap<String, SettableFeature> features = new ConcurrentHashMap<String, SettableFeature>();
    ConfigurationFeatureProvider featureProvider = new ConfigurationFeatureProvider(rootScope, featureConf, features);
    String featureName1 = "feature1";
    String fullFeatureName1 = rootScope + "." + featureName1;
    int availability1 = 1234;
    featureConf.setProperty(fullFeatureName1, availability1);
    Feature feature1 = featureProvider.getFeature(featureName1);
    assertEquals(availability1, feature1.availability());
    assertTrue(features.containsKey(fullFeatureName1));
    assertTrue(feature1 == features.get(fullFeatureName1));
    String subScope = "subscope";
    String featureName2 = "feature2";
    String fullFeatureName2 = rootScope + "." + subScope + "." + featureName2;
    int availability2 = 4321;
    featureConf.setProperty(fullFeatureName2, availability2);
    Feature feature2 = featureProvider.scope(subScope).getFeature(featureName2);
    assertEquals(availability2, feature2.availability());
    assertTrue(features.containsKey(fullFeatureName2));
    assertTrue(feature2 == features.get(fullFeatureName2));
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SettableFeature(org.apache.bookkeeper.feature.SettableFeature) SettableFeature(org.apache.bookkeeper.feature.SettableFeature) Feature(org.apache.bookkeeper.feature.Feature) ConcurrentBaseConfiguration(com.twitter.distributedlog.config.ConcurrentBaseConfiguration) Test(org.junit.Test)

Aggregations

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