DistributedLogMultiStreamWriter implements Runnable { public static Builder newBuilder() { return new Builder(); } private  DistributedLogMultiStreamWriter(List<String> streams,
                                            DistributedLogClient client,
                                            int bufferSize,
                                            long flushIntervalMicros,
                                            long requestTimeoutMs,
                                            int firstSpecultiveTimeoutMs,
                                            int maxSpeculativeTimeoutMs,
                                            float speculativeBackoffMultiplier,
                                            CompressionCodec.Type codec,
                                            Ticker clockTicker,
                                            ScheduledExecutorService scheduler); static Builder newBuilder(); synchronized Future<DLSN> write(ByteBuffer buffer); @Override void run(); void close();  }
@Test(timeout = 20000, expected = NullPointerException.class) public void testBuildWithNullCodec() throws Exception { DistributedLogMultiStreamWriter.newBuilder() .streams(Lists.newArrayList("stream1", "stream2")) .client(mock(DistributedLogClient.class)) .compressionCodec(null) .build(); }
@Test(timeout = 20000, expected = IllegalArgumentException.class) public void testBuildWithInvalidSpeculativeSettings1() throws Exception { DistributedLogMultiStreamWriter.newBuilder() .streams(Lists.newArrayList("stream1", "stream2")) .client(mock(DistributedLogClient.class)) .compressionCodec(CompressionCodec.Type.LZ4) .firstSpeculativeTimeoutMs(-1) .build(); }
@Test(timeout = 20000, expected = IllegalArgumentException.class) public void testBuildWithInvalidSpeculativeSettings2() throws Exception { DistributedLogMultiStreamWriter.newBuilder() .streams(Lists.newArrayList("stream1", "stream2")) .client(mock(DistributedLogClient.class)) .compressionCodec(CompressionCodec.Type.LZ4) .firstSpeculativeTimeoutMs(10) .maxSpeculativeTimeoutMs(5) .build(); }
@Test(timeout = 20000, expected = IllegalArgumentException.class) public void testBuildWithInvalidSpeculativeSettings3() throws Exception { DistributedLogMultiStreamWriter.newBuilder() .streams(Lists.newArrayList("stream1", "stream2")) .client(mock(DistributedLogClient.class)) .compressionCodec(CompressionCodec.Type.LZ4) .firstSpeculativeTimeoutMs(10) .maxSpeculativeTimeoutMs(20) .speculativeBackoffMultiplier(-1) .build(); }
@Test(timeout = 20000, expected = IllegalArgumentException.class) public void testBuildWithInvalidSpeculativeSettings4() throws Exception { DistributedLogMultiStreamWriter.newBuilder() .streams(Lists.newArrayList("stream1", "stream2")) .client(mock(DistributedLogClient.class)) .compressionCodec(CompressionCodec.Type.LZ4) .firstSpeculativeTimeoutMs(10) .maxSpeculativeTimeoutMs(20) .speculativeBackoffMultiplier(2) .requestTimeoutMs(10) .build(); }
@Test(timeout = 20000) public void testBuildMultiStreamWriter() throws Exception { DistributedLogMultiStreamWriter.newBuilder() .streams(Lists.newArrayList("stream1", "stream2")) .client(mock(DistributedLogClient.class)) .compressionCodec(CompressionCodec.Type.LZ4) .firstSpeculativeTimeoutMs(10) .maxSpeculativeTimeoutMs(20) .speculativeBackoffMultiplier(2) .requestTimeoutMs(50) .build(); assertTrue(true); }
@Test(timeout = 20000) public void testBuildWithPeriodicalFlushEnabled() throws Exception { ScheduledExecutorService executorService = mock(ScheduledExecutorService.class); DistributedLogMultiStreamWriter writer = DistributedLogMultiStreamWriter.newBuilder() .streams(Lists.newArrayList("stream1", "stream2")) .client(mock(DistributedLogClient.class)) .compressionCodec(CompressionCodec.Type.LZ4) .firstSpeculativeTimeoutMs(10) .maxSpeculativeTimeoutMs(20) .speculativeBackoffMultiplier(2) .requestTimeoutMs(50) .flushIntervalMs(1000) .scheduler(executorService) .build(); verify(executorService, times(1)).scheduleAtFixedRate(writer, 1000000, 1000000, TimeUnit.MICROSECONDS); }
@Test(timeout = 20000, expected = IllegalArgumentException.class) public void testBuildWithNullStreams() throws Exception { DistributedLogMultiStreamWriter.newBuilder() .build(); }
@Test(timeout = 20000, expected = IllegalArgumentException.class) public void testBuildWithEmptyStreamList() throws Exception { DistributedLogMultiStreamWriter.newBuilder() .streams(Lists.<String>newArrayList()) .build(); }
@Test(timeout = 20000, expected = NullPointerException.class) public void testBuildWithNullClient() throws Exception { DistributedLogMultiStreamWriter.newBuilder() .streams(Lists.newArrayList("stream1", "stream2")) .build(); }