Search in sources :

Example 31 with DistributedLogConfiguration

use of org.apache.distributedlog.DistributedLogConfiguration in project bookkeeper by apache.

the class TestDynamicConfigurationFeatureProvider method testLoadFeaturesFromOverlay.

/**
 * {@link https://issues.apache.org/jira/browse/DL-40}.
 */
@DistributedLogAnnotations.FlakyTest
@Ignore
@Test(timeout = 60000)
public void testLoadFeaturesFromOverlay() throws Exception {
    PropertiesWriter writer = new PropertiesWriter();
    writer.setProperty("feature_1", "10000");
    writer.setProperty("feature_2", "5000");
    writer.save();
    PropertiesWriter overlayWriter = new PropertiesWriter();
    overlayWriter.setProperty("feature_2", "6000");
    overlayWriter.setProperty("feature_4", "6000");
    overlayWriter.save();
    DistributedLogConfiguration conf = new DistributedLogConfiguration().setDynamicConfigReloadIntervalSec(Integer.MAX_VALUE).setFileFeatureProviderBaseConfigPath(writer.getFile().toURI().toURL().getPath()).setFileFeatureProviderOverlayConfigPath(overlayWriter.getFile().toURI().toURL().getPath());
    DynamicConfigurationFeatureProvider provider = new DynamicConfigurationFeatureProvider("", conf, NullStatsLogger.INSTANCE);
    provider.start();
    ensureConfigReloaded();
    Feature feature1 = provider.getFeature("feature_1");
    assertTrue(feature1.isAvailable());
    assertEquals(10000, feature1.availability());
    Feature feature2 = provider.getFeature("feature_2");
    assertTrue(feature2.isAvailable());
    assertEquals(6000, feature2.availability());
    Feature feature3 = provider.getFeature("feature_3");
    assertFalse(feature3.isAvailable());
    assertEquals(0, feature3.availability());
    Feature feature4 = provider.getFeature("feature_4");
    assertTrue(feature4.isAvailable());
    assertEquals(6000, feature4.availability());
    Feature feature5 = provider.getFeature("unknown_feature");
    assertFalse(feature5.isAvailable());
    assertEquals(0, feature5.availability());
    provider.stop();
}
Also used : DistributedLogConfiguration(org.apache.distributedlog.DistributedLogConfiguration) PropertiesWriter(org.apache.distributedlog.common.config.PropertiesWriter) Feature(org.apache.bookkeeper.feature.Feature) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 32 with DistributedLogConfiguration

use of org.apache.distributedlog.DistributedLogConfiguration in project bookkeeper by apache.

the class TestDynamicConfigurationFeatureProvider method testLoadFeaturesFromBase.

@Test(timeout = 60000)
public void testLoadFeaturesFromBase() throws Exception {
    PropertiesWriter writer = new PropertiesWriter();
    writer.setProperty("feature_1", "10000");
    writer.setProperty("feature_2", "5000");
    writer.save();
    DistributedLogConfiguration conf = new DistributedLogConfiguration().setDynamicConfigReloadIntervalSec(Integer.MAX_VALUE).setFileFeatureProviderBaseConfigPath(writer.getFile().toURI().toURL().getPath());
    DynamicConfigurationFeatureProvider provider = new DynamicConfigurationFeatureProvider("", conf, NullStatsLogger.INSTANCE);
    provider.start();
    ensureConfigReloaded();
    Feature feature1 = provider.getFeature("feature_1");
    assertTrue(feature1.isAvailable());
    assertEquals(10000, feature1.availability());
    Feature feature2 = provider.getFeature("feature_2");
    assertTrue(feature2.isAvailable());
    assertEquals(5000, feature2.availability());
    Feature feature3 = provider.getFeature("feature_3");
    assertFalse(feature3.isAvailable());
    assertEquals(0, feature3.availability());
    Feature feature4 = provider.getFeature("unknown_feature");
    assertFalse(feature4.isAvailable());
    assertEquals(0, feature4.availability());
    provider.stop();
}
Also used : DistributedLogConfiguration(org.apache.distributedlog.DistributedLogConfiguration) PropertiesWriter(org.apache.distributedlog.common.config.PropertiesWriter) Feature(org.apache.bookkeeper.feature.Feature) Test(org.junit.Test)

Example 33 with DistributedLogConfiguration

use of org.apache.distributedlog.DistributedLogConfiguration in project bookkeeper by apache.

the class TestZKNamespaceWatcher method testNamespaceListener.

