use of org.apache.distributedlog.api.AsyncLogWriter in project bookkeeper by apache.
the class DLMTestUtil method generateLogSegmentNonPartitioned.
public static long generateLogSegmentNonPartitioned(DistributedLogManager dlm, int controlEntries, int userEntries, long startTxid, long txidStep) throws Exception {
AsyncLogWriter out = dlm.startAsyncLogSegmentNonPartitioned();
long txid = startTxid;
for (int i = 0; i < controlEntries; ++i) {
LogRecord record = DLMTestUtil.getLargeLogRecordInstance(txid);
record.setControl();
Utils.ioResult(out.write(record));
txid += txidStep;
}
for (int i = 0; i < userEntries; ++i) {
LogRecord record = DLMTestUtil.getLargeLogRecordInstance(txid);
Utils.ioResult(out.write(record));
txid += txidStep;
}
Utils.close(out);
return txid - startTxid;
}
use of org.apache.distributedlog.api.AsyncLogWriter in project bookkeeper by apache.
the class TestBKDistributedLogManager method testMaxLogRecSize.
@Test(timeout = 60000, expected = LogRecordTooLongException.class)
public void testMaxLogRecSize() throws Exception {
DistributedLogManager dlm = createNewDLM(conf, "distrlog-maxlogRecSize");
AsyncLogWriter writer = Utils.ioResult(dlm.openAsyncLogWriter());
Utils.ioResult(writer.write(new LogRecord(1L, DLMTestUtil.repeatString(DLMTestUtil.repeatString("abcdefgh", 256), 512).getBytes())));
}
use of org.apache.distributedlog.api.AsyncLogWriter in project bookkeeper by apache.
the class TestBKDistributedLogManager method testInvalidStreamFromInvalidZkPath.
@Test(timeout = 60000)
public void testInvalidStreamFromInvalidZkPath() throws Exception {
String baseName = testNames.getMethodName();
String streamName = "\0blah";
URI uri = createDLMURI("/" + baseName);
Namespace namespace = NamespaceBuilder.newBuilder().conf(conf).uri(uri).build();
DistributedLogManager dlm = null;
AsyncLogWriter writer = null;
try {
dlm = namespace.openLog(streamName);
writer = dlm.startAsyncLogSegmentNonPartitioned();
fail("should have thrown");
} catch (InvalidStreamNameException e) {
} finally {
if (null != writer) {
Utils.close(writer);
}
if (null != dlm) {
dlm.close();
}
namespace.close();
}
}
use of org.apache.distributedlog.api.AsyncLogWriter in project bookkeeper by apache.
the class TestBKDistributedLogManager method testTwoWritersOnLockDisabled.
@Test(timeout = 60000)
public void testTwoWritersOnLockDisabled() throws Exception {
DistributedLogConfiguration confLocal = new DistributedLogConfiguration();
confLocal.addConfiguration(conf);
confLocal.setOutputBufferSize(0);
confLocal.setWriteLockEnabled(false);
String name = "distrlog-two-writers-lock-disabled";
DistributedLogManager manager = createNewDLM(confLocal, name);
AsyncLogWriter writer1 = Utils.ioResult(manager.openAsyncLogWriter());
Utils.ioResult(writer1.write(DLMTestUtil.getLogRecordInstance(1L)));
AsyncLogWriter writer2 = Utils.ioResult(manager.openAsyncLogWriter());
Utils.ioResult(writer2.write(DLMTestUtil.getLogRecordInstance(2L)));
// write a record to writer 1 again
try {
Utils.ioResult(writer1.write(DLMTestUtil.getLogRecordInstance(3L)));
fail("Should fail writing record to writer 1 again as writer 2 took over the ownership");
} catch (BKTransmitException bkte) {
assertEquals(BKException.Code.LedgerFencedException, bkte.getBKResultCode());
}
}
use of org.apache.distributedlog.api.AsyncLogWriter in project bookkeeper by apache.
the class TestBKDistributedLogManager method testMaxTransmissionSize.
@Test(timeout = 60000)
public void testMaxTransmissionSize() throws Exception {
DistributedLogConfiguration confLocal = new DistributedLogConfiguration();
confLocal.loadConf(conf);
confLocal.setOutputBufferSize(1024 * 1024);
BKDistributedLogManager dlm = createNewDLM(confLocal, "distrlog-transmissionSize");
AsyncLogWriter out = Utils.ioResult(dlm.openAsyncLogWriter());
boolean exceptionEncountered = false;
byte[] largePayload = new byte[(LogRecord.MAX_LOGRECORDSET_SIZE / 2) + 2];
RAND.nextBytes(largePayload);
try {
LogRecord op = new LogRecord(1L, largePayload);
CompletableFuture<DLSN> firstWriteFuture = out.write(op);
op = new LogRecord(2L, largePayload);
// the second write will flush the first one, since we reached the maximum transmission size.
out.write(op);
Utils.ioResult(firstWriteFuture);
} catch (LogRecordTooLongException exc) {
exceptionEncountered = true;
} finally {
Utils.ioResult(out.asyncClose());
}
assertFalse(exceptionEncountered);
Abortables.abortQuietly(out);
dlm.close();
}
Aggregations