Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package com.facebook.presto.split;
 
 
 import java.net.URI;
 import java.util.List;
 import java.util.Set;
 
 import static com.facebook.presto.spi.type.VarcharType.VARCHAR;
 import static com.facebook.presto.util.ImmutableCollectors.toImmutableSet;
 import static io.airlift.concurrent.MoreFutures.getFutureValue;
 import static java.lang.String.format;
 import static org.testng.Assert.assertEquals;
 
 public class TestJmxSplitManager
 {
     private static final String CONNECTOR_ID = "test_connector";
 
     private final Node localNode = new TestingNode("host1");
     private final Set<Nodenodes = ImmutableSet.of(new TestingNode("host2"), new TestingNode("host3"));
 
     private final JmxColumnHandle columnHandle = new JmxColumnHandle("node", 0);
     private final JmxTableHandle tableHandle = new JmxTableHandle("objectName", ImmutableList.of());
 
     @Test
     public void testPredicatePushdown()
             throws Exception
     {
         for (Node node : ) {
             String nodeIdentifier = node.getNodeIdentifier();
             TupleDomain<ColumnHandlenodeTupleDomain = TupleDomain.withFixedValues(ImmutableMap.of(, Slices.utf8Slice(nodeIdentifier)));
 
             ConnectorPartitionResult connectorPartitionResult = .getPartitions(nodeTupleDomain);
             ConnectorSplitSource splitSource = .getPartitionSplits(connectorPartitionResult.getPartitions());
             List<ConnectorSplitallSplits = getAllSplits(splitSource);
 
             assertEquals(allSplits.size(), 1);
             assertEquals(allSplits.get(0).getAddresses().size(), 1);
             assertEquals(allSplits.get(0).getAddresses().get(0).getHostText(), nodeIdentifier);
         }
     }
 
     @Test
     public void testNoPredicate()
             throws Exception
     {
         ConnectorPartitionResult connectorPartitionResult = .getPartitions(, TupleDomain.all());
         ConnectorSplitSource splitSource = .getPartitionSplits(connectorPartitionResult.getPartitions());
         List<ConnectorSplitallSplits = getAllSplits(splitSource);
         assertEquals(allSplits.size(), .size());
 
         Set<StringactualNodes = .stream().map(Node::getNodeIdentifier).collect(toImmutableSet());
         Set<StringexpectedNodes = new HashSet<>();
         for (ConnectorSplit split : allSplits) {
             List<HostAddressaddresses = split.getAddresses();
             assertEquals(addresses.size(), 1);
             expectedNodes.add(addresses.get(0).getHostText());
         }
         assertEquals(actualNodesexpectedNodes);
     }
 
     private static List<ConnectorSplitgetAllSplits(ConnectorSplitSource splitSource)
             throws InterruptedException
     {
         ImmutableList.Builder<ConnectorSplitsplits = ImmutableList.builder();
         while (!splitSource.isFinished()) {
             List<ConnectorSplitbatch = getFutureValue(splitSource.getNextBatch(1000));
             splits.addAll(batch);
        }
        return splits.build();
    }
    private class TestingNodeManager
            implements NodeManager
    {
        @Override
        public Set<NodegetActiveNodes()
        {
            return ;
        }
        @Override
        public Set<NodegetActiveDatasourceNodes(String datasourceName)
        {
            return ;
        }
        @Override
        public Node getCurrentNode()
        {
            return ;
        }
        @Override
        public Set<NodegetCoordinators()
        {
            return ImmutableSet.of();
        }
    }
    private static class TestingNode
            implements Node
    {
        private final String hostname;
        public TestingNode(String hostname)
        {
            this. = hostname;
        }
        @Override
        public HostAddress getHostAndPort()
        {
            return HostAddress.fromParts(, 8080);
        }
        @Override
        public URI getHttpUri()
        {
            return URI.create(format("http://%s:8080"));
        }
        @Override
        public String getNodeIdentifier()
        {
            return ;
        }
    }
New to GrepCode? Check out our FAQ X