Search in sources :

Example 6 with WriteOp

use of com.twitter.distributedlog.service.stream.WriteOp in project distributedlog by twitter.

the class TestStreamOp method testResponseFailedTwice.

@Test(timeout = 60000)
public void testResponseFailedTwice() throws Exception {
    WriteOp writeOp = getWriteOp();
    writeOp.fail(new InternalServerException("test1"));
    writeOp.fail(new InternalServerException("test2"));
    WriteResponse response = Await.result(writeOp.result());
    assertEquals(StatusCode.INTERNAL_SERVER_ERROR, response.getHeader().getCode());
    assertEquals(ResponseUtils.exceptionToHeader(new InternalServerException("test1")), response.getHeader());
}
Also used : WriteOp(com.twitter.distributedlog.service.stream.WriteOp) InternalServerException(com.twitter.distributedlog.exceptions.InternalServerException) WriteResponse(com.twitter.distributedlog.thrift.service.WriteResponse) Test(org.junit.Test)

Example 7 with WriteOp

use of com.twitter.distributedlog.service.stream.WriteOp 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 8 with WriteOp

use of com.twitter.distributedlog.service.stream.WriteOp 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)

Example 9 with WriteOp

use of com.twitter.distributedlog.service.stream.WriteOp in project distributedlog by twitter.

the class TestDistributedLogService method testFailRequestsDuringClosing.

@Test(timeout = 60000)
public void testFailRequestsDuringClosing() throws Exception {
    String streamName = testName.getMethodName();
    StreamImpl s = createUnstartedStream(service, streamName);
    Future<Void> closeFuture = s.requestClose("close");
    assertTrue("Stream " + streamName + " should be set to " + StreamStatus.CLOSING, StreamStatus.CLOSING == s.getStatus() || StreamStatus.CLOSED == s.getStatus());
    WriteOp op1 = createWriteOp(service, streamName, 0L);
    s.submit(op1);
    WriteResponse response1 = Await.result(op1.result());
    assertEquals("Op should fail with " + StatusCode.STREAM_UNAVAILABLE + " if it is closing", StatusCode.STREAM_UNAVAILABLE, response1.getHeader().getCode());
    Await.result(closeFuture);
    assertEquals("Stream " + streamName + " should be set to " + StreamStatus.CLOSED, StreamStatus.CLOSED, s.getStatus());
    WriteOp op2 = createWriteOp(service, streamName, 1L);
    s.submit(op2);
    WriteResponse response2 = Await.result(op2.result());
    assertEquals("Op should fail with " + StatusCode.STREAM_UNAVAILABLE + " if it is closed", StatusCode.STREAM_UNAVAILABLE, response2.getHeader().getCode());
}
Also used : WriteOp(com.twitter.distributedlog.service.stream.WriteOp) StreamImpl(com.twitter.distributedlog.service.stream.StreamImpl) WriteResponse(com.twitter.distributedlog.thrift.service.WriteResponse) Test(org.junit.Test)

Example 10 with WriteOp

use of com.twitter.distributedlog.service.stream.WriteOp 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)

Aggregations

WriteOp (com.twitter.distributedlog.service.stream.WriteOp)11 Test (org.junit.Test)10 WriteResponse (com.twitter.distributedlog.thrift.service.WriteResponse)8 StreamImpl (com.twitter.distributedlog.service.stream.StreamImpl)4 DistributedLogConfiguration (com.twitter.distributedlog.DistributedLogConfiguration)2 InternalServerException (com.twitter.distributedlog.exceptions.InternalServerException)2 OwnershipAcquireFailedException (com.twitter.distributedlog.exceptions.OwnershipAcquireFailedException)2 StreamUnavailableException (com.twitter.distributedlog.exceptions.StreamUnavailableException)2 ServerConfiguration (com.twitter.distributedlog.service.config.ServerConfiguration)2 Stream (com.twitter.distributedlog.service.stream.Stream)2 Future (com.twitter.util.Future)2 ArrayList (java.util.ArrayList)2 SettableFeature (org.apache.bookkeeper.feature.SettableFeature)2 AsyncLogWriter (com.twitter.distributedlog.AsyncLogWriter)1 DLSN (com.twitter.distributedlog.DLSN)1 BulkWriteOp (com.twitter.distributedlog.service.stream.BulkWriteOp)1 Sequencer (com.twitter.distributedlog.util.Sequencer)1 ConfigurationException (org.apache.commons.configuration.ConfigurationException)1 BoxedUnit (scala.runtime.BoxedUnit)1