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();
}
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();
}
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());
}
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);
}
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();
}
Aggregations