Search in sources :

Example 21 with AsyncLogWriter

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;
}
Also used : AsyncLogWriter(org.apache.distributedlog.api.AsyncLogWriter)

Example 22 with AsyncLogWriter

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

Example 23 with AsyncLogWriter

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();
    }
}
Also used : InvalidStreamNameException(org.apache.distributedlog.exceptions.InvalidStreamNameException) DistributedLogManager(org.apache.distributedlog.api.DistributedLogManager) AsyncLogWriter(org.apache.distributedlog.api.AsyncLogWriter) URI(java.net.URI) Namespace(org.apache.distributedlog.api.namespace.Namespace) Test(org.junit.Test)

Example 24 with AsyncLogWriter

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

Example 25 with AsyncLogWriter

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

Aggregations

AsyncLogWriter (org.apache.distributedlog.api.AsyncLogWriter)32 Test (org.junit.Test)23 DistributedLogManager (org.apache.distributedlog.api.DistributedLogManager)20 URI (java.net.URI)6 DLSN (org.apache.distributedlog.DLSN)4 LogRecord (org.apache.distributedlog.LogRecord)4 LogRecordWithDLSN (org.apache.distributedlog.LogRecordWithDLSN)4 Namespace (org.apache.distributedlog.api.namespace.Namespace)4 List (java.util.List)3 DynamicDistributedLogConfiguration (org.apache.distributedlog.config.DynamicDistributedLogConfiguration)3 IOException (java.io.IOException)2 DistributedLogConfiguration (org.apache.distributedlog.DistributedLogConfiguration)2 Entry (org.apache.distributedlog.Entry)2 LogSegmentMetadata (org.apache.distributedlog.LogSegmentMetadata)2 AsyncLogReader (org.apache.distributedlog.api.AsyncLogReader)2 BKNamespaceDriver (org.apache.distributedlog.impl.BKNamespaceDriver)2 RateLimiter (com.google.common.util.concurrent.RateLimiter)1 BufferedOutputStream (java.io.BufferedOutputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 ArrayList (java.util.ArrayList)1