use of com.twitter.distributedlog.thrift.service.WriteResponse 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();
}
use of com.twitter.distributedlog.thrift.service.WriteResponse in project distributedlog by twitter.
the class TestDistributedLogService method testAcquireStreams.
@Test(timeout = 60000)
public void testAcquireStreams() throws Exception {
String streamName = testName.getMethodName();
StreamImpl s0 = createUnstartedStream(service, streamName);
s0.suspendAcquiring();
DistributedLogServiceImpl service1 = createService(serverConf, dlConf);
StreamImpl s1 = createUnstartedStream(service1, streamName);
s1.suspendAcquiring();
// create write ops
WriteOp op0 = createWriteOp(service, streamName, 0L);
s0.submit(op0);
WriteOp op1 = createWriteOp(service1, streamName, 1L);
s1.submit(op1);
// check pending size
assertEquals("Write Op 0 should be pending in service 0", 1, s0.numPendingOps());
assertEquals("Write Op 1 should be pending in service 1", 1, s1.numPendingOps());
// start acquiring s0
s0.resumeAcquiring().start();
WriteResponse wr0 = Await.result(op0.result());
assertEquals("Op 0 should succeed", StatusCode.SUCCESS, wr0.getHeader().getCode());
assertEquals("Service 0 should acquire stream", StreamStatus.INITIALIZED, s0.getStatus());
assertNotNull(s0.getManager());
assertNotNull(s0.getWriter());
assertNull(s0.getLastException());
// start acquiring s1
s1.resumeAcquiring().start();
WriteResponse wr1 = Await.result(op1.result());
assertEquals("Op 1 should fail", StatusCode.FOUND, wr1.getHeader().getCode());
assertEquals("Service 1 should be in BACKOFF state", StreamStatus.BACKOFF, s1.getStatus());
assertNotNull(s1.getManager());
assertNull(s1.getWriter());
assertNotNull(s1.getLastException());
assertTrue(s1.getLastException() instanceof OwnershipAcquireFailedException);
service1.shutdown();
}
use of com.twitter.distributedlog.thrift.service.WriteResponse in project distributedlog by twitter.
the class TestDistributedLogService method testAcquireStreamsWhenExceedMaxCachedPartitions.
@Test(timeout = 60000)
public void testAcquireStreamsWhenExceedMaxCachedPartitions() throws Exception {
String streamName = testName.getMethodName() + "_0000";
DistributedLogConfiguration confLocal = new DistributedLogConfiguration();
confLocal.addConfiguration(dlConf);
confLocal.setMaxCachedPartitionsPerProxy(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 fail to acquire another partition
try {
serviceLocal.getLogWriter(testName.getMethodName() + "_0001");
fail("Should fail to acquire new streams");
} catch (StreamUnavailableException sue) {
// expected
}
assertEquals(1, serviceLocal.getStreamManager().numCached());
assertEquals(1, serviceLocal.getStreamManager().numAcquired());
// should be able to acquire partitions from other streams
String anotherStreamName = testName.getMethodName() + "-another_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 succeed", StatusCode.SUCCESS, wr1.getHeader().getCode());
assertEquals(2, serviceLocal.getStreamManager().numAcquired());
}
use of com.twitter.distributedlog.thrift.service.WriteResponse 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();
}
use of com.twitter.distributedlog.thrift.service.WriteResponse in project distributedlog by twitter.
the class TestDistributedLogService method testNonDurableWrite.
@Test(timeout = 60000)
public void testNonDurableWrite() throws Exception {
DistributedLogConfiguration confLocal = newLocalConf();
confLocal.setOutputBufferSize(Integer.MAX_VALUE).setImmediateFlushEnabled(false).setPeriodicFlushFrequencyMilliSeconds(0).setDurableWriteEnabled(false);
ServerConfiguration serverConfLocal = new ServerConfiguration();
serverConfLocal.addConfiguration(serverConf);
serverConfLocal.enableDurableWrite(false);
serverConfLocal.setServiceTimeoutMs(Integer.MAX_VALUE).setStreamProbationTimeoutMs(Integer.MAX_VALUE);
String streamName = testName.getMethodName();
DistributedLogServiceImpl localService = createService(serverConfLocal, confLocal);
StreamManagerImpl streamManager = (StreamManagerImpl) localService.getStreamManager();
int numWrites = 10;
List<Future<WriteResponse>> futureList = new ArrayList<Future<WriteResponse>>();
for (int i = 0; i < numWrites; i++) {
futureList.add(localService.write(streamName, createRecord(i)));
}
assertTrue("Stream " + streamName + " should be cached", streamManager.getCachedStreams().containsKey(streamName));
List<WriteResponse> resultList = FutureUtils.result(Future.collect(futureList));
for (WriteResponse wr : resultList) {
assertEquals(DLSN.InvalidDLSN, DLSN.deserialize(wr.getDlsn()));
}
localService.shutdown();
}
Aggregations