use of org.apache.distributedlog.api.LogWriter in project bookkeeper by apache.
the class TestBKDistributedLogNamespace method initDlogMeta.
private void initDlogMeta(String dlNamespace, String un, String streamName) throws Exception {
URI uri = createDLMURI(dlNamespace);
DistributedLogConfiguration newConf = new DistributedLogConfiguration();
newConf.addConfiguration(conf);
newConf.setCreateStreamIfNotExists(true);
newConf.setZkAclId(un);
Namespace namespace = NamespaceBuilder.newBuilder().conf(newConf).uri(uri).build();
DistributedLogManager dlm = namespace.openLog(streamName);
LogWriter writer = dlm.startLogSegmentNonPartitioned();
for (int i = 0; i < 10; i++) {
writer.write(DLMTestUtil.getLogRecordInstance(1L));
}
writer.close();
dlm.close();
namespace.close();
}
use of org.apache.distributedlog.api.LogWriter in project bookkeeper by apache.
the class TestBKDistributedLogNamespace method testCreateIfNotExists.
@Test(timeout = 60000)
public void testCreateIfNotExists() throws Exception {
URI uri = createDLMURI("/" + runtime.getMethodName());
ensureURICreated(zooKeeperClient.get(), uri);
DistributedLogConfiguration newConf = new DistributedLogConfiguration();
newConf.addConfiguration(conf);
newConf.setCreateStreamIfNotExists(false);
String streamName = "test-stream";
Namespace namespace = NamespaceBuilder.newBuilder().conf(newConf).uri(uri).build();
DistributedLogManager dlm = namespace.openLog(streamName);
LogWriter writer;
try {
writer = dlm.startLogSegmentNonPartitioned();
writer.write(DLMTestUtil.getLogRecordInstance(1L));
fail("Should fail to write data if stream doesn't exist.");
} catch (IOException ioe) {
// expected
}
dlm.close();
// create the stream
namespace.createLog(streamName);
DistributedLogManager newDLM = namespace.openLog(streamName);
LogWriter newWriter = newDLM.startLogSegmentNonPartitioned();
newWriter.write(DLMTestUtil.getLogRecordInstance(1L));
newWriter.close();
newDLM.close();
}
use of org.apache.distributedlog.api.LogWriter in project bookkeeper by apache.
the class TestBKDistributedLogNamespace method createLogPathTest.
private void createLogPathTest(String logName) throws Exception {
URI uri = createDLMURI("/" + runtime.getMethodName());
ensureURICreated(zooKeeperClient.get(), uri);
DistributedLogConfiguration newConf = new DistributedLogConfiguration();
newConf.addConfiguration(conf);
newConf.setCreateStreamIfNotExists(false);
Namespace namespace = NamespaceBuilder.newBuilder().conf(newConf).uri(uri).build();
DistributedLogManager dlm = namespace.openLog(logName);
LogWriter writer;
try {
writer = dlm.startLogSegmentNonPartitioned();
writer.write(DLMTestUtil.getLogRecordInstance(1L));
writer.commit();
fail("Should fail to write data if stream doesn't exist.");
} catch (IOException ioe) {
// expected
}
dlm.close();
}
use of org.apache.distributedlog.api.LogWriter in project bookkeeper by apache.
the class TestBKDistributedLogManager method testCheckLogExists.
@Test(timeout = 60000)
public void testCheckLogExists() throws Exception {
String name = "distrlog-check-log-exists";
DistributedLogManager dlm = createNewDLM(conf, name);
long txid = 1;
LogWriter writer = dlm.startLogSegmentNonPartitioned();
for (long j = 1; j <= DEFAULT_SEGMENT_SIZE / 2; j++) {
writer.write(DLMTestUtil.getLogRecordInstance(txid++));
}
writer.flush();
writer.commit();
writer.close();
dlm.close();
URI uri = createDLMURI("/" + name);
Namespace namespace = NamespaceBuilder.newBuilder().conf(conf).uri(uri).build();
assertTrue(namespace.logExists(name));
assertFalse(namespace.logExists("non-existent-log"));
URI nonExistentUri = createDLMURI("/" + "non-existent-ns");
Namespace nonExistentNS = NamespaceBuilder.newBuilder().conf(conf).uri(nonExistentUri).build();
assertFalse(nonExistentNS.logExists(name));
int logCount = 0;
Iterator<String> logIter = namespace.getLogs();
while (logIter.hasNext()) {
String log = logIter.next();
logCount++;
assertEquals(name, log);
}
assertEquals(1, logCount);
namespace.close();
}
Aggregations