@Test(timeout = 60000)
public void testNamespaceListener() throws Exception {
    URI uri = createDLMURI("/" + runtime.getMethodName());
    zkc.get().create(uri.getPath(), new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    DistributedLogConfiguration conf = new DistributedLogConfiguration();
    conf.addConfiguration(baseConf);
    ZKNamespaceWatcher watcher = new ZKNamespaceWatcher(conf, uri, zkc, scheduler);
    final CountDownLatch[] latches = new CountDownLatch[10];
    for (int i = 0; i < 10; i++) {
        latches[i] = new CountDownLatch(1);
    }
    final AtomicInteger numUpdates = new AtomicInteger(0);
    final AtomicReference<Set<String>> receivedLogs = new AtomicReference<Set<String>>(null);
    watcher.registerListener(new NamespaceListener() {

        @Override
        public void onStreamsChanged(Iterator<String> streams) {
            Set<String> streamSet = Sets.newHashSet(streams);
            int updates = numUpdates.incrementAndGet();
            receivedLogs.set(streamSet);
            latches[updates - 1].countDown();
        }
    });
    // first update
    final Set<String> expectedLogs = Sets.newHashSet();
    latches[0].await();
    validateReceivedLogs(expectedLogs, receivedLogs.get());
    // create test1
    expectedLogs.add("test1");
    createLogInNamespace(uri, "test1");
    latches[1].await();
    validateReceivedLogs(expectedLogs, receivedLogs.get());
    // create invalid log
    createLogInNamespace(uri, ".test1");
    latches[2].await();
    validateReceivedLogs(expectedLogs, receivedLogs.get());
    // create test2
    expectedLogs.add("test2");
    createLogInNamespace(uri, "test2");
    latches[3].await();
    validateReceivedLogs(expectedLogs, receivedLogs.get());
    // delete test1
    expectedLogs.remove("test1");
    deleteLogInNamespace(uri, "test1");
    latches[4].await();
    validateReceivedLogs(expectedLogs, receivedLogs.get());
}
Also used : NamespaceListener(org.apache.distributedlog.callback.NamespaceListener) Set(java.util.Set) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) URI(java.net.URI) DistributedLogConfiguration(org.apache.distributedlog.DistributedLogConfiguration) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Example 34 with DistributedLogConfiguration

use of org.apache.distributedlog.DistributedLogConfiguration in project bookkeeper by apache.

the class TestLedgerAllocatorPool method testNonAvailableAllocator.

@Test(timeout = 60000)
public void testNonAvailableAllocator() throws Exception {
    String allocationPath = "/nonAvailableAllocator";
    DistributedLogConfiguration confLocal = new DistributedLogConfiguration();
    confLocal.addConfiguration(dlConf);
    confLocal.setEnsembleSize(2 * numBookies);
    confLocal.setWriteQuorumSize(2 * numBookies);
    int numAllocators = 3;
    LedgerAllocatorPool pool = new LedgerAllocatorPool(allocationPath, numAllocators, confLocal, zkc, bkc, allocationExecutor);
    for (int i = 0; i < numAllocators; i++) {
        try {
            pool.allocate();
            Utils.ioResult(pool.tryObtain(newTxn(), NULL_LISTENER));
            fail("Should fail to allocate ledger if there are enought bookies");
        } catch (SimpleLedgerAllocator.AllocationException ae) {
            assertEquals(SimpleLedgerAllocator.Phase.ERROR, ae.getPhase());
        }
    }
    for (int i = 0; i < numAllocators; i++) {
        try {
            pool.allocate();
            Utils.ioResult(pool.tryObtain(newTxn(), NULL_LISTENER));
            fail("Should fail to allocate ledger if there aren't available allocators");
        } catch (SimpleLedgerAllocator.AllocationException ae) {
            assertEquals(SimpleLedgerAllocator.Phase.ERROR, ae.getPhase());
        } catch (IOException ioe) {
        // expected
        }
    }
    Utils.close(pool);
}
Also used : DistributedLogConfiguration(org.apache.distributedlog.DistributedLogConfiguration) IOException(java.io.IOException) Test(org.junit.Test)

Example 35 with DistributedLogConfiguration

use of org.apache.distributedlog.DistributedLogConfiguration in project bookkeeper by apache.

the class TestZKLogSegmentMetadataStore method setup.

@Before
public void setup() throws Exception {
    zkc = TestZooKeeperClientBuilder.newBuilder().uri(createDLMURI("/")).sessionTimeoutMs(zkSessionTimeoutMs).build();
    scheduler = OrderedScheduler.newSchedulerBuilder().name("test-zk-logsegment-metadata-store").numThreads(1).build();
    DistributedLogConfiguration conf = new DistributedLogConfiguration();
    conf.addConfiguration(baseConf);
    this.uri = createDLMURI("/" + runtime.getMethodName());
    lsmStore = new ZKLogSegmentMetadataStore(conf, zkc, scheduler);
    zkc.get().create("/" + runtime.getMethodName(), new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    this.rootZkPath = "/" + runtime.getMethodName();
}
Also used : DistributedLogConfiguration(org.apache.distributedlog.DistributedLogConfiguration) Before(org.junit.Before)

Aggregations

DistributedLogConfiguration (org.apache.distributedlog.DistributedLogConfiguration)39 Test (org.junit.Test)25 URI (java.net.URI)10 DistributedLogManager (org.apache.distributedlog.api.DistributedLogManager)10 DLSN (org.apache.distributedlog.DLSN)9 LogRecordWithDLSN (org.apache.distributedlog.LogRecordWithDLSN)8 LogSegmentMetadata (org.apache.distributedlog.LogSegmentMetadata)8 Entry (org.apache.distributedlog.Entry)7 IOException (java.io.IOException)6 ZooKeeperClient (org.apache.distributedlog.ZooKeeperClient)5 Before (org.junit.Before)4 List (java.util.List)3 Feature (org.apache.bookkeeper.feature.Feature)3 Namespace (org.apache.distributedlog.api.namespace.Namespace)3 KeeperException (org.apache.zookeeper.KeeperException)3 Set (java.util.Set)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 AsyncLogWriter (org.apache.distributedlog.api.AsyncLogWriter)2