Search in sources :

Example 1 with IndividualRequestTimeoutException

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();
}
Also used : DLSN(com.twitter.distributedlog.DLSN) IndividualRequestTimeoutException(com.twitter.finagle.IndividualRequestTimeoutException) ByteBuffer(java.nio.ByteBuffer) DistributedLogClient(com.twitter.distributedlog.service.DistributedLogClient) Test(org.junit.Test)

Aggregations

DLSN (com.twitter.distributedlog.DLSN)1 DistributedLogClient (com.twitter.distributedlog.service.DistributedLogClient)1 IndividualRequestTimeoutException (com.twitter.finagle.IndividualRequestTimeoutException)1 ByteBuffer (java.nio.ByteBuffer)1 Test (org.junit.Test)1