You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@accumulo.apache.org by GitBox <gi...@apache.org> on 2020/03/06 23:14:13 UTC

[GitHub] [accumulo] keith-turner commented on a change in pull request #1552: Fix and simplify TransportCachingIT

keith-turner commented on a change in pull request #1552: Fix and simplify TransportCachingIT
URL: https://github.com/apache/accumulo/pull/1552#discussion_r389188554
 
 

 ##########
 File path: test/src/main/java/org/apache/accumulo/test/TransportCachingIT.java
 ##########
 @@ -18,87 +18,53 @@
  */
 package org.apache.accumulo.test;
 
-import static java.nio.charset.StandardCharsets.UTF_8;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNotSame;
 import static org.junit.Assert.assertSame;
 
-import java.util.ArrayList;
 import java.util.List;
 
-import org.apache.accumulo.core.Constants;
 import org.apache.accumulo.core.client.Accumulo;
 import org.apache.accumulo.core.client.AccumuloClient;
 import org.apache.accumulo.core.clientImpl.ClientContext;
 import org.apache.accumulo.core.clientImpl.ThriftTransportKey;
 import org.apache.accumulo.core.clientImpl.ThriftTransportPool;
 import org.apache.accumulo.core.conf.ConfigurationTypeHelper;
 import org.apache.accumulo.core.conf.Property;
-import org.apache.accumulo.core.util.ServerServices;
-import org.apache.accumulo.core.util.ServerServices.Service;
-import org.apache.accumulo.fate.zookeeper.ZooCache;
+import org.apache.accumulo.core.util.HostAndPort;
 import org.apache.accumulo.harness.AccumuloClusterHarness;
 import org.apache.thrift.transport.TTransport;
 import org.apache.thrift.transport.TTransportException;
 import org.junit.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.common.collect.Lists;
+
 /**
  * Test that {@link ThriftTransportPool} actually adheres to the cachedConnection argument
  */
 public class TransportCachingIT extends AccumuloClusterHarness {
   private static final Logger log = LoggerFactory.getLogger(TransportCachingIT.class);
-  private static int ATTEMPTS = 0;
 
   @Test
   public void testCachedTransport() throws InterruptedException {
     try (AccumuloClient client = Accumulo.newClient().from(getClientProps()).build()) {
-      while (client.instanceOperations().getTabletServers().isEmpty()) {
+
+      List<String> tservers;
+
+      while ((tservers = client.instanceOperations().getTabletServers()).isEmpty()) {
         // sleep until a tablet server is up
         Thread.sleep(50);
       }
+
       ClientContext context = (ClientContext) client;
       long rpcTimeout =
           ConfigurationTypeHelper.getTimeInMillis(Property.GENERAL_RPC_TIMEOUT.getDefaultValue());
 
-      ZooCache zc = context.getZooCache();
-      final String zkRoot = context.getZooKeeperRoot();
-
-      // wait until Zookeeper is populated
-      List<String> children = zc.getChildren(zkRoot + Constants.ZTSERVERS);
-      while (children.isEmpty()) {
-        Thread.sleep(100);
-        children = zc.getChildren(zkRoot + Constants.ZTSERVERS);
-      }
-
-      ArrayList<ThriftTransportKey> servers = new ArrayList<>();
-      while (servers.isEmpty()) {
-        for (String tserver : children) {
-          String path = zkRoot + Constants.ZTSERVERS + "/" + tserver;
-          byte[] data = zc.getLockData(path);
-          if (data != null) {
-            String strData = new String(data, UTF_8);
-            if (!strData.equals("master"))
-              servers.add(new ThriftTransportKey(
-                  new ServerServices(strData).getAddress(Service.TSERV_CLIENT), rpcTimeout,
-                  context));
-          }
-        }
-        ATTEMPTS++;
-        if (!servers.isEmpty())
-          break;
-        else {
-          if (ATTEMPTS < 100) {
-            log.warn("Making another attempt to add ThriftTransportKey servers");
-            Thread.sleep(100);
-          } else {
-            log.error("Failed to add ThriftTransportKey servers - Failing TransportCachingIT test");
-            org.junit.Assert
-                .fail("Failed to add ThriftTransportKey servers - Failing TransportCachingIT test");
-          }
-        }
-      }
+      List<ThriftTransportKey> servers = Lists.transform(tservers,
+          serverStr -> new ThriftTransportKey(HostAndPort.fromString(serverStr), rpcTimeout,
+              context));
 
 Review comment:
   I doubt modernizer would complain because there is no exact analogue.  Using streams requires copying/allocating a new list where Lists.transform does not.  However in this case performance does not matter so using streams is better.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services