use of com.twitter.distributedlog.DistributedLogConfiguration in project distributedlog by twitter.
the class TestZkMetadataResolver method testFirstLogSegmentSequenceNumber.
@Test(timeout = 60000)
public void testFirstLogSegmentSequenceNumber() throws Exception {
DistributedLogConfiguration dlConf = new DistributedLogConfiguration();
URI uri = createURI("/messaging/distributedlog-testfirstledgerseqno/dl1");
DLMetadata meta1 = DLMetadata.create(new BKDLConfig("127.0.0.1:7000", "ledgers"));
meta1.create(uri);
BKDLConfig read1 = BKDLConfig.resolveDLConfig(zkc, uri);
BKDLConfig.propagateConfiguration(read1, dlConf);
assertEquals(DistributedLogConstants.FIRST_LOGSEGMENT_SEQNO, dlConf.getFirstLogSegmentSequenceNumber());
BKDLConfig.clearCachedDLConfigs();
DLMetadata meta2 = DLMetadata.create(new BKDLConfig("127.0.0.1:7000", "ledgers").setFirstLogSegmentSeqNo(9999L));
meta2.update(uri);
BKDLConfig read2 = BKDLConfig.resolveDLConfig(zkc, uri);
BKDLConfig.propagateConfiguration(read2, dlConf);
assertEquals(9999L, dlConf.getFirstLogSegmentSequenceNumber());
BKDLConfig.clearCachedDLConfigs();
DLMetadata meta3 = DLMetadata.create(new BKDLConfig("127.0.0.1:7000", "ledgers").setFirstLogSegmentSeqNo(99L));
meta3.update(uri);
BKDLConfig read3 = BKDLConfig.resolveDLConfig(zkc, uri);
BKDLConfig.propagateConfiguration(read3, dlConf);
assertEquals(99L, dlConf.getFirstLogSegmentSequenceNumber());
BKDLConfig.clearCachedDLConfigs();
}
use of com.twitter.distributedlog.DistributedLogConfiguration in project distributedlog by twitter.
the class TestZkMetadataResolver method testFederatedNamespace.
@Test(timeout = 60000)
public void testFederatedNamespace() throws Exception {
DistributedLogConfiguration dlConf = new DistributedLogConfiguration();
URI uri = createURI("/messaging/distributedlog-testfederatednamespace/dl1");
DLMetadata meta1 = DLMetadata.create(new BKDLConfig("127.0.0.1:7000", "ledgers"));
meta1.create(uri);
BKDLConfig read1 = BKDLConfig.resolveDLConfig(zkc, uri);
BKDLConfig.propagateConfiguration(read1, dlConf);
assertTrue(dlConf.getCreateStreamIfNotExists());
BKDLConfig.clearCachedDLConfigs();
DLMetadata meta2 = DLMetadata.create(new BKDLConfig("127.0.0.1:7000", "ledgers").setFederatedNamespace(true));
meta2.update(uri);
BKDLConfig read2 = BKDLConfig.resolveDLConfig(zkc, uri);
BKDLConfig.propagateConfiguration(read2, dlConf);
assertFalse(dlConf.getCreateStreamIfNotExists());
BKDLConfig.clearCachedDLConfigs();
DLMetadata meta3 = DLMetadata.create(new BKDLConfig("127.0.0.1:7000", "ledgers").setFederatedNamespace(false));
meta3.update(uri);
BKDLConfig read3 = BKDLConfig.resolveDLConfig(zkc, uri);
BKDLConfig.propagateConfiguration(read3, dlConf);
// if it is non-federated namespace, it won't change the create stream behavior.
assertFalse(dlConf.getCreateStreamIfNotExists());
BKDLConfig.clearCachedDLConfigs();
}
use of com.twitter.distributedlog.DistributedLogConfiguration in project distributedlog by twitter.
the class TestZkMetadataResolver method testEncodeRegionID.
@Test(timeout = 60000)
public void testEncodeRegionID() throws Exception {
DistributedLogConfiguration dlConf = new DistributedLogConfiguration();
URI uri = createURI("/messaging/distributedlog-testencoderegionid/dl1");
DLMetadata meta1 = DLMetadata.create(new BKDLConfig("127.0.0.1:7000", "ledgers"));
meta1.create(uri);
BKDLConfig read1 = BKDLConfig.resolveDLConfig(zkc, uri);
BKDLConfig.propagateConfiguration(read1, dlConf);
assertFalse(dlConf.getEncodeRegionIDInLogSegmentMetadata());
BKDLConfig.clearCachedDLConfigs();
DLMetadata meta2 = DLMetadata.create(new BKDLConfig("127.0.0.1:7000", "ledgers").setEncodeRegionID(true));
meta2.update(uri);
BKDLConfig read2 = BKDLConfig.resolveDLConfig(zkc, uri);
BKDLConfig.propagateConfiguration(read2, dlConf);
assertTrue(dlConf.getEncodeRegionIDInLogSegmentMetadata());
BKDLConfig.clearCachedDLConfigs();
DLMetadata meta3 = DLMetadata.create(new BKDLConfig("127.0.0.1:7000", "ledgers").setEncodeRegionID(false));
meta3.update(uri);
BKDLConfig read3 = BKDLConfig.resolveDLConfig(zkc, uri);
BKDLConfig.propagateConfiguration(read3, dlConf);
assertFalse(dlConf.getEncodeRegionIDInLogSegmentMetadata());
BKDLConfig.clearCachedDLConfigs();
}
use of com.twitter.distributedlog.DistributedLogConfiguration in project distributedlog by twitter.
the class DistributedLogServerApp method runCmd.
private void runCmd(CommandLine cmdline) throws IllegalArgumentException, IOException, ConfigurationException {
final StatsReceiver statsReceiver = NullStatsReceiver.get();
Optional<String> confOptional = getOptionalStringArg(cmdline, "c");
DistributedLogConfiguration dlConf = new DistributedLogConfiguration();
if (confOptional.isPresent()) {
String configFile = confOptional.get();
try {
dlConf.loadConf(new File(configFile).toURI().toURL());
} catch (ConfigurationException e) {
throw new IllegalArgumentException("Failed to load distributedlog configuration from " + configFile + ".");
} catch (MalformedURLException e) {
throw new IllegalArgumentException("Failed to load distributedlog configuration from malformed " + configFile + ".");
}
}
// load the stats provider
final StatsProvider statsProvider = getOptionalStringArg(cmdline, "pd").transform(new Function<String, StatsProvider>() {
@Nullable
@Override
public StatsProvider apply(@Nullable String name) {
return ReflectionUtils.newInstance(name, StatsProvider.class);
}
}).or(new NullStatsProvider());
final DistributedLogServer server = DistributedLogServer.runServer(getOptionalStringArg(cmdline, "u"), confOptional, getOptionalStringArg(cmdline, "sc"), getOptionalIntegerArg(cmdline, "p"), getOptionalIntegerArg(cmdline, "sp"), getOptionalIntegerArg(cmdline, "si"), getOptionalBooleanArg(cmdline, "a"), getOptionalBooleanArg(cmdline, "mx"), statsReceiver, statsProvider);
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
logger.info("Closing DistributedLog Server.");
server.close();
logger.info("Closed DistributedLog Server.");
statsProvider.stop();
}
});
try {
server.join();
} catch (InterruptedException e) {
logger.warn("Interrupted when waiting distributedlog server to be finished : ", e);
}
logger.info("DistributedLog Service Interrupted.");
server.close();
logger.info("Closed DistributedLog Server.");
statsProvider.stop();
}
use of com.twitter.distributedlog.DistributedLogConfiguration in project distributedlog by twitter.
the class StreamBenchmark method parseCommandLine.
protected void parseCommandLine(String[] args) throws Exception {
BasicParser parser = new BasicParser();
CommandLine cmdline = parser.parse(options, args);
if (cmdline.hasOption("h")) {
printUsage();
System.exit(0);
}
if (cmdline.hasOption("u")) {
this.uri = URI.create(cmdline.getOptionValue("u"));
} else {
printUsage();
System.exit(0);
}
this.conf = new DistributedLogConfiguration();
if (cmdline.hasOption("c")) {
String configFile = cmdline.getOptionValue("c");
this.conf.loadConf(new File(configFile).toURI().toURL());
}
if (cmdline.hasOption("p")) {
statsProvider = ReflectionUtils.newInstance(cmdline.getOptionValue("p"), StatsProvider.class);
} else {
statsProvider = new NullStatsProvider();
}
if (cmdline.hasOption("s")) {
this.streamName = cmdline.getOptionValue("s");
} else {
printUsage();
System.exit(0);
}
parseCommandLine(cmdline);
}
Aggregations