@Override public Void handle(ZooKeeperClient zkc) throws IOException { for (String s : streamNames) { try { BKDistributedLogManager.createLog(conf, zkc, uri, s); } catch (InterruptedException e) { LOG.error("Interrupted on creating unpartitioned stream {} : ", s, e); return null; } } return null; } }, conf, uri);
.build(); BKDistributedLogManager.createLog(conf, zkClient, ((BKDistributedLogManager) dlm).uri, name); dlm.registerListener(new LogSegmentListener() { @Override
@Test(timeout = 60000) public void testWriterStartsAtTxidZeroForEmptyStream() throws Exception { String name = testNames.getMethodName(); DistributedLogConfiguration conf = new DistributedLogConfiguration(); conf.setImmediateFlushEnabled(true); conf.setOutputBufferSize(1024); BKDistributedLogManager dlm = (BKDistributedLogManager) createNewDLM(conf, name); URI uri = createDLMURI("/" + name); BKDistributedLogManager.createLog(conf, dlm.getReaderZKC(), uri, name); // Log exists but is empty, better not throw. AppendOnlyStreamWriter writer = dlm.getAppendOnlyStreamWriter(); byte[] byteStream = DLMTestUtil.repeatString("a", 1025).getBytes(); Await.result(writer.write(byteStream)); writer.close(); dlm.close(); }
BKDistributedLogManager.createLog(conf, dlm.getReaderZKC(), uri, name);
@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"; DistributedLogNamespace namespace = DistributedLogNamespaceBuilder.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 BKDistributedLogManager.createLog(conf, zooKeeperClient, uri, streamName); DistributedLogManager newDLM = namespace.openLog(streamName); LogWriter newWriter = newDLM.startLogSegmentNonPartitioned(); newWriter.write(DLMTestUtil.getLogRecordInstance(1L)); newWriter.close(); newDLM.close(); }