1717import java .util .Map ;
1818import java .util .concurrent .ConcurrentLinkedQueue ;
1919import java .util .concurrent .CountDownLatch ;
20+ import java .util .concurrent .ExecutionException ;
2021import java .util .concurrent .ExecutorService ;
2122import java .util .concurrent .Executors ;
23+ import java .util .concurrent .Future ;
2224import java .util .concurrent .TimeUnit ;
2325import java .util .concurrent .atomic .AtomicBoolean ;
2426
@@ -52,7 +54,7 @@ public void process(MessagePack msgpack, Socket socket) throws IOException {
5254 fluentd .waitUntilReady ();
5355
5456 // start asyncSenders
55- Sender asyncSender = new AsyncRawSocketSender ("localhost" , port );
57+ AsyncSender asyncSender = new AsyncRawSocketSender ("localhost" , port );
5658 Map <String , Object > data = new HashMap <String , Object >();
5759 data .put ("t1k1" , "t1v1" );
5860 data .put ("t1k2" , "t1v2" );
@@ -115,7 +117,7 @@ public void process(MessagePack msgpack, Socket socket) throws IOException {
115117 fluentd .waitUntilReady ();
116118
117119 // start asyncSenders
118- Sender asyncSender = new AsyncRawSocketSender ("localhost" , port );
120+ AsyncSender asyncSender = new AsyncRawSocketSender ("localhost" , port );
119121 int count = 10000 ;
120122 for (int i = 0 ; i < count ; i ++) {
121123 String tag = "tag:i" ;
@@ -186,7 +188,7 @@ public void process(MessagePack msgpack, Socket socket) throws IOException {
186188 fluentds [1 ].waitUntilReady ();
187189
188190 // start AsyncSenders
189- Sender [] asyncSenders = new Sender [2 ];
191+ AsyncSender [] asyncSenders = new AsyncSender [2 ];
190192 int [] counts = new int [2 ];
191193 asyncSenders [0 ] = asyncRawSocketSender ;
192194 counts [0 ] = 10000 ;
@@ -254,7 +256,7 @@ public void run() {
254256 }
255257
256258 @ Test
257- public void testBufferingAndResending () throws InterruptedException , IOException {
259+ public void testBufferingAndResending () throws InterruptedException , IOException , ExecutionException {
258260 final ConcurrentLinkedQueue <Event > readEvents = new ConcurrentLinkedQueue <Event >();
259261 final CountDownLatch countDownLatch = new CountDownLatch (4 );
260262 int port = MockFluentd .randomPort ();
@@ -278,12 +280,12 @@ public void process(MessagePack msgpack, Socket socket) throws IOException {
278280 fluentd .start ();
279281 fluentd .waitUntilReady ();
280282
281- Sender asyncSender = new AsyncRawSocketSender ("localhost" , port );
283+ AsyncSender asyncSender = new AsyncRawSocketSender ("localhost" , port );
282284 assertFalse (asyncSender .isConnected ());
283285 Map <String , Object > data = new HashMap <String , Object >();
284286 data .put ("key0" , "v0" );
285- boolean emitted1 = asyncSender .emit ("tag0" , data );
286- assertTrue (emitted1 );
287+ Future < Boolean > emitted1 = asyncSender .emit ("tag0" , data );
288+ assertTrue (emitted1 . get () );
287289
288290 // close fluentd to make the next sending failed
289291 TimeUnit .MILLISECONDS .sleep (500 );
@@ -294,21 +296,21 @@ public void process(MessagePack msgpack, Socket socket) throws IOException {
294296
295297 data = new HashMap <String , Object >();
296298 data .put ("key0" , "v1" );
297- boolean emitted2 = asyncSender .emit ("tag0" , data );
298- assertTrue (emitted2 );
299+ Future < Boolean > emitted2 = asyncSender .emit ("tag0" , data );
300+ assertTrue (emitted2 . get () );
299301
300302 // wait to avoid the suppression of reconnection
301303 TimeUnit .MILLISECONDS .sleep (500 );
302304
303305 data = new HashMap <String , Object >();
304306 data .put ("key0" , "v2" );
305- boolean emitted3 = asyncSender .emit ("tag0" , data );
306- assertTrue (emitted3 );
307+ Future < Boolean > emitted3 = asyncSender .emit ("tag0" , data );
308+ assertTrue (emitted3 . get () );
307309
308310 data = new HashMap <String , Object >();
309311 data .put ("key0" , "v3" );
310- boolean emitted4 = asyncSender .emit ("tag0" , data );
311- assertTrue (emitted4 );
312+ Future < Boolean > emitted4 = asyncSender .emit ("tag0" , data );
313+ assertTrue (emitted4 . get () );
312314
313315 countDownLatch .await (500 , TimeUnit .MILLISECONDS );
314316
@@ -382,7 +384,7 @@ public void run() {
382384 });
383385
384386 // start asyncSenders
385- Sender asyncSender = new AsyncRawSocketSender ("localhost" , port );
387+ AsyncSender asyncSender = new AsyncRawSocketSender ("localhost" , port );
386388 String tag = "tag" ;
387389 int i ;
388390 for (i = 0 ; i < 1000000 ; i ++) { // Enough to fill the sender's buffer
@@ -392,7 +394,7 @@ public void run() {
392394
393395 if (bufferFull .getCount () > 0 ) {
394396 // Fill the sender's buffer
395- if (!asyncSender .emit (tag , record )) {
397+ if (!asyncSender .emit (tag , record ). get () ) {
396398 // Buffer full. Need to recover the fluentd
397399 bufferFull .countDown ();
398400 Thread .sleep (2000 );
0 commit comments