use of com.twitter.distributedlog.thrift.service.WriteResponse 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.thrift.service.WriteResponse in project distributedlog by twitter.
the class TestDistributedLogService method testWriteOpChecksumBadStream.
@Test(timeout = 60000)
public void testWriteOpChecksumBadStream() throws Exception {
DistributedLogServiceImpl localService = createConfiguredLocalService();
WriteContext ctx = new WriteContext().setCrc32(ProtocolUtils.writeOpCRC32("test", getTestDataBuffer().array()));
Future<WriteResponse> result = localService.writeWithContext("test1", 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 BulkWriteOp method executeOp.
@Override
protected Future<BulkWriteResponse> executeOp(AsyncLogWriter writer, Sequencer sequencer, Object txnLock) {
// Need to convert input buffers to LogRecords.
List<LogRecord> records;
Future<List<Future<DLSN>>> futureList;
synchronized (txnLock) {
records = asRecordList(buffers, sequencer);
futureList = writer.writeBulk(records);
}
// Collect into a list of tries to make it easier to extract exception or DLSN.
Future<List<Try<DLSN>>> writes = asTryList(futureList);
Future<BulkWriteResponse> response = writes.flatMap(new AbstractFunction1<List<Try<DLSN>>, Future<BulkWriteResponse>>() {
@Override
public Future<BulkWriteResponse> apply(List<Try<DLSN>> results) {
// Considered a success at batch level even if no individual writes succeeed.
// The reason is that its impossible to make an appropriate decision re retries without
// individual buffer failure reasons.
List<WriteResponse> writeResponses = new ArrayList<WriteResponse>(results.size());
BulkWriteResponse bulkWriteResponse = ResponseUtils.bulkWriteSuccess().setWriteResponses(writeResponses);
// failed.
if (results.size() > 0) {
Try<DLSN> firstResult = results.get(0);
if (isDefiniteFailure(firstResult)) {
return new ConstFuture(firstResult);
}
}
// Translate all futures to write responses.
Iterator<Try<DLSN>> iterator = results.iterator();
while (iterator.hasNext()) {
Try<DLSN> completedFuture = iterator.next();
try {
DLSN dlsn = completedFuture.get();
WriteResponse writeResponse = ResponseUtils.writeSuccess().setDlsn(dlsn.serialize());
writeResponses.add(writeResponse);
successRecordCounter.inc();
} catch (Exception ioe) {
WriteResponse writeResponse = ResponseUtils.write(ResponseUtils.exceptionToHeader(ioe));
writeResponses.add(writeResponse);
if (StatusCode.FOUND == writeResponse.getHeader().getCode()) {
redirectRecordCounter.inc();
} else {
failureRecordCounter.inc();
}
}
}
return Future.value(bulkWriteResponse);
}
});
return response;
}
Aggregations