Search in sources :

Example 16 with WriteResponse

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

the class TestDistributedLogService method testAcquireStreamsWhenExceedMaxAcquiredPartitions.

@Test(timeout = 60000)
public void testAcquireStreamsWhenExceedMaxAcquiredPartitions() throws Exception {
    String streamName = testName.getMethodName() + "_0000";
    DistributedLogConfiguration confLocal = new DistributedLogConfiguration();
    confLocal.addConfiguration(dlConf);
    confLocal.setMaxCachedPartitionsPerProxy(-1);
    confLocal.setMaxAcquiredPartitionsPerProxy(1);
    ServerConfiguration serverConfLocal = new ServerConfiguration();
    serverConfLocal.addConfiguration(serverConf);
    serverConfLocal.setStreamPartitionConverterClass(DelimiterStreamPartitionConverter.class);
    DistributedLogServiceImpl serviceLocal = createService(serverConfLocal, confLocal);
    Stream stream = serviceLocal.getLogWriter(streamName);
    // stream is cached
    assertNotNull(stream);
    assertEquals(1, serviceLocal.getStreamManager().numCached());
    // create write ops
    WriteOp op0 = createWriteOp(service, streamName, 0L);
    stream.submit(op0);
    WriteResponse wr0 = Await.result(op0.result());
    assertEquals("Op 0 should succeed", StatusCode.SUCCESS, wr0.getHeader().getCode());
    assertEquals(1, serviceLocal.getStreamManager().numAcquired());
    // should be able to cache partitions from same stream
    String anotherStreamName = testName.getMethodName() + "_0001";
    Stream anotherStream = serviceLocal.getLogWriter(anotherStreamName);
    assertNotNull(anotherStream);
    assertEquals(2, serviceLocal.getStreamManager().numCached());
    // create write ops
    WriteOp op1 = createWriteOp(service, anotherStreamName, 0L);
    anotherStream.submit(op1);
    WriteResponse wr1 = Await.result(op1.result());
    assertEquals("Op 1 should fail", StatusCode.STREAM_UNAVAILABLE, wr1.getHeader().getCode());
    assertEquals(1, serviceLocal.getStreamManager().numAcquired());
}
Also used : DistributedLogConfiguration(com.twitter.distributedlog.DistributedLogConfiguration) WriteOp(com.twitter.distributedlog.service.stream.WriteOp) ServerConfiguration(com.twitter.distributedlog.service.config.ServerConfiguration) WriteResponse(com.twitter.distributedlog.thrift.service.WriteResponse) Stream(com.twitter.distributedlog.service.stream.Stream) Test(org.junit.Test)

Example 17 with WriteResponse

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

the class TestDistributedLogService method testCloseShouldErrorOutPendingOps.

@Test(timeout = 60000)
public void testCloseShouldErrorOutPendingOps() throws Exception {
    String streamName = testName.getMethodName();
    StreamImpl s = createUnstartedStream(service, streamName);
    int numWrites = 10;
    List<Future<WriteResponse>> futureList = new ArrayList<Future<WriteResponse>>(numWrites);
    for (int i = 0; i < numWrites; i++) {
        WriteOp op = createWriteOp(service, streamName, i);
        s.submit(op);
        futureList.add(op.result());
    }
    assertEquals(numWrites, s.numPendingOps());
    Await.result(s.requestClose("close stream"));
    assertEquals("Stream " + streamName + " is set to " + StreamStatus.CLOSED, StreamStatus.CLOSED, s.getStatus());
    for (int i = 0; i < numWrites; i++) {
        Future<WriteResponse> future = futureList.get(i);
        WriteResponse wr = Await.result(future);
        assertEquals("Pending op should fail with " + StatusCode.STREAM_UNAVAILABLE, StatusCode.STREAM_UNAVAILABLE, wr.getHeader().getCode());
    }
}
Also used : WriteOp(com.twitter.distributedlog.service.stream.WriteOp) StreamImpl(com.twitter.distributedlog.service.stream.StreamImpl) ArrayList(java.util.ArrayList) WriteResponse(com.twitter.distributedlog.thrift.service.WriteResponse) Future(com.twitter.util.Future) Test(org.junit.Test)

Example 18 with WriteResponse

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

the class TestDistributedLogService method testWriteOpChecksumBadChecksum.

@Test(timeout = 60000)
public void testWriteOpChecksumBadChecksum() throws Exception {
    DistributedLogServiceImpl localService = createConfiguredLocalService();
    WriteContext ctx = new WriteContext().setCrc32(999);
    Future<WriteResponse> result = localService.writeWithContext("test", getTestDataBuffer(), ctx);
    WriteResponse 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 19 with WriteResponse

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

the class TestDistributedLogService method testWriteOpNoChecksum.

@Test(timeout = 60000)
public void testWriteOpNoChecksum() throws Exception {
    DistributedLogServiceImpl localService = createConfiguredLocalService();
    WriteContext ctx = new WriteContext();
    Future<WriteResponse> result = localService.writeWithContext("test", getTestDataBuffer(), ctx);
    WriteResponse resp = Await.result(result);
    assertEquals(StatusCode.SUCCESS, 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 20 with WriteResponse

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

the class TestDistributedLogService method testCloseTwice.

@Test(timeout = 60000)
public void testCloseTwice() throws Exception {
    String streamName = testName.getMethodName();
    StreamImpl s = createUnstartedStream(service, streamName);
    int numWrites = 10;
    List<Future<WriteResponse>> futureList = new ArrayList<Future<WriteResponse>>(numWrites);
    for (int i = 0; i < numWrites; i++) {
        WriteOp op = createWriteOp(service, streamName, i);
        s.submit(op);
        futureList.add(op.result());
    }
    assertEquals(numWrites, s.numPendingOps());
    Future<Void> closeFuture0 = s.requestClose("close 0");
    assertTrue("Stream " + streamName + " should be set to " + StreamStatus.CLOSING, StreamStatus.CLOSING == s.getStatus() || StreamStatus.CLOSED == s.getStatus());
    Future<Void> closeFuture1 = s.requestClose("close 1");
    assertTrue("Stream " + streamName + " should be set to " + StreamStatus.CLOSING, StreamStatus.CLOSING == s.getStatus() || StreamStatus.CLOSED == s.getStatus());
    Await.result(closeFuture0);
    assertEquals("Stream " + streamName + " should be set to " + StreamStatus.CLOSED, StreamStatus.CLOSED, s.getStatus());
    Await.result(closeFuture1);
    assertEquals("Stream " + streamName + " should be set to " + StreamStatus.CLOSED, StreamStatus.CLOSED, s.getStatus());
    for (int i = 0; i < numWrites; i++) {
        Future<WriteResponse> future = futureList.get(i);
        WriteResponse wr = Await.result(future);
        assertEquals("Pending op should fail with " + StatusCode.STREAM_UNAVAILABLE, StatusCode.STREAM_UNAVAILABLE, wr.getHeader().getCode());
    }
}
Also used : WriteOp(com.twitter.distributedlog.service.stream.WriteOp) StreamImpl(com.twitter.distributedlog.service.stream.StreamImpl) ArrayList(java.util.ArrayList) WriteResponse(com.twitter.distributedlog.thrift.service.WriteResponse) Future(com.twitter.util.Future) Test(org.junit.Test)

Aggregations

WriteResponse (com.twitter.distributedlog.thrift.service.WriteResponse)23 Test (org.junit.Test)21 WriteContext (com.twitter.distributedlog.thrift.service.WriteContext)10 WriteOp (com.twitter.distributedlog.service.stream.WriteOp)8 Future (com.twitter.util.Future)7 ArrayList (java.util.ArrayList)7 DistributedLogConfiguration (com.twitter.distributedlog.DistributedLogConfiguration)6 StreamImpl (com.twitter.distributedlog.service.stream.StreamImpl)6 DLSN (com.twitter.distributedlog.DLSN)5 StreamManagerImpl (com.twitter.distributedlog.service.stream.StreamManagerImpl)5 ServerConfiguration (com.twitter.distributedlog.service.config.ServerConfiguration)4 Stream (com.twitter.distributedlog.service.stream.Stream)3 List (java.util.List)3 LogRecord (com.twitter.distributedlog.LogRecord)2 InternalServerException (com.twitter.distributedlog.exceptions.InternalServerException)2 OwnershipAcquireFailedException (com.twitter.distributedlog.exceptions.OwnershipAcquireFailedException)2 HeartbeatOptions (com.twitter.distributedlog.thrift.service.HeartbeatOptions)2 AsyncLogWriter (com.twitter.distributedlog.AsyncLogWriter)1 AlreadyClosedException (com.twitter.distributedlog.exceptions.AlreadyClosedException)1 DLException (com.twitter.distributedlog.exceptions.DLException)1