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());
}
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());
}
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());
}
}
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());
}
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());
}
}
Aggregations