Search in sources :

Example 1 with NullStatsLogger

use of org.apache.bookkeeper.stats.NullStatsLogger in project distributedlog by twitter.

the class TestEnvelopedEntry method testLZ4Compression.

@Test(timeout = 20000)
public void testLZ4Compression() throws Exception {
    byte[] data = getString(true).getBytes();
    EnvelopedEntry writeEntry = new EnvelopedEntry(EnvelopedEntry.CURRENT_VERSION, CompressionCodec.Type.LZ4, data, data.length, new NullStatsLogger());
    Buffer outBuf = new Buffer(data.length);
    writeEntry.writeFully(new DataOutputStream(outBuf));
    Assert.assertTrue(data.length > outBuf.size());
    EnvelopedEntry readEntry = new EnvelopedEntry(EnvelopedEntry.CURRENT_VERSION, new NullStatsLogger());
    readEntry.readFully(new DataInputStream(new ByteArrayInputStream(outBuf.getData())));
    byte[] newData = readEntry.getDecompressedPayload();
    Assert.assertEquals("Written data should equal read data", new String(data), new String(newData));
}
Also used : Buffer(com.twitter.distributedlog.io.Buffer) NullStatsLogger(org.apache.bookkeeper.stats.NullStatsLogger) ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) DataInputStream(java.io.DataInputStream) Test(org.junit.Test)

Example 2 with NullStatsLogger

use of org.apache.bookkeeper.stats.NullStatsLogger in project distributedlog by twitter.

the class TestEnvelopedEntry method testEnvelope.

@Test(timeout = 20000)
public void testEnvelope() throws Exception {
    byte[] data = getString(false).getBytes();
    EnvelopedEntry writeEntry = new EnvelopedEntry(EnvelopedEntry.CURRENT_VERSION, CompressionCodec.Type.NONE, data, data.length, new NullStatsLogger());
    Buffer outBuf = new Buffer(2 * data.length);
    writeEntry.writeFully(new DataOutputStream(outBuf));
    EnvelopedEntry readEntry = new EnvelopedEntry(EnvelopedEntry.CURRENT_VERSION, new NullStatsLogger());
    readEntry.readFully(new DataInputStream(new ByteArrayInputStream(outBuf.getData())));
    byte[] newData = readEntry.getDecompressedPayload();
    Assert.assertEquals("Written data should equal read data", new String(data), new String(newData));
}
Also used : Buffer(com.twitter.distributedlog.io.Buffer) NullStatsLogger(org.apache.bookkeeper.stats.NullStatsLogger) ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) DataInputStream(java.io.DataInputStream) Test(org.junit.Test)

Example 3 with NullStatsLogger

use of org.apache.bookkeeper.stats.NullStatsLogger in project distributedlog by twitter.

the class TestAsyncReaderWriter method writeRecordsWithOutstandingWriteLimit.

public void writeRecordsWithOutstandingWriteLimit(int stream, int global, boolean shouldFail) throws Exception {
    DistributedLogConfiguration confLocal = new DistributedLogConfiguration();
    confLocal.addConfiguration(testConf);
    confLocal.setOutputBufferSize(0);
    confLocal.setImmediateFlushEnabled(true);
    confLocal.setPerWriterOutstandingWriteLimit(stream);
    confLocal.setOutstandingWriteLimitDarkmode(false);
    DistributedLogManager dlm;
    if (global > -1) {
        dlm = createNewDLM(confLocal, runtime.getMethodName(), new SimplePermitLimiter(false, global, new NullStatsLogger(), true, new FixedValueFeature("", 0)));
    } else {
        dlm = createNewDLM(confLocal, runtime.getMethodName());
    }
    BKAsyncLogWriter writer = (BKAsyncLogWriter) (dlm.startAsyncLogSegmentNonPartitioned());
    ArrayList<Future<DLSN>> results = new ArrayList<Future<DLSN>>(1000);
    for (int i = 0; i < 1000; i++) {
        results.add(writer.write(DLMTestUtil.getLogRecordInstance(1L)));
    }
    for (Future<DLSN> result : results) {
        try {
            Await.result(result);
            if (shouldFail) {
                fail("should fail due to no outstanding writes permitted");
            }
        } catch (OverCapacityException ex) {
            assertTrue(shouldFail);
        }
    }
    writer.closeAndComplete();
    dlm.close();
}
Also used : FixedValueFeature(org.apache.bookkeeper.feature.FixedValueFeature) ArrayList(java.util.ArrayList) DynamicDistributedLogConfiguration(com.twitter.distributedlog.config.DynamicDistributedLogConfiguration) NullStatsLogger(org.apache.bookkeeper.stats.NullStatsLogger) Future(com.twitter.util.Future) SimplePermitLimiter(com.twitter.distributedlog.util.SimplePermitLimiter) OverCapacityException(com.twitter.distributedlog.exceptions.OverCapacityException)

Example 4 with NullStatsLogger

use of org.apache.bookkeeper.stats.NullStatsLogger in project distributedlog by twitter.

the class TestStatsFilter method testServiceSuccess.

@Test(timeout = 60000)
public void testServiceSuccess() throws Exception {
    StatsLogger stats = new NullStatsLogger();
    StatsFilter<String, String> filter = new StatsFilter<String, String>(stats);
    Future<String> result = filter.apply("", new ConstantService<String, String>(Future.value("result")));
    assertEquals("result", Await.result(result));
}
Also used : NullStatsLogger(org.apache.bookkeeper.stats.NullStatsLogger) StatsLogger(org.apache.bookkeeper.stats.StatsLogger) NullStatsLogger(org.apache.bookkeeper.stats.NullStatsLogger) Test(org.junit.Test)

Example 5 with NullStatsLogger

use of org.apache.bookkeeper.stats.NullStatsLogger in project distributedlog by twitter.

the class TestStatsFilter method testServiceFailure.

@Test(timeout = 60000)
public void testServiceFailure() throws Exception {
    StatsLogger stats = new NullStatsLogger();
    StatsFilter<String, String> filter = new StatsFilter<String, String>(stats);
    try {
        filter.apply("", new RuntimeExService<String, String>());
    } catch (RuntimeException ex) {
    }
}
Also used : NullStatsLogger(org.apache.bookkeeper.stats.NullStatsLogger) StatsLogger(org.apache.bookkeeper.stats.StatsLogger) NullStatsLogger(org.apache.bookkeeper.stats.NullStatsLogger) Test(org.junit.Test)

Aggregations

NullStatsLogger (org.apache.bookkeeper.stats.NullStatsLogger)5 Test (org.junit.Test)4 Buffer (com.twitter.distributedlog.io.Buffer)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 DataInputStream (java.io.DataInputStream)2 DataOutputStream (java.io.DataOutputStream)2 StatsLogger (org.apache.bookkeeper.stats.StatsLogger)2 DynamicDistributedLogConfiguration (com.twitter.distributedlog.config.DynamicDistributedLogConfiguration)1 OverCapacityException (com.twitter.distributedlog.exceptions.OverCapacityException)1 SimplePermitLimiter (com.twitter.distributedlog.util.SimplePermitLimiter)1 Future (com.twitter.util.Future)1 ArrayList (java.util.ArrayList)1 FixedValueFeature (org.apache.bookkeeper.feature.FixedValueFeature)1