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