@@ -0,0 +1,1907 @@
+package com.flozano.statsd.client;%0A%0Aimport static com.jayway.awaitility.Awaitility.await;%0Aimport static org.junit.Assert.assertFalse;%0Aimport static org.mockito.Matchers.anyVararg;%0Aimport static org.mockito.Mockito.mock;%0Aimport static org.mockito.Mockito.times;%0Aimport static org.mockito.Mockito.verify;%0Aimport static org.mockito.Mockito.verifyNoMoreInteractions;%0Aimport static org.mockito.Mockito.when;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.Arrays;%0Aimport java.util.List;%0Aimport java.util.concurrent.CompletableFuture;%0Aimport java.util.concurrent.TimeUnit;%0A%0Aimport org.junit.Before;%0Aimport org.junit.Test;%0A%0Aimport com.flozano.statsd.values.GaugeValue;%0Aimport com.flozano.statsd.values.MetricValue;%0Aimport com.flozano.statsd.values.TimingValue;%0A%0Apublic class BatchClientTest %7B%0A%0A%09StatsDClient inner;%0A%0A%09@Before%0A%09public void setUp() %7B%0A%09%09inner = mock(StatsDClient.class);%0A%09%09when(inner.send(anyVararg())).thenReturn(%0A%09%09%09%09CompletableFuture.completedFuture(null));%0A%09%7D%0A%0A%09@Test(expected = IllegalStateException.class)%0A%09public void testDoubleBatch() %7B%0A%09%09try (BatchStatsDClient batchClient = new BatchStatsDClient(inner)) %7B%0A%09%09%09try (StatsDClient c = batchClient.batch()) %7B%0A%09%09%09%7D%0A%09%09%7D%0A%09%7D%0A%0A%09@Test%0A%09public void testBatch() %7B%0A%09%09List%3CMetricValue%3E metrics = Arrays.asList(new GaugeValue(%22test%22, 4321),%0A%09%09%09%09new TimingValue(%22test2%22, 321));%0A%09%09List%3CCompletableFuture%3CVoid%3E%3E cfs = new ArrayList%3C%3E();%0A%0A%09%09CompletableFuture%3CVoid%3E cf;%0A%09%09try (BatchStatsDClient batchClient = new BatchStatsDClient(inner)) %7B%0A%09%09%09for (MetricValue m : metrics) %7B%0A%09%09%09%09cfs.add(batchClient.send(m));%0A%09%09%09%7D%0A%09%09%09cf = CompletableFuture.allOf(cfs.toArray(new CompletableFuture%5Bcfs%0A%09%09%09%09%09.size()%5D));%0A%09%09%09assertFalse(cf.isDone());%0A%09%09%09verifyNoMoreInteractions(inner);%0A%09%09%7D%0A%09%09await().atMost(5, TimeUnit.SECONDS).until(() -%3E cf.isDone());%0A%09%09assertFalse(cf.isCancelled());%0A%09%09assertFalse(cf.isCompletedExceptionally());%0A%09%09verify(inner, times(1)).send(anyVararg());%0A%09%7D%0A%7D%0A

Test batch client