Search in sources :

Example 1 with WriteContext

use of com.twitter.distributedlog.thrift.service.WriteContext in project distributedlog by twitter.

the class TestDistributedLogServer method testBulkWriteTotalFailureLostLock.

@Test(timeout = 60000)
public void testBulkWriteTotalFailureLostLock() throws Exception {
    String name = String.format("dlserver-bulk-write-%s", "lost-lock");
    dlClient.routingService.addHost(name, dlServer.getAddress());
    final int writeCount = 8;
    List<ByteBuffer> writes = new ArrayList<ByteBuffer>(writeCount + 1);
    ByteBuffer buf = ByteBuffer.allocate(8);
    writes.add(buf);
    for (long i = 1; i <= writeCount; i++) {
        writes.add(ByteBuffer.wrap(("" + i).getBytes()));
    }
    // Warm it up with a write.
    Await.result(dlClient.dlClient.write(name, ByteBuffer.allocate(8)));
    // Failpoint a lost lock, make sure the failure gets promoted to an operation failure.
    DistributedLogServiceImpl svcImpl = (DistributedLogServiceImpl) dlServer.dlServer.getLeft();
    try {
        FailpointUtils.setFailpoint(FailpointUtils.FailPointName.FP_WriteInternalLostLock, FailpointUtils.FailPointActions.FailPointAction_Default);
        Future<BulkWriteResponse> futures = svcImpl.writeBulkWithContext(name, writes, new WriteContext());
        assertEquals(StatusCode.LOCKING_EXCEPTION, Await.result(futures).header.code);
    } finally {
        FailpointUtils.removeFailpoint(FailpointUtils.FailPointName.FP_WriteInternalLostLock);
    }
}
Also used : ArrayList(java.util.ArrayList) BulkWriteResponse(com.twitter.distributedlog.thrift.service.BulkWriteResponse) ByteBuffer(java.nio.ByteBuffer) WriteContext(com.twitter.distributedlog.thrift.service.WriteContext) Test(org.junit.Test)

Example 2 with WriteContext

use of com.twitter.distributedlog.thrift.service.WriteContext in project distributedlog by twitter.

the class TestDistributedLogService method testTruncateOpNoChecksum.

@Test(timeout = 60000)
public void testTruncateOpNoChecksum() throws Exception {
    DistributedLogServiceImpl localService = createConfiguredLocalService();
    WriteContext ctx = new WriteContext();
    Future<WriteResponse> result = localService.truncate("test", new DLSN(1, 2, 3).serialize(), ctx);
    WriteResponse resp = Await.result(result);
    assertEquals(StatusCode.SUCCESS, resp.getHeader().getCode());
    localService.shutdown();
}
Also used : DLSN(com.twitter.distributedlog.DLSN) WriteResponse(com.twitter.distributedlog.thrift.service.WriteResponse) WriteContext(com.twitter.distributedlog.thrift.service.WriteContext) Test(org.junit.Test)

Example 3 with WriteContext

use of com.twitter.distributedlog.thrift.service.WriteContext in project distributedlog by twitter.

the class TestDistributedLogService method testWriteOpChecksumBadData.

@Test(timeout = 60000)
public void testWriteOpChecksumBadData() throws Exception {
    DistributedLogServiceImpl localService = createConfiguredLocalService();
    ByteBuffer buffer = getTestDataBuffer();
    WriteContext ctx = new WriteContext().setCrc32(ProtocolUtils.writeOpCRC32("test", buffer.array()));
    // Overwrite 1 byte to corrupt data.
    buffer.put(1, (byte) 0xab);
    Future<WriteResponse> result = localService.writeWithContext("test", buffer, ctx);
    WriteResponse resp = Await.result(result);
    assertEquals(StatusCode.CHECKSUM_FAILED, resp.getHeader().getCode());
    localService.shutdown();
}
Also used : WriteResponse(com.twitter.distributedlog.thrift.service.WriteResponse) ByteBuffer(java.nio.ByteBuffer) WriteContext(com.twitter.distributedlog.thrift.service.WriteContext) Test(org.junit.Test)

Example 4 with WriteContext

use of com.twitter.distributedlog.thrift.service.WriteContext in project distributedlog by twitter.

the class TestDistributedLogService method testStreamOpChecksumBadChecksum.

@Test(timeout = 60000)
public void testStreamOpChecksumBadChecksum() throws Exception {
    DistributedLogServiceImpl localService = createConfiguredLocalService();
    WriteContext ctx = new WriteContext().setCrc32(999);
    Future<WriteResponse> result = localService.heartbeat("test", ctx);
    WriteResponse resp = Await.result(result);
    assertEquals(StatusCode.CHECKSUM_FAILED, resp.getHeader().getCode());
    result = localService.release("test", ctx);
    resp = Await.result(result);
    assertEquals(StatusCode.CHECKSUM_FAILED, resp.getHeader().getCode());
    result = localService.delete("test", ctx);
    resp = Await.result(result);
    assertEquals(StatusCode.CHECKSUM_FAILED, resp.getHeader().getCode());
    localService.shutdown();
}
Also used : WriteResponse(com.twitter.distributedlog.thrift.service.WriteResponse) WriteContext(com.twitter.distributedlog.thrift.service.WriteContext) Test(org.junit.Test)

Example 5 with WriteContext

use of com.twitter.distributedlog.thrift.service.WriteContext in project distributedlog by twitter.

the class TestDistributedLogService method testCloseStreamsShouldFlush.

@Test(timeout = 60000)
public void testCloseStreamsShouldFlush() throws Exception {
    DistributedLogConfiguration confLocal = newLocalConf();
    confLocal.setOutputBufferSize(Integer.MAX_VALUE).setImmediateFlushEnabled(false).setPeriodicFlushFrequencyMilliSeconds(0);
    String streamNamePrefix = testName.getMethodName();
    DistributedLogServiceImpl localService = createService(serverConf, confLocal);
    StreamManagerImpl streamManager = (StreamManagerImpl) localService.getStreamManager();
    int numStreams = 10;
    int numWrites = 10;
    List<Future<WriteResponse>> futureList = Lists.newArrayListWithExpectedSize(numStreams * numWrites);
    for (int i = 0; i < numStreams; i++) {
        String streamName = streamNamePrefix + "-" + i;
        HeartbeatOptions hbOptions = new HeartbeatOptions();
        hbOptions.setSendHeartBeatToReader(true);
        // make sure the first log segment of each stream created
        FutureUtils.result(localService.heartbeatWithOptions(streamName, new WriteContext(), hbOptions));
        for (int j = 0; j < numWrites; j++) {
            futureList.add(localService.write(streamName, createRecord(i * numWrites + j)));
        }
    }
    assertEquals("There should be " + numStreams + " streams in cache", numStreams, streamManager.getCachedStreams().size());
    while (streamManager.getAcquiredStreams().size() < numStreams) {
        TimeUnit.MILLISECONDS.sleep(20);
    }
    Future<List<Void>> closeResult = localService.closeStreams();
    List<Void> closedStreams = Await.result(closeResult);
    assertEquals("There should be " + numStreams + " streams closed", numStreams, closedStreams.size());
    // all writes should be flushed
    for (Future<WriteResponse> future : futureList) {
        WriteResponse response = Await.result(future);
        assertTrue("Op should succeed or be rejected : " + response.getHeader().getCode(), StatusCode.SUCCESS == response.getHeader().getCode() || StatusCode.WRITE_EXCEPTION == response.getHeader().getCode() || StatusCode.STREAM_UNAVAILABLE == response.getHeader().getCode());
    }
    assertTrue("There should be no streams in the cache", streamManager.getCachedStreams().isEmpty());
    assertTrue("There should be no streams in the acquired cache", streamManager.getAcquiredStreams().isEmpty());
    localService.shutdown();
}
Also used : WriteResponse(com.twitter.distributedlog.thrift.service.WriteResponse) StreamManagerImpl(com.twitter.distributedlog.service.stream.StreamManagerImpl) WriteContext(com.twitter.distributedlog.thrift.service.WriteContext) DistributedLogConfiguration(com.twitter.distributedlog.DistributedLogConfiguration) HeartbeatOptions(com.twitter.distributedlog.thrift.service.HeartbeatOptions) Future(com.twitter.util.Future) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Aggregations

WriteContext (com.twitter.distributedlog.thrift.service.WriteContext)11 Test (org.junit.Test)11 WriteResponse (com.twitter.distributedlog.thrift.service.WriteResponse)10 ArrayList (java.util.ArrayList)3 DLSN (com.twitter.distributedlog.DLSN)2 DistributedLogConfiguration (com.twitter.distributedlog.DistributedLogConfiguration)2 StreamManagerImpl (com.twitter.distributedlog.service.stream.StreamManagerImpl)2 HeartbeatOptions (com.twitter.distributedlog.thrift.service.HeartbeatOptions)2 Future (com.twitter.util.Future)2 ByteBuffer (java.nio.ByteBuffer)2 List (java.util.List)2 Stream (com.twitter.distributedlog.service.stream.Stream)1 StreamImpl (com.twitter.distributedlog.service.stream.StreamImpl)1 BulkWriteResponse (com.twitter.distributedlog.thrift.service.BulkWriteResponse)1