You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@druid.apache.org by ji...@apache.org on 2018/07/09 17:48:45 UTC

[incubator-druid] branch 0.12.2 updated: Increase timeout for BlockingPoolTest (#5975)

This is an automated email from the ASF dual-hosted git repository.

jihoonson pushed a commit to branch 0.12.2
in repository https://gitbox.apache.org/repos/asf/incubator-druid.git


The following commit(s) were added to refs/heads/0.12.2 by this push:
     new 9c39472  Increase timeout for BlockingPoolTest (#5975)
9c39472 is described below

commit 9c394727cb92673fdf981b5172120c993e17c76f
Author: Jihoon Son <ji...@apache.org>
AuthorDate: Mon Jul 9 10:48:41 2018 -0700

    Increase timeout for BlockingPoolTest (#5975)
---
 .../io/druid/collections/BlockingPoolTest.java     | 153 +++++++++++----------
 1 file changed, 81 insertions(+), 72 deletions(-)

diff --git a/common/src/test/java/io/druid/collections/BlockingPoolTest.java b/common/src/test/java/io/druid/collections/BlockingPoolTest.java
index f76339c..8e13cb5 100644
--- a/common/src/test/java/io/druid/collections/BlockingPoolTest.java
+++ b/common/src/test/java/io/druid/collections/BlockingPoolTest.java
@@ -21,7 +21,9 @@ package io.druid.collections;
 
 import com.google.common.base.Suppliers;
 import com.google.common.collect.Lists;
-import org.junit.AfterClass;
+import io.druid.java.util.common.concurrent.Execs;
+import org.junit.After;
+import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
@@ -30,7 +32,6 @@ import java.util.List;
 import java.util.concurrent.Callable;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
 import java.util.concurrent.Future;
 
 import static org.junit.Assert.assertEquals;
@@ -40,26 +41,34 @@ import static org.junit.Assert.assertTrue;
 
 public class BlockingPoolTest
 {
-  private static final ExecutorService SERVICE = Executors.newFixedThreadPool(2);
+  private ExecutorService service;
 
-  private static final DefaultBlockingPool<Integer> POOL = new DefaultBlockingPool<>(Suppliers.ofInstance(1), 10);
-  private static final BlockingPool<Integer> EMPTY_POOL = new DefaultBlockingPool<>(Suppliers.ofInstance(1), 0);
+  private DefaultBlockingPool<Integer> pool;
+  private BlockingPool<Integer> emptyPool;
 
-  @AfterClass
-  public static void teardown()
+  @Rule
+  public ExpectedException expectedException = ExpectedException.none();
+
+  @Before
+  public void setup()
   {
-    SERVICE.shutdown();
+    service = Execs.multiThreaded(2, "blocking-pool-test");
+    pool = new DefaultBlockingPool<>(Suppliers.ofInstance(1), 10);
+    emptyPool = new DefaultBlockingPool<>(Suppliers.ofInstance(1), 0);
   }
 
-  @Rule
-  public ExpectedException expectedException = ExpectedException.none();
+  @After
+  public void teardown()
+  {
+    service.shutdownNow();
+  }
 
   @Test
   public void testTakeFromEmptyPool()
   {
     expectedException.expect(IllegalStateException.class);
     expectedException.expectMessage("Pool was initialized with limit = 0, there are no objects to take.");
-    EMPTY_POOL.take(0);
+    emptyPool.take(0);
   }
 
   @Test
@@ -67,54 +76,54 @@ public class BlockingPoolTest
   {
     expectedException.expect(IllegalStateException.class);
     expectedException.expectMessage("Pool was initialized with limit = 0, there are no objects to take.");
-    EMPTY_POOL.takeBatch(1, 0);
+    emptyPool.takeBatch(1, 0);
   }
 
-  @Test(timeout = 1000)
+  @Test(timeout = 5000)
   public void testTake()
   {
-    final ReferenceCountingResourceHolder<Integer> holder = POOL.take(100);
+    final ReferenceCountingResourceHolder<Integer> holder = pool.take(100);
     assertNotNull(holder);
-    assertEquals(9, POOL.getPoolSize());
+    assertEquals(9, pool.getPoolSize());
     holder.close();
-    assertEquals(10, POOL.getPoolSize());
+    assertEquals(10, pool.getPoolSize());
   }
 
-  @Test(timeout = 1000)
+  @Test(timeout = 5000)
   public void testTakeTimeout()
   {
-    final ReferenceCountingResourceHolder<List<Integer>> batchHolder = POOL.takeBatch(10, 100L);
-    final ReferenceCountingResourceHolder<Integer> holder = POOL.take(100);
+    final ReferenceCountingResourceHolder<List<Integer>> batchHolder = pool.takeBatch(10, 100L);
+    final ReferenceCountingResourceHolder<Integer> holder = pool.take(100);
     assertNull(holder);
     batchHolder.close();
   }
 
-  @Test(timeout = 1000)
+  @Test(timeout = 5000)
   public void testTakeBatch()
   {
-    final ReferenceCountingResourceHolder<List<Integer>> holder = POOL.takeBatch(6, 100L);
+    final ReferenceCountingResourceHolder<List<Integer>> holder = pool.takeBatch(6, 100L);
     assertNotNull(holder);
     assertEquals(6, holder.get().size());
-    assertEquals(4, POOL.getPoolSize());
+    assertEquals(4, pool.getPoolSize());
     holder.close();
-    assertEquals(10, POOL.getPoolSize());
+    assertEquals(10, pool.getPoolSize());
   }
 
-  @Test(timeout = 1000)
+  @Test(timeout = 5000)
   public void testWaitAndTakeBatch() throws InterruptedException, ExecutionException
   {
-    ReferenceCountingResourceHolder<List<Integer>> batchHolder = POOL.takeBatch(10, 10);
+    ReferenceCountingResourceHolder<List<Integer>> batchHolder = pool.takeBatch(10, 10);
     assertNotNull(batchHolder);
     assertEquals(10, batchHolder.get().size());
-    assertEquals(0, POOL.getPoolSize());
+    assertEquals(0, pool.getPoolSize());
 
-    final Future<ReferenceCountingResourceHolder<List<Integer>>> future = SERVICE.submit(
+    final Future<ReferenceCountingResourceHolder<List<Integer>>> future = service.submit(
         new Callable<ReferenceCountingResourceHolder<List<Integer>>>()
         {
           @Override
           public ReferenceCountingResourceHolder<List<Integer>> call() throws Exception
           {
-            return POOL.takeBatch(8, 100);
+            return pool.takeBatch(8, 100);
           }
         }
     );
@@ -124,26 +133,26 @@ public class BlockingPoolTest
     batchHolder = future.get();
     assertNotNull(batchHolder);
     assertEquals(8, batchHolder.get().size());
-    assertEquals(2, POOL.getPoolSize());
+    assertEquals(2, pool.getPoolSize());
 
     batchHolder.close();
-    assertEquals(10, POOL.getPoolSize());
+    assertEquals(10, pool.getPoolSize());
   }
 
-  @Test(timeout = 1000)
+  @Test(timeout = 5000)
   public void testTakeBatchTooManyObjects()
   {
-    final ReferenceCountingResourceHolder<List<Integer>> holder = POOL.takeBatch(100, 100L);
+    final ReferenceCountingResourceHolder<List<Integer>> holder = pool.takeBatch(100, 100L);
     assertNull(holder);
   }
 
-  @Test(timeout = 1000)
+  @Test(timeout = 5000)
   public void testConcurrentTake() throws ExecutionException, InterruptedException
   {
-    final int limit1 = POOL.maxSize() / 2;
-    final int limit2 = POOL.maxSize() - limit1 + 1;
+    final int limit1 = pool.maxSize() / 2;
+    final int limit2 = pool.maxSize() - limit1 + 1;
 
-    final Future<List<ReferenceCountingResourceHolder<Integer>>> f1 = SERVICE.submit(
+    final Future<List<ReferenceCountingResourceHolder<Integer>>> f1 = service.submit(
         new Callable<List<ReferenceCountingResourceHolder<Integer>>>()
         {
           @Override
@@ -151,13 +160,13 @@ public class BlockingPoolTest
           {
             List<ReferenceCountingResourceHolder<Integer>> result = Lists.newArrayList();
             for (int i = 0; i < limit1; i++) {
-              result.add(POOL.take(10));
+              result.add(pool.take(10));
             }
             return result;
           }
         }
     );
-    final Future<List<ReferenceCountingResourceHolder<Integer>>> f2 = SERVICE.submit(
+    final Future<List<ReferenceCountingResourceHolder<Integer>>> f2 = service.submit(
         new Callable<List<ReferenceCountingResourceHolder<Integer>>>()
         {
           @Override
@@ -165,7 +174,7 @@ public class BlockingPoolTest
           {
             List<ReferenceCountingResourceHolder<Integer>> result = Lists.newArrayList();
             for (int i = 0; i < limit2; i++) {
-              result.add(POOL.take(10));
+              result.add(pool.take(10));
             }
             return result;
           }
@@ -175,7 +184,7 @@ public class BlockingPoolTest
     final List<ReferenceCountingResourceHolder<Integer>> r1 = f1.get();
     final List<ReferenceCountingResourceHolder<Integer>> r2 = f2.get();
 
-    assertEquals(0, POOL.getPoolSize());
+    assertEquals(0, pool.getPoolSize());
     assertTrue(r1.contains(null) || r2.contains(null));
 
     int nonNullCount = 0;
@@ -190,9 +199,9 @@ public class BlockingPoolTest
         nonNullCount++;
       }
     }
-    assertEquals(POOL.maxSize(), nonNullCount);
+    assertEquals(pool.maxSize(), nonNullCount);
 
-    final Future future1 = SERVICE.submit(new Runnable()
+    final Future future1 = service.submit(new Runnable()
     {
       @Override
       public void run()
@@ -204,7 +213,7 @@ public class BlockingPoolTest
         }
       }
     });
-    final Future future2 = SERVICE.submit(new Runnable()
+    final Future future2 = service.submit(new Runnable()
     {
       @Override
       public void run()
@@ -220,82 +229,82 @@ public class BlockingPoolTest
     future1.get();
     future2.get();
 
-    assertEquals(POOL.maxSize(), POOL.getPoolSize());
+    assertEquals(pool.maxSize(), pool.getPoolSize());
   }
 
-  @Test(timeout = 1000)
+  @Test(timeout = 5000)
   public void testConcurrentTakeBatch() throws ExecutionException, InterruptedException
   {
-    final int batch1 = POOL.maxSize() / 2;
+    final int batch1 = pool.maxSize() / 2;
     final Callable<ReferenceCountingResourceHolder<List<Integer>>> c1 =
         new Callable<ReferenceCountingResourceHolder<List<Integer>>>()
         {
           @Override
           public ReferenceCountingResourceHolder<List<Integer>> call() throws Exception
           {
-            return POOL.takeBatch(batch1, 10);
+            return pool.takeBatch(batch1, 10);
           }
         };
 
-    final int batch2 = POOL.maxSize() - batch1 + 1;
+    final int batch2 = pool.maxSize() - batch1 + 1;
     final Callable<ReferenceCountingResourceHolder<List<Integer>>> c2 =
         new Callable<ReferenceCountingResourceHolder<List<Integer>>>()
         {
           @Override
           public ReferenceCountingResourceHolder<List<Integer>> call() throws Exception
           {
-            return POOL.takeBatch(batch2, 10);
+            return pool.takeBatch(batch2, 10);
           }
         };
 
-    final Future<ReferenceCountingResourceHolder<List<Integer>>> f1 = SERVICE.submit(c1);
-    final Future<ReferenceCountingResourceHolder<List<Integer>>> f2 = SERVICE.submit(c2);
+    final Future<ReferenceCountingResourceHolder<List<Integer>>> f1 = service.submit(c1);
+    final Future<ReferenceCountingResourceHolder<List<Integer>>> f2 = service.submit(c2);
 
     final ReferenceCountingResourceHolder<List<Integer>> r1 = f1.get();
     final ReferenceCountingResourceHolder<List<Integer>> r2 = f2.get();
 
     if (r1 != null) {
       assertNull(r2);
-      assertEquals(POOL.maxSize() - batch1, POOL.getPoolSize());
+      assertEquals(pool.maxSize() - batch1, pool.getPoolSize());
       assertEquals(batch1, r1.get().size());
       r1.close();
     } else {
       assertNotNull(r2);
-      assertEquals(POOL.maxSize() - batch2, POOL.getPoolSize());
+      assertEquals(pool.maxSize() - batch2, pool.getPoolSize());
       assertEquals(batch2, r2.get().size());
       r2.close();
     }
 
-    assertEquals(POOL.maxSize(), POOL.getPoolSize());
+    assertEquals(pool.maxSize(), pool.getPoolSize());
   }
 
-  @Test(timeout = 1000)
+  @Test(timeout = 5000)
   public void testConcurrentBatchClose() throws ExecutionException, InterruptedException
   {
-    final int batch1 = POOL.maxSize() / 2;
+    final int batch1 = pool.maxSize() / 2;
     final Callable<ReferenceCountingResourceHolder<List<Integer>>> c1 =
         new Callable<ReferenceCountingResourceHolder<List<Integer>>>()
         {
           @Override
           public ReferenceCountingResourceHolder<List<Integer>> call() throws Exception
           {
-            return POOL.takeBatch(batch1, 10);
+            return pool.takeBatch(batch1, 10);
           }
         };
 
-    final int batch2 = POOL.maxSize() - batch1;
+    final int batch2 = pool.maxSize() - batch1;
     final Callable<ReferenceCountingResourceHolder<List<Integer>>> c2 =
         new Callable<ReferenceCountingResourceHolder<List<Integer>>>()
         {
           @Override
           public ReferenceCountingResourceHolder<List<Integer>> call() throws Exception
           {
-            return POOL.takeBatch(batch2, 10);
+            return pool.takeBatch(batch2, 10);
           }
         };
 
-    final Future<ReferenceCountingResourceHolder<List<Integer>>> f1 = SERVICE.submit(c1);
-    final Future<ReferenceCountingResourceHolder<List<Integer>>> f2 = SERVICE.submit(c2);
+    final Future<ReferenceCountingResourceHolder<List<Integer>>> f1 = service.submit(c1);
+    final Future<ReferenceCountingResourceHolder<List<Integer>>> f2 = service.submit(c2);
 
     final ReferenceCountingResourceHolder<List<Integer>> r1 = f1.get();
     final ReferenceCountingResourceHolder<List<Integer>> r2 = f2.get();
@@ -304,9 +313,9 @@ public class BlockingPoolTest
     assertNotNull(r2);
     assertEquals(batch1, r1.get().size());
     assertEquals(batch2, r2.get().size());
-    assertEquals(0, POOL.getPoolSize());
+    assertEquals(0, pool.getPoolSize());
 
-    final Future future1 = SERVICE.submit(new Runnable()
+    final Future future1 = service.submit(new Runnable()
     {
       @Override
       public void run()
@@ -314,7 +323,7 @@ public class BlockingPoolTest
         r1.close();
       }
     });
-    final Future future2 = SERVICE.submit(new Runnable()
+    final Future future2 = service.submit(new Runnable()
     {
       @Override
       public void run()
@@ -326,13 +335,13 @@ public class BlockingPoolTest
     future1.get();
     future2.get();
 
-    assertEquals(POOL.maxSize(), POOL.getPoolSize());
+    assertEquals(pool.maxSize(), pool.getPoolSize());
   }
 
-  @Test(timeout = 1000)
+  @Test(timeout = 5000)
   public void testConcurrentTakeBatchClose() throws ExecutionException, InterruptedException
   {
-    final ReferenceCountingResourceHolder<List<Integer>> r1 = POOL.takeBatch(1, 10);
+    final ReferenceCountingResourceHolder<List<Integer>> r1 = pool.takeBatch(1, 10);
 
     final Callable<ReferenceCountingResourceHolder<List<Integer>>> c2 =
         new Callable<ReferenceCountingResourceHolder<List<Integer>>>()
@@ -340,12 +349,12 @@ public class BlockingPoolTest
           @Override
           public ReferenceCountingResourceHolder<List<Integer>> call() throws Exception
           {
-            return POOL.takeBatch(10, 100);
+            return pool.takeBatch(10, 100);
           }
         };
 
-    final Future<ReferenceCountingResourceHolder<List<Integer>>> f2 = SERVICE.submit(c2);
-    final Future f1 = SERVICE.submit(new Runnable()
+    final Future<ReferenceCountingResourceHolder<List<Integer>>> f2 = service.submit(c2);
+    final Future f1 = service.submit(new Runnable()
     {
       @Override
       public void run()
@@ -364,9 +373,9 @@ public class BlockingPoolTest
     f1.get();
     assertNotNull(r2);
     assertEquals(10, r2.get().size());
-    assertEquals(0, POOL.getPoolSize());
+    assertEquals(0, pool.getPoolSize());
 
     r2.close();
-    assertEquals(POOL.maxSize(), POOL.getPoolSize());
+    assertEquals(pool.maxSize(), pool.getPoolSize());
   }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@druid.apache.org
For additional commands, e-mail: dev-help@druid.apache.org