use of com.twitter.finagle.IndividualRequestTimeoutException in project distributedlog by twitter.
the class TestDistributedLogMultiStreamWriter method testFailRequestAfterRetriedAllStreams.
@Test(timeout = 20000)
public void testFailRequestAfterRetriedAllStreams() throws Exception {
DistributedLogClient client = mock(DistributedLogClient.class);
when(client.writeRecordSet((String) any(), (LogRecordSetBuffer) any())).thenReturn(new Promise<DLSN>());
DistributedLogMultiStreamWriter writer = DistributedLogMultiStreamWriter.newBuilder().streams(Lists.newArrayList("stream1", "stream2")).client(client).compressionCodec(CompressionCodec.Type.LZ4).firstSpeculativeTimeoutMs(10).maxSpeculativeTimeoutMs(20).speculativeBackoffMultiplier(2).requestTimeoutMs(5000000).flushIntervalMs(10).bufferSize(Integer.MAX_VALUE).build();
byte[] data = "test-test".getBytes(UTF_8);
ByteBuffer buffer = ByteBuffer.wrap(data);
Future<DLSN> writeFuture = writer.write(buffer);
try {
Await.result(writeFuture);
fail("Should fail the request after retries all streams");
} catch (IndividualRequestTimeoutException e) {
long timeoutMs = e.timeout().inMilliseconds();
assertTrue(timeoutMs >= (10 + 20) && timeoutMs < 5000000);
}
writer.close();
}
Aggregations