lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a.@apache.org
Subject [37/45] lucene-solr:jira/solr-11285-sim: SOLR-11285: Make the API less confusing, and reuse existing ClusterStateProvider abstraction.
Date Wed, 04 Oct 2017 14:43:33 GMT
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/efa281e8/solr/solrj/src/test/org/apache/solr/client/solrj/cloud/autoscaling/TestPolicy.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/cloud/autoscaling/TestPolicy.java
b/solr/solrj/src/test/org/apache/solr/client/solrj/cloud/autoscaling/TestPolicy.java
index 80621cb..08b8e7c 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/cloud/autoscaling/TestPolicy.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/cloud/autoscaling/TestPolicy.java
@@ -25,9 +25,11 @@ import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import com.google.common.collect.ImmutableList;
 import org.apache.solr.SolrTestCaseJ4;
@@ -35,8 +37,8 @@ import org.apache.solr.client.solrj.SolrRequest;
 import org.apache.solr.client.solrj.SolrResponse;
 import org.apache.solr.client.solrj.cloud.autoscaling.Clause.Violation;
 import org.apache.solr.client.solrj.cloud.autoscaling.Policy.Suggester.Hint;
+import org.apache.solr.client.solrj.impl.ClusterStateProvider;
 import org.apache.solr.client.solrj.request.CollectionAdminRequest;
-import org.apache.solr.cloud.autoscaling.TriggerEvent;
 import org.apache.solr.common.cloud.Replica;
 import org.apache.solr.common.cloud.ReplicaPosition;
 import org.apache.solr.common.cloud.ZkStateReader;
@@ -270,7 +272,7 @@ public class TestPolicy extends SolrTestCaseJ4 {
         "           'precision':100}]}";
 
     Policy policy = new Policy((Map<String, Object>) Utils.fromJSONString(autoScalingjson));
-    Policy.Session session = policy.createSession(dataProviderWithData(dataproviderdata));
+    Policy.Session session = policy.createSession(cloudManagerWithData(dataproviderdata));
     SolrRequest op = session.getSuggester(MOVEREPLICA).hint(Hint.SRC_NODE, "127.0.0.1:65427_solr").getOperation();
     assertNotNull(op);
     assertEquals( "127.0.0.1:65434_solr",op.getParams().get("targetNode") );
@@ -292,7 +294,7 @@ public class TestPolicy extends SolrTestCaseJ4 {
         "      'freedisk':884.7097854614258}," +
         "}";
 
-    ClusterDataProvider provider = getClusterDataProvider((Map<String, Map>) Utils.fromJSONString(nodeValues),
clusterState);
+    SolrCloudManager provider = getSolrCloudManager((Map<String, Map>) Utils.fromJSONString(nodeValues),
clusterState);
     Map policies = (Map) Utils.fromJSONString("{" +
         "  'cluster-preferences': [" +
         "    { 'maximize': 'freedisk', 'precision': 50}," +
@@ -409,7 +411,7 @@ public class TestPolicy extends SolrTestCaseJ4 {
     assertEquals("r1", operation.getParams().get("replica"));
   }
 
-  private static ClusterDataProvider dataProviderWithData(String data){
+  private static SolrCloudManager cloudManagerWithData(String data) {
     final Map m = (Map) Utils.fromJSONString(data);
     Map replicaInfo = (Map) m.get("replicaInfo");
     replicaInfo.forEach((node, val) -> {
@@ -429,29 +431,32 @@ public class TestPolicy extends SolrTestCaseJ4 {
       });
 
     });
-    return new DelegatingClusterDataProvider(null) {
+    return new DelegatingCloudManager(null) {
       @Override
-      public Map<String, Object> getNodeValues(String node, Collection<String>
tags) {
-        return (Map<String, Object>) Utils.getObjectByPath(m,false, Arrays.asList("nodeValues",
node));
-      }
-
-      @Override
-      public Map<String, Map<String, List<ReplicaInfo>>> getReplicaInfo(String
node, Collection<String> keys) {
-        return (Map<String, Map<String, List<ReplicaInfo>>>) Utils.getObjectByPath(m,false,
Arrays.asList("replicaInfo", node));
+      public ClusterStateProvider getClusterStateProvider() {
+        return new DelegatingClusterStateProvider(null) {
+          @Override
+          public Set<String> getLiveNodes() {
+            return new HashSet<>((Collection<String>) m.get("liveNodes"));
+          }
+        };
       }
 
       @Override
-      public Collection<String> getLiveNodes() {
-        return (Collection<String>) m.get("liveNodes");
-      }
+      public NodeStateProvider getNodeStateProvider() {
+        return new DelegatingNodeStateProvider(null) {
+          @Override
+          public Map<String, Object> getNodeValues(String node, Collection<String>
tags) {
+            return (Map<String, Object>) Utils.getObjectByPath(m,false, Arrays.asList("nodeValues",
node));
+          }
 
-      @Override
-      public String getPolicyNameByCollection(String coll) {
-        return null;
+          @Override
+          public Map<String, Map<String, List<ReplicaInfo>>> getReplicaInfo(String
node, Collection<String> keys) {
+            return (Map<String, Map<String, List<ReplicaInfo>>>) Utils.getObjectByPath(m,false,
Arrays.asList("replicaInfo", node));
+          }
+        };
       }
     };
-
-
   }
 
   public void testPolicyWithReplicaType() {
@@ -474,7 +479,7 @@ public class TestPolicy extends SolrTestCaseJ4 {
         "node4:{cores:8, freedisk: 375, heapUsage:16900, nodeRole:overseer, rack: rack1}"
+
         "}");
     Policy policy = new Policy(policies);
-    Policy.Suggester suggester = policy.createSession(getClusterDataProvider(nodeValues,
clusterState))
+    Policy.Suggester suggester = policy.createSession(getSolrCloudManager(nodeValues, clusterState))
         .getSuggester(ADDREPLICA)
         .hint(Hint.COLL_SHARD, new Pair("newColl", "shard1"))
         .hint(Hint.REPLICATYPE, Replica.Type.PULL);
@@ -614,7 +619,7 @@ public class TestPolicy extends SolrTestCaseJ4 {
         "  'tlogReplicas':'0'}\n" +
         "}";
     Policy policy = new Policy(new HashMap<>());
-    Policy.Suggester suggester = policy.createSession(getClusterDataProvider(nodeValues,
clusterState))
+    Policy.Suggester suggester = policy.createSession(getSolrCloudManager(nodeValues, clusterState))
         .getSuggester(MOVEREPLICA)
         .hint(Hint.COLL, "collection1")
         .hint(Hint.COLL, "collection2")
@@ -670,7 +675,7 @@ public class TestPolicy extends SolrTestCaseJ4 {
         "node4:{cores:8, freedisk: 375, heapUsage:16900, nodeRole:overseer, rack: rack1}"
+
         "}");
     Policy policy = new Policy(policies);
-    Policy.Suggester suggester = policy.createSession(getClusterDataProvider(nodeValues,
clusterState))
+    Policy.Suggester suggester = policy.createSession(getSolrCloudManager(nodeValues, clusterState))
         .getSuggester(ADDREPLICA)
         .hint(Hint.REPLICATYPE, Replica.Type.PULL)
         .hint(Hint.COLL_SHARD, new Pair<>("newColl", "shard1"))
@@ -798,7 +803,7 @@ public class TestPolicy extends SolrTestCaseJ4 {
 
     Policy policy = new Policy((Map<String, Object>) Utils.fromJSONString(rules));
     Policy.Session session;
-    session = policy.createSession(getClusterDataProvider(nodeValues, clusterState));
+    session = policy.createSession(getSolrCloudManager(nodeValues, clusterState));
 
     List<Row> l = session.getSorted();
     assertEquals("node1", l.get(0).node);
@@ -825,7 +830,7 @@ public class TestPolicy extends SolrTestCaseJ4 {
         "node5:{cores:0, freedisk: 895, heapUsage:17834}," +
         "node4:{cores:8, freedisk: 375, heapUsage:16900, nodeRole:overseer}" +
         "}");
-    session = policy.createSession(getClusterDataProvider(nodeValues, clusterState));
+    session = policy.createSession(getSolrCloudManager(nodeValues, clusterState));
     SolrRequest opReq = session.getSuggester(MOVEREPLICA)
         .hint(Hint.TARGET_NODE, "node5")
         .getOperation();
@@ -858,7 +863,7 @@ public class TestPolicy extends SolrTestCaseJ4 {
         "      'freedisk':884.7097854614258}," +
         "}";
 
-    ClusterDataProvider provider = getClusterDataProvider((Map<String, Map>) Utils.fromJSONString(nodeValues),
clusterState);
+    SolrCloudManager provider = getSolrCloudManager((Map<String, Map>) Utils.fromJSONString(nodeValues),
clusterState);
     Map policies = (Map) Utils.fromJSONString("{" +
         "  'cluster-preferences': [" +
         "    { 'maximize': 'freedisk', 'precision': 50}," +
@@ -871,34 +876,7 @@ public class TestPolicy extends SolrTestCaseJ4 {
         "}");
     AutoScalingConfig config = new AutoScalingConfig(policies);
 
-    SolrCloudDataProvider dataProvider = new SolrCloudDataProvider() {
-      @Override
-      public ClusterDataProvider getClusterDataProvider() {
-        return provider;
-      }
-
-      @Override
-      public DistribStateManager getDistribStateManager() {
-        return null;
-      }
-
-      @Override
-      public DistributedQueueFactory getDistributedQueueFactory() {
-        return null;
-      }
-
-      @Override
-      public SolrResponse request(SolrRequest req) throws IOException {
-        return null;
-      }
-
-      @Override
-      public byte[] httpRequest(String url, SolrRequest.METHOD method, Map<String, String>
headers, String payload, int timeout, boolean followRedirects) throws IOException {
-        return new byte[0];
-      }
-    };
-
-    List<ReplicaPosition> locations = PolicyHelper.getReplicaLocations("c", config,
dataProvider, null,
+    List<ReplicaPosition> locations = PolicyHelper.getReplicaLocations("c", config,
provider, null,
         Arrays.asList("s1", "s2"), 1, 0, 0,
         null);
 
@@ -912,7 +890,7 @@ public class TestPolicy extends SolrTestCaseJ4 {
     ref1Copy.decref(sessionRefVersion);
     PolicyHelper.SESSION_REF.set(ref1);
     AutoScalingConfig config2 = new AutoScalingConfig(policies);
-    locations = PolicyHelper.getReplicaLocations("c2", config2, dataProvider, null, Arrays.asList("s1",
"s2"), 1, 0, 0,
+    locations = PolicyHelper.getReplicaLocations("c2", config2, provider, null, Arrays.asList("s1",
"s2"), 1, 0, 0,
         null);
     sessionRefVersion =  PolicyHelper.REF_VERSION.get();
     ref1Copy = PolicyHelper.SESSION_REF.get();
@@ -926,7 +904,7 @@ public class TestPolicy extends SolrTestCaseJ4 {
     ref1.decref(sessionRefVersion);//decref 1
     ref1.decref(sessionRefVersion);//decref 2
     PolicyHelper.SESSION_REF.set(ref1);
-    locations = PolicyHelper.getReplicaLocations("c3", config2, dataProvider, null, Arrays.asList("s1",
"s2"), 1, 0, 0,
+    locations = PolicyHelper.getReplicaLocations("c3", config2, provider, null, Arrays.asList("s1",
"s2"), 1, 0, 0,
         null);
     sessionRefVersion =  PolicyHelper.REF_VERSION.get();
     ref1Copy = PolicyHelper.SESSION_REF.get();
@@ -953,8 +931,8 @@ public class TestPolicy extends SolrTestCaseJ4 {
         "node4:{cores:8, freedisk: 375, heapUsage:16900, nodeRole:overseer, rack: rack1}"
+
         "}");
     Policy policy = new Policy((Map<String, Object>) Utils.fromJSONString(autoscaleJson));
-    ClusterDataProvider clusterDataProvider = getClusterDataProvider(nodeValues, clusterState);
-    Policy.Session session = policy.createSession(clusterDataProvider);
+    SolrCloudManager cloudManager = getSolrCloudManager(nodeValues, clusterState);
+    Policy.Session session = policy.createSession(cloudManager);
     for (int i = 0; i < 3; i++) {
       Policy.Suggester suggester = session.getSuggester(ADDREPLICA);
       SolrRequest op = suggester
@@ -985,29 +963,8 @@ public class TestPolicy extends SolrTestCaseJ4 {
         "}");
 
     Policy policy = new Policy((Map<String, Object>) Utils.fromJSONString(autoscaleJson));
-    ClusterDataProvider clusterDataProvider = getClusterDataProvider(nodeValues, clusterState);
-    ClusterDataProvider cdp = new DelegatingClusterDataProvider(null) {
-      @Override
-      public Map<String, Object> getNodeValues(String node, Collection<String>
tags) {
-        return clusterDataProvider.getNodeValues(node, tags);
-      }
-
-      @Override
-      public Map<String, Map<String, List<ReplicaInfo>>> getReplicaInfo(String
node, Collection<String> keys) {
-        return clusterDataProvider.getReplicaInfo(node, keys);
-      }
-
-      @Override
-      public Collection<String> getLiveNodes() {
-        return clusterDataProvider.getLiveNodes();
-      }
-
-      @Override
-      public String getPolicyNameByCollection(String coll) {
-        return null;
-      }
-    };
-    Policy.Session session = policy.createSession(cdp);
+    SolrCloudManager cloudManager = getSolrCloudManager(nodeValues, clusterState);
+    Policy.Session session = policy.createSession(cloudManager);
     Policy.Suggester suggester = session.getSuggester(ADDREPLICA);
     SolrRequest op = suggester
         .hint(Hint.COLL_SHARD, new Pair<>("newColl", "shard1"))
@@ -1061,28 +1018,33 @@ public class TestPolicy extends SolrTestCaseJ4 {
         "            'freedisk':918005641216}}}");
 
     Policy policy = new Policy((Map<String, Object>) Utils.fromJSONString(autoscaleJson));
-    Policy.Session session = policy.createSession(new DelegatingClusterDataProvider(null)
{
+    Policy.Session session = policy.createSession(new DelegatingCloudManager(null) {
       @Override
-      public Map<String, Object> getNodeValues(String node, Collection<String>
tags) {
-        return tagsMap.get(node);
-      }
+      public ClusterStateProvider getClusterStateProvider() {
+        return new DelegatingClusterStateProvider(null) {
+          @Override
+          public Set<String> getLiveNodes() {
+            return replicaInfoMap.keySet();
+          }
 
-      @Override
-      public Map<String, Map<String, List<ReplicaInfo>>> getReplicaInfo(String
node, Collection<String> keys) {
-        return (Map<String, Map<String, List<ReplicaInfo>>>) replicaInfoMap.get(node);
+        };
       }
 
       @Override
-      public Collection<String> getLiveNodes() {
-        return replicaInfoMap.keySet();
-      }
+      public NodeStateProvider getNodeStateProvider() {
+        return new DelegatingNodeStateProvider(null) {
+          @Override
+          public Map<String, Object> getNodeValues(String node, Collection<String>
tags) {
+            return tagsMap.get(node);
+          }
 
-      @Override
-      public String getPolicyNameByCollection(String coll) {
-        return null;
+          @Override
+          public Map<String, Map<String, List<ReplicaInfo>>> getReplicaInfo(String
node, Collection<String> keys) {
+            return (Map<String, Map<String, List<ReplicaInfo>>>) replicaInfoMap.get(node);
+          }
+        };
       }
     });
-
     Policy.Suggester suggester = session.getSuggester(MOVEREPLICA)
         .hint(Hint.TARGET_NODE, "127.0.0.1:60099_solr");
     SolrRequest op = suggester.getOperation();
@@ -1118,27 +1080,39 @@ public class TestPolicy extends SolrTestCaseJ4 {
         "node4:{cores:8, freedisk: 375, heapUsage:16900, nodeRole:overseer, sysprop.rack:
rack1}" +
         "}");
     Policy policy = new Policy((Map<String, Object>) Utils.fromJSONString(rules));
-    ClusterDataProvider clusterDataProvider = getClusterDataProvider(nodeValues, clusterState);
-    ClusterDataProvider cdp = new DelegatingClusterDataProvider(null) {
+    SolrCloudManager cloudManager = getSolrCloudManager(nodeValues, clusterState);
+    SolrCloudManager cdp = new DelegatingCloudManager(null) {
       @Override
-      public Map<String, Object> getNodeValues(String node, Collection<String>
tags) {
-        return clusterDataProvider.getNodeValues(node, tags);
-      }
+      public NodeStateProvider getNodeStateProvider() {
+        return new DelegatingNodeStateProvider(null) {
+          @Override
+          public Map<String, Object> getNodeValues(String node, Collection<String>
tags) {
+            return cloudManager.getNodeStateProvider().getNodeValues(node, tags);
+          }
 
-      @Override
-      public Map<String, Map<String, List<ReplicaInfo>>> getReplicaInfo(String
node, Collection<String> keys) {
-        return clusterDataProvider.getReplicaInfo(node, keys);
+          @Override
+          public Map<String, Map<String, List<ReplicaInfo>>> getReplicaInfo(String
node, Collection<String> keys) {
+            return cloudManager.getNodeStateProvider().getReplicaInfo(node, keys);
+          }
+        };
       }
 
       @Override
-      public Collection<String> getLiveNodes() {
-        return clusterDataProvider.getLiveNodes();
-      }
+      public ClusterStateProvider getClusterStateProvider() {
+        return new DelegatingClusterStateProvider(null) {
+          @Override
+          public Set<String> getLiveNodes() {
+            return cloudManager.getClusterStateProvider().getLiveNodes();
+          }
 
-      @Override
-      public String getPolicyNameByCollection(String coll) {
-        return "p1";
+          @Override
+          public String getPolicyNameByCollection(String coll) {
+            return "p1";
+          }
+        };
       }
+
+
     };
     Policy.Session session = policy.createSession(cdp);
 
@@ -1149,32 +1123,58 @@ public class TestPolicy extends SolrTestCaseJ4 {
     assertEquals("node2", op.getNode());
   }
 
-  private ClusterDataProvider getClusterDataProvider(final Map<String, Map> nodeValues,
String clusterState) {
-    return new DelegatingClusterDataProvider(null) {
+  private SolrCloudManager getSolrCloudManager(final Map<String, Map> nodeValues, String
clusterState) {
+    return new SolrCloudManager() {
       @Override
-      public Map<String, Object> getNodeValues(String node, Collection<String>
tags) {
-        Map<String, Object> result = new LinkedHashMap<>();
-        tags.stream().forEach(s -> result.put(s, nodeValues.get(node).get(s)));
-        return result;
+      public ClusterStateProvider getClusterStateProvider() {
+        return new DelegatingClusterStateProvider(null) {
+          @Override
+          public Set<String> getLiveNodes() {
+            return nodeValues.keySet();
+          }
+
+        };
+      }
+
+      @Override
+      public NodeStateProvider getNodeStateProvider() {
+        return new DelegatingNodeStateProvider(null) {
+          @Override
+          public Map<String, Object> getNodeValues(String node, Collection<String>
tags) {
+            Map<String, Object> result = new LinkedHashMap<>();
+            tags.stream().forEach(s -> result.put(s, nodeValues.get(node).get(s)));
+            return result;
+          }
+
+          @Override
+          public Map<String, Map<String, List<ReplicaInfo>>> getReplicaInfo(String
node, Collection<String> keys) {
+            return getReplicaDetails(node, clusterState);
+          }
+        };
       }
 
       @Override
-      public Collection<String> getLiveNodes() {
-        return nodeValues.keySet();
+      public DistribStateManager getDistribStateManager() {
+        return null;
       }
 
       @Override
-      public String getPolicyNameByCollection(String coll) {
+      public DistributedQueueFactory getDistributedQueueFactory() {
         return null;
       }
 
       @Override
-      public Map<String, Map<String, List<ReplicaInfo>>> getReplicaInfo(String
node, Collection<String> keys) {
-        return getReplicaDetails(node, clusterState);
+      public SolrResponse request(SolrRequest req) throws IOException {
+        return null;
       }
 
+      @Override
+      public byte[] httpRequest(String url, SolrRequest.METHOD method, Map<String, String>
headers, String payload, int timeout, boolean followRedirects) throws IOException {
+        return new byte[0];
+      }
     };
   }
+
   public void testEmptyClusterState(){
     String autoScaleJson =  " {'policies':{'c1':[{" +
         "        'replica':1," +
@@ -1187,53 +1187,32 @@ public class TestPolicy extends SolrTestCaseJ4 {
         "    '127.0.0.1:50096_solr':{" +
         "      'cores':0," +
         "      'port':'50096'}}");
-    ClusterDataProvider provider = new DelegatingClusterDataProvider(null) {
-      @Override
-      public Map<String, Object> getNodeValues(String node, Collection<String>
keys) {
-        Map<String, Object> result = new LinkedHashMap<>();
-        keys.stream().forEach(s -> result.put(s, nodeValues.get(node).get(s)));
-        return result;
-      }
-
-      @Override
-      public Map<String, Map<String, List<ReplicaInfo>>> getReplicaInfo(String
node, Collection<String> keys) {
-        return getReplicaDetails(node, clusterState);
-      }
-
-      @Override
-      public String getPolicyNameByCollection(String coll) {
-        return null;
-      }
-
-      @Override
-      public Collection<String> getLiveNodes() {
-        return Arrays.asList( "127.0.0.1:50097_solr", "127.0.0.1:50096_solr");
-      }
-    };
-    SolrCloudDataProvider dataProvider = new SolrCloudDataProvider() {
+    SolrCloudManager dataProvider = new DelegatingCloudManager(null) {
       @Override
-      public ClusterDataProvider getClusterDataProvider() {
-        return provider;
-      }
-
-      @Override
-      public DistribStateManager getDistribStateManager() {
-        return null;
-      }
-
-      @Override
-      public DistributedQueueFactory getDistributedQueueFactory() {
-        return null;
+      public ClusterStateProvider getClusterStateProvider() {
+        return new DelegatingClusterStateProvider(null) {
+          @Override
+          public Set<String> getLiveNodes() {
+            return new HashSet<>(Arrays.asList( "127.0.0.1:50097_solr", "127.0.0.1:50096_solr"));
+          }
+        };
       }
 
       @Override
-      public SolrResponse request(SolrRequest req) throws IOException {
-        return null;
-      }
+      public NodeStateProvider getNodeStateProvider() {
+        return new DelegatingNodeStateProvider(null) {
+          @Override
+          public Map<String, Object> getNodeValues(String node, Collection<String>
keys) {
+            Map<String, Object> result = new LinkedHashMap<>();
+            keys.stream().forEach(s -> result.put(s, nodeValues.get(node).get(s)));
+            return result;
+          }
 
-      @Override
-      public byte[] httpRequest(String url, SolrRequest.METHOD method, Map<String, String>
headers, String payload, int timeout, boolean followRedirects) throws IOException {
-        return new byte[0];
+          @Override
+          public Map<String, Map<String, List<ReplicaInfo>>> getReplicaInfo(String
node, Collection<String> keys) {
+            return getReplicaDetails(node, clusterState);
+          }
+        };
       }
     };
     List<ReplicaPosition> locations = PolicyHelper.getReplicaLocations(
@@ -1270,58 +1249,37 @@ public class TestPolicy extends SolrTestCaseJ4 {
         "node4:{cores:0, freedisk: 900, heap:16900, nodeRole:overseer, sysprop.rack:rack2}"
+
         "}");
 
-    ClusterDataProvider provider = new DelegatingClusterDataProvider(null) {
+    SolrCloudManager cloudManager = new DelegatingCloudManager(null) {
       @Override
-      public Map<String, Object> getNodeValues(String node, Collection<String>
keys) {
-        Map<String, Object> result = new LinkedHashMap<>();
-        keys.stream().forEach(s -> result.put(s, nodeValues.get(node).get(s)));
-        return result;
-      }
-
-      @Override
-      public Map<String, Map<String, List<ReplicaInfo>>> getReplicaInfo(String
node, Collection<String> keys) {
-        return getReplicaDetails(node, clusterState);
-      }
-
-      @Override
-      public String getPolicyNameByCollection(String coll) {
-        return null;
-      }
-
-      @Override
-      public Collection<String> getLiveNodes() {
-        return Arrays.asList("node1", "node2", "node3", "node4");
-      }
-    };
-    SolrCloudDataProvider dataProvider = new SolrCloudDataProvider() {
-      @Override
-      public ClusterDataProvider getClusterDataProvider() {
-        return provider;
-      }
-
-      @Override
-      public DistribStateManager getDistribStateManager() {
-        return null;
-      }
-
-      @Override
-      public DistributedQueueFactory getDistributedQueueFactory() {
-        return null;
-      }
+      public NodeStateProvider getNodeStateProvider() {
+        return new DelegatingNodeStateProvider(null) {
+          @Override
+          public Map<String, Object> getNodeValues(String node, Collection<String>
keys) {
+            Map<String, Object> result = new LinkedHashMap<>();
+            keys.stream().forEach(s -> result.put(s, nodeValues.get(node).get(s)));
+            return result;
+          }
 
-      @Override
-      public SolrResponse request(SolrRequest req) throws IOException {
-        return null;
+          @Override
+          public Map<String, Map<String, List<ReplicaInfo>>> getReplicaInfo(String
node, Collection<String> keys) {
+            return getReplicaDetails(node, clusterState);
+          }
+        };
       }
 
       @Override
-      public byte[] httpRequest(String url, SolrRequest.METHOD method, Map<String, String>
headers, String payload, int timeout, boolean followRedirects) throws IOException {
-        return new byte[0];
+      public ClusterStateProvider getClusterStateProvider() {
+        return new DelegatingClusterStateProvider(null) {
+          @Override
+          public Set<String> getLiveNodes() {
+            return new HashSet<>(Arrays.asList("node1", "node2", "node3", "node4"));
+          }
+        };
       }
     };
     List<ReplicaPosition> locations = PolicyHelper.getReplicaLocations(
         "newColl", new AutoScalingConfig((Map<String, Object>) Utils.fromJSONString(autoScaleJson)),
-        dataProvider, Collections.singletonMap("newColl", "policy1"), Arrays.asList("shard1",
"shard2"), 3,0,0, null);
+        cloudManager, Collections.singletonMap("newColl", "policy1"), Arrays.asList("shard1",
"shard2"), 3,0,0, null);
     assertTrue(locations.stream().allMatch(it -> ImmutableList.of("node2", "node1", "node3").contains(it.node))
);
   }
 
@@ -1348,7 +1306,7 @@ public class TestPolicy extends SolrTestCaseJ4 {
         "    {      'nodeRole':'overseer','replica':0}]," +
         "  'cluster-preferences':[{'minimize':'cores'}]}";
     Policy policy = new Policy((Map<String, Object>) Utils.fromJSONString(autoScalingjson));
-    Policy.Session session = policy.createSession(dataProviderWithData(dataproviderdata));
+    Policy.Session session = policy.createSession(cloudManagerWithData(dataproviderdata));
     Policy.Suggester suggester = session.getSuggester(MOVEREPLICA).hint(Hint.TARGET_NODE,
"10.0.0.6:7574_solr");
     SolrRequest op = suggester.getOperation();
     assertNotNull(op);
@@ -1385,7 +1343,7 @@ public class TestPolicy extends SolrTestCaseJ4 {
         "       {replica:'<2', shard:'#EACH',node:'#ANY'}," +
         "       { nodeRole:overseer,replica:0}]}";
     Policy policy = new Policy((Map<String, Object>) Utils.fromJSONString(autoScalingjson));
-    Policy.Session session = policy.createSession(dataProviderWithData(dataproviderdata));
+    Policy.Session session = policy.createSession(cloudManagerWithData(dataproviderdata));
     Policy.Suggester suggester = session.getSuggester(CollectionParams.CollectionAction.MOVEREPLICA)
         .hint(Hint.TARGET_NODE, "127.0.0.1:51147_solr");
     SolrRequest op = suggester.getOperation();

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/efa281e8/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientCacheTest.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientCacheTest.java
b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientCacheTest.java
index 0a83138..77421ed 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientCacheTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientCacheTest.java
@@ -32,6 +32,7 @@ import java.util.function.Function;
 import com.google.common.collect.ImmutableSet;
 import org.apache.http.NoHttpResponseException;
 import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.client.solrj.cloud.autoscaling.DelegatingClusterStateProvider;
 import org.apache.solr.client.solrj.request.UpdateRequest;
 import org.apache.solr.common.cloud.ClusterState;
 import org.apache.solr.common.cloud.DocCollection;
@@ -119,14 +120,14 @@ public class CloudSolrClientCacheTest extends SolrTestCaseJ4 {
 
   private ClusterStateProvider getStateProvider(Set<String> livenodes,
                                                                 Map<String, ClusterState.CollectionRef>
colls) {
-    return new ClusterStateProvider() {
+    return new DelegatingClusterStateProvider(null) {
       @Override
       public ClusterState.CollectionRef getState(String collection) {
         return colls.get(collection);
       }
 
       @Override
-      public Set<String> liveNodes() {
+      public Set<String> getLiveNodes() {
         return livenodes;
       }
 
@@ -141,20 +142,7 @@ public class CloudSolrClientCacheTest extends SolrTestCaseJ4 {
       }
 
       @Override
-      public void connect() { }
-
-      @Override
-      public void close() throws IOException {
-
-      }
-
-      @Override
-      public Object getClusterProperty(String propertyName) {
-        return null;
-      }
-
-      @Override
-      public Object getClusterProperty(String propertyName, String def) {
+      public <T> T getClusterProperty(String propertyName, T def) {
         return def;
       }
     };


Mime
View raw message