You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by ja...@apache.org on 2019/07/24 02:44:30 UTC

[incubator-pinot] branch master updated: Remove the usage of guava deprecated methods (#4457)

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

jackie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-pinot.git


The following commit(s) were added to refs/heads/master by this push:
     new 14ef543  Remove the usage of guava deprecated methods (#4457)
14ef543 is described below

commit 14ef543ebb701a8208f87e578b8fb82ca7786cbf
Author: Xiaotian (Jackie) Jiang <17...@users.noreply.github.com>
AuthorDate: Tue Jul 23 19:44:25 2019 -0700

    Remove the usage of guava deprecated methods (#4457)
    
    Remove the usage of the following methods:
    - Futures.addCallback(ListenableFuture FutureCallback)
    - MoreExecutors.sameThreadExecutor()
---
 .../request/ScheduledRequestHandlerTest.java       | 11 +++++-----
 .../apache/pinot/transport/netty/NettyServer.java  |  3 ++-
 .../transport/perf/ScatterGatherPerfClient.java    |  5 ++---
 .../pool/AsyncPoolResourceManagerAdapterTest.java  | 14 ++++++------
 .../pinot/transport/pool/KeyedPoolImplTest.java    | 25 +++++++++-------------
 5 files changed, 27 insertions(+), 31 deletions(-)

diff --git a/pinot-server/src/test/java/org/apache/pinot/server/request/ScheduledRequestHandlerTest.java b/pinot-server/src/test/java/org/apache/pinot/server/request/ScheduledRequestHandlerTest.java
index a487f42..e0fe072 100644
--- a/pinot-server/src/test/java/org/apache/pinot/server/request/ScheduledRequestHandlerTest.java
+++ b/pinot-server/src/test/java/org/apache/pinot/server/request/ScheduledRequestHandlerTest.java
@@ -18,10 +18,10 @@
  */
 package org.apache.pinot.server.request;
 
-import com.google.common.base.Function;
 import com.google.common.base.Preconditions;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.MoreExecutors;
 import com.yammer.metrics.core.MetricsRegistry;
 import java.io.IOException;
 import java.util.Arrays;
@@ -115,8 +115,7 @@ public class ScheduledRequestHandlerTest {
             // Specifying it for less ambiguity.
             ListenableFuture<DataTable> dataTable = resourceManager.getQueryRunners().submit(new Callable<DataTable>() {
               @Override
-              public DataTable call()
-                  throws Exception {
+              public DataTable call() {
                 throw new RuntimeException("query processing error");
               }
             });
@@ -124,7 +123,7 @@ public class ScheduledRequestHandlerTest {
               DataTable result = new DataTableImplV2();
               result.addException(QueryException.INTERNAL_ERROR);
               return result;
-            });
+            }, MoreExecutors.directExecutor());
             return serializeData(queryResponse);
           }
 
@@ -199,13 +198,13 @@ public class ScheduledRequestHandlerTest {
   }
 
   private ListenableFuture<byte[]> serializeData(ListenableFuture<DataTable> dataTable) {
-    return Futures.transform(dataTable, (Function<DataTable, byte[]>) input -> {
+    return Futures.transform(dataTable, input -> {
       try {
         Preconditions.checkNotNull(input);
         return input.toBytes();
       } catch (IOException e) {
         return new byte[0];
       }
-    });
+    }, MoreExecutors.directExecutor());
   }
 }
diff --git a/pinot-transport/src/main/java/org/apache/pinot/transport/netty/NettyServer.java b/pinot-transport/src/main/java/org/apache/pinot/transport/netty/NettyServer.java
index 16f00a8..b2fdcad 100644
--- a/pinot-transport/src/main/java/org/apache/pinot/transport/netty/NettyServer.java
+++ b/pinot-transport/src/main/java/org/apache/pinot/transport/netty/NettyServer.java
@@ -22,6 +22,7 @@ import com.google.common.base.Preconditions;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.MoreExecutors;
 import io.netty.bootstrap.ServerBootstrap;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
@@ -290,7 +291,7 @@ public abstract class NettyServer implements Runnable {
           LOGGER.error("Request processing returned unhandled exception, error: ", t);
           sendResponse(new byte[0]);
         }
-      });
+      }, MoreExecutors.directExecutor());
     }
 
     @Override
diff --git a/pinot-transport/src/test/java/org/apache/pinot/transport/perf/ScatterGatherPerfClient.java b/pinot-transport/src/test/java/org/apache/pinot/transport/perf/ScatterGatherPerfClient.java
index 0783d03..bf4422c 100644
--- a/pinot-transport/src/test/java/org/apache/pinot/transport/perf/ScatterGatherPerfClient.java
+++ b/pinot-transport/src/test/java/org/apache/pinot/transport/perf/ScatterGatherPerfClient.java
@@ -152,9 +152,8 @@ public class ScatterGatherPerfClient implements Runnable {
 
     NettyClientMetrics clientMetrics = new NettyClientMetrics(registry, "client_");
     PooledNettyClientResourceManager rm = new PooledNettyClientResourceManager(_eventLoopGroup, _timer, clientMetrics);
-    _pool =
-        new KeyedPoolImpl<PooledNettyClientResourceManager.PooledClientConnection>(1, _maxActiveConnections, 300000, 10,
-            rm, _timedExecutor, MoreExecutors.sameThreadExecutor(), registry);
+    _pool = new KeyedPoolImpl<>(1, _maxActiveConnections, 300000, 10, rm, _timedExecutor,
+        MoreExecutors.newDirectExecutorService(), registry);
     rm.setPool(_pool);
     _scatterGather = new ScatterGatherImpl(_pool, _service);
     for (AsyncReader r : _readerThreads) {
diff --git a/pinot-transport/src/test/java/org/apache/pinot/transport/pool/AsyncPoolResourceManagerAdapterTest.java b/pinot-transport/src/test/java/org/apache/pinot/transport/pool/AsyncPoolResourceManagerAdapterTest.java
index 1d2feaa..a7c0bf8 100644
--- a/pinot-transport/src/test/java/org/apache/pinot/transport/pool/AsyncPoolResourceManagerAdapterTest.java
+++ b/pinot-transport/src/test/java/org/apache/pinot/transport/pool/AsyncPoolResourceManagerAdapterTest.java
@@ -19,6 +19,7 @@
 package org.apache.pinot.transport.pool;
 
 import com.google.common.util.concurrent.MoreExecutors;
+import java.util.concurrent.ExecutorService;
 import org.apache.pinot.common.response.ServerInstance;
 import org.apache.pinot.transport.common.Callback;
 import org.testng.Assert;
@@ -26,6 +27,7 @@ import org.testng.annotations.Test;
 
 
 public class AsyncPoolResourceManagerAdapterTest {
+  private static final ExecutorService EXECUTOR_SERVICE = MoreExecutors.newDirectExecutorService();
 
   @Test
   public void testCreate() {
@@ -36,7 +38,7 @@ public class AsyncPoolResourceManagerAdapterTest {
       String value = "dummy";
       MyPooledResourceManager rm = new MyPooledResourceManager(true, value);
       AsyncPoolResourceManagerAdapter<String> adapter =
-          new AsyncPoolResourceManagerAdapter<>(key, rm, MoreExecutors.sameThreadExecutor(), null);
+          new AsyncPoolResourceManagerAdapter<>(key, rm, EXECUTOR_SERVICE, null);
       MyCallback callback = new MyCallback();
 
       adapter.create(callback);
@@ -52,7 +54,7 @@ public class AsyncPoolResourceManagerAdapterTest {
       ServerInstance key = new ServerInstance("localhost:8080");
       MyPooledResourceManager rm = new MyPooledResourceManager(true, null);
       AsyncPoolResourceManagerAdapter<String> adapter =
-          new AsyncPoolResourceManagerAdapter<String>(key, rm, MoreExecutors.sameThreadExecutor(), null);
+          new AsyncPoolResourceManagerAdapter<String>(key, rm, EXECUTOR_SERVICE, null);
       MyCallback callback = new MyCallback();
 
       adapter.create(callback);
@@ -72,7 +74,7 @@ public class AsyncPoolResourceManagerAdapterTest {
       String value = "dummy";
       MyPooledResourceManager rm = new MyPooledResourceManager(true, null);
       AsyncPoolResourceManagerAdapter<String> adapter =
-          new AsyncPoolResourceManagerAdapter<>(key, rm, MoreExecutors.sameThreadExecutor(), null);
+          new AsyncPoolResourceManagerAdapter<>(key, rm, EXECUTOR_SERVICE, null);
 
       boolean ret = adapter.validateGet(value);
       Assert.assertTrue(ret, "Validate Return");
@@ -93,7 +95,7 @@ public class AsyncPoolResourceManagerAdapterTest {
       String value = "dummy";
       MyPooledResourceManager rm = new MyPooledResourceManager(false, null);
       AsyncPoolResourceManagerAdapter<String> adapter =
-          new AsyncPoolResourceManagerAdapter<>(key, rm, MoreExecutors.sameThreadExecutor(), null);
+          new AsyncPoolResourceManagerAdapter<>(key, rm, EXECUTOR_SERVICE, null);
 
       boolean ret = adapter.validateGet(value);
       Assert.assertFalse(ret, "Validate Return");
@@ -119,7 +121,7 @@ public class AsyncPoolResourceManagerAdapterTest {
       String value = "dummy";
       MyPooledResourceManager rm = new MyPooledResourceManager(true, null);
       AsyncPoolResourceManagerAdapter<String> adapter =
-          new AsyncPoolResourceManagerAdapter<>(key, rm, MoreExecutors.sameThreadExecutor(), null);
+          new AsyncPoolResourceManagerAdapter<>(key, rm, EXECUTOR_SERVICE, null);
       MyCallback callback = new MyCallback();
 
       adapter.destroy(value, true, callback);
@@ -137,7 +139,7 @@ public class AsyncPoolResourceManagerAdapterTest {
       String value = "dummy";
       MyPooledResourceManager rm = new MyPooledResourceManager(false, null);
       AsyncPoolResourceManagerAdapter<String> adapter =
-          new AsyncPoolResourceManagerAdapter<>(key, rm, MoreExecutors.sameThreadExecutor(), null);
+          new AsyncPoolResourceManagerAdapter<>(key, rm, EXECUTOR_SERVICE, null);
       MyCallback callback = new MyCallback();
 
       adapter.destroy(value, true, callback);
diff --git a/pinot-transport/src/test/java/org/apache/pinot/transport/pool/KeyedPoolImplTest.java b/pinot-transport/src/test/java/org/apache/pinot/transport/pool/KeyedPoolImplTest.java
index 6756090..7c847b8 100644
--- a/pinot-transport/src/test/java/org/apache/pinot/transport/pool/KeyedPoolImplTest.java
+++ b/pinot-transport/src/test/java/org/apache/pinot/transport/pool/KeyedPoolImplTest.java
@@ -38,15 +38,12 @@ import org.apache.pinot.transport.common.AsyncResponseFuture;
 import org.apache.pinot.transport.common.NoneType;
 import org.apache.pinot.transport.common.ServerResponseFuture;
 import org.apache.pinot.transport.metrics.AggregatedPoolStats;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 import org.testng.Assert;
 import org.testng.annotations.Test;
 
 
 public class KeyedPoolImplTest {
-
-  protected static Logger LOGGER = LoggerFactory.getLogger(KeyedPoolImplTest.class);
+  private static final ExecutorService EXECUTOR_SERVICE = MoreExecutors.newDirectExecutorService();
 
   @Test
   public void testCancelAfterCheckingOut()
@@ -152,14 +149,14 @@ public class KeyedPoolImplTest {
   public void testCreateError()
       throws Exception {
     ScheduledExecutorService timedExecutor = new ScheduledThreadPoolExecutor(1);
-    ExecutorService service = MoreExecutors.sameThreadExecutor();
     int numKeys = 1;
     int numResourcesPerKey = 1;
     Map<ServerInstance, List<String>> resources = buildCreateMap(numKeys, numResourcesPerKey);
 
     TestResourceManager rm = new TestResourceManager(resources, resources, null, null);
 
-    KeyedPool<String> kPool = new KeyedPoolImpl<>(0, 1, 1000L, 1000 * 60 * 60, rm, timedExecutor, service, null);
+    KeyedPool<String> kPool =
+        new KeyedPoolImpl<>(0, 1, 1000L, 1000 * 60 * 60, rm, timedExecutor, EXECUTOR_SERVICE, null);
     AsyncResponseFuture<String> f = (AsyncResponseFuture<String>) kPool.checkoutObject(getKey(0), "none");
     Assert.assertTrue(f.isDone());
     Assert.assertNull(f.get());
@@ -175,14 +172,14 @@ public class KeyedPoolImplTest {
   public void testDestroyError()
       throws Exception {
     ScheduledExecutorService timedExecutor = new ScheduledThreadPoolExecutor(1);
-    ExecutorService service = MoreExecutors.sameThreadExecutor();
     int numKeys = 1;
     int numResourcesPerKey = 1;
     Map<ServerInstance, List<String>> resources = buildCreateMap(numKeys, numResourcesPerKey);
 
     TestResourceManager rm = new TestResourceManager(resources, null, resources, null);
 
-    KeyedPool<String> kPool = new KeyedPoolImpl<>(0, 5, 1000L, 1000 * 60 * 60, rm, timedExecutor, service, null);
+    KeyedPool<String> kPool =
+        new KeyedPoolImpl<>(0, 5, 1000L, 1000 * 60 * 60, rm, timedExecutor, EXECUTOR_SERVICE, null);
     AsyncResponseFuture<String> f = (AsyncResponseFuture<String>) kPool.checkoutObject(getKey(0), "none");
     String r = f.getOne();
     Assert.assertTrue(f.isDone());
@@ -216,13 +213,12 @@ public class KeyedPoolImplTest {
    */ public void testTimeout()
       throws Exception {
     ScheduledExecutorService timedExecutor = new ScheduledThreadPoolExecutor(1);
-    ExecutorService service = MoreExecutors.sameThreadExecutor();
     int numKeys = 5;
     int numResourcesPerKey = 1;
     TestResourceManager rm = new TestResourceManager(buildCreateMap(numKeys, numResourcesPerKey), null, null, null);
 
     // Idle Timeout 1 second
-    KeyedPool<String> kPool = new KeyedPoolImpl<>(0, 5, 1000L, 100, rm, timedExecutor, service, null);
+    KeyedPool<String> kPool = new KeyedPoolImpl<>(0, 5, 1000L, 100, rm, timedExecutor, EXECUTOR_SERVICE, null);
 
     // Create a countdown latch that waits for all resources to be deleted
     CountDownLatch latch = new CountDownLatch(numKeys * numResourcesPerKey);
@@ -279,11 +275,11 @@ public class KeyedPoolImplTest {
    */ public void testPoolImpl1()
       throws Exception {
     ScheduledExecutorService timedExecutor = new ScheduledThreadPoolExecutor(1);
-    ExecutorService service = MoreExecutors.sameThreadExecutor();
     int numKeys = 5;
     int numResourcesPerKey = 5;
     TestResourceManager rm = new TestResourceManager(buildCreateMap(numKeys, numResourcesPerKey), null, null, null);
-    KeyedPool<String> kPool = new KeyedPoolImpl<>(5, 5, 1000 * 60 * 60L, 100, rm, timedExecutor, service, null);
+    KeyedPool<String> kPool =
+        new KeyedPoolImpl<>(5, 5, 1000 * 60 * 60L, 100, rm, timedExecutor, EXECUTOR_SERVICE, null);
 
     kPool.start();
     AggregatedPoolStats s = (AggregatedPoolStats) kPool.getStats();
@@ -355,11 +351,11 @@ public class KeyedPoolImplTest {
    */ public void testShutdown()
       throws Exception {
     ScheduledExecutorService timedExecutor = new ScheduledThreadPoolExecutor(1);
-    ExecutorService service = MoreExecutors.sameThreadExecutor();
     int numKeys = 5;
     int numResourcesPerKey = 5;
     TestResourceManager rm = new TestResourceManager(buildCreateMap(numKeys, numResourcesPerKey), null, null, null);
-    KeyedPool<String> kPool = new KeyedPoolImpl<>(5, 5, 1000 * 60 * 60L, 100, rm, timedExecutor, service, null);
+    KeyedPool<String> kPool =
+        new KeyedPoolImpl<>(5, 5, 1000 * 60 * 60L, 100, rm, timedExecutor, EXECUTOR_SERVICE, null);
 
     kPool.start();
     AggregatedPoolStats s = (AggregatedPoolStats) kPool.getStats();
@@ -483,7 +479,6 @@ public class KeyedPoolImplTest {
       } catch (InterruptedException e) {
         e.printStackTrace();
       }
-      LOGGER.info("Create Latch opened. Proceding with creating resource !!");
       return super.create(key);
     }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org