Search in sources :

Example 6 with LogRecordTooLongException

use of org.apache.distributedlog.exceptions.LogRecordTooLongException 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();
}
Also used : AsyncLogWriter(org.apache.distributedlog.api.AsyncLogWriter) LogRecordTooLongException(org.apache.distributedlog.exceptions.LogRecordTooLongException) Test(org.junit.Test)

Aggregations

LogRecordTooLongException (org.apache.distributedlog.exceptions.LogRecordTooLongException)6 ByteBuf (io.netty.buffer.ByteBuf)4 Test (org.junit.Test)4 ByteBuffer (java.nio.ByteBuffer)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 Writer (org.apache.distributedlog.Entry.Writer)2 Reader (org.apache.distributedlog.LogRecordSet.Reader)2 Writer (org.apache.distributedlog.LogRecordSet.Writer)2 IOException (java.io.IOException)1 Reader (org.apache.distributedlog.Entry.Reader)1 AsyncLogWriter (org.apache.distributedlog.api.AsyncLogWriter)1 WriteException (org.apache.distributedlog.exceptions.WriteException)1