@Test public void testQueryMultipleIndexes() throws Exception { final BasicNodeSelectionPolicy policy = new BasicNodeSelectionPolicy(); final Map<String, List<String>> indexToShards = new HashMap<String, List<String>>(); addIndex(indexToShards, "indexA", "shardA1"); addIndex(indexToShards, "indexB", "shardB1", "shardB2"); addNodes(policy, "shardA1", "node1", "node2"); addNodes(policy, "shardB1", "node1"); addNodes(policy, "shardB2", "node2"); List<String> shards = new ArrayList<String>(); shards.addAll(indexToShards.get("indexA")); shards.addAll(indexToShards.get("indexB")); Map<String, List<String>> nodeShardsMap = policy.createNode2ShardsMap(shards); assertEquals(2, nodeShardsMap.size()); assertEquals(3, extractFoundShards(nodeShardsMap).size()); }
public Map<String, List<String>> createNode2ShardsMap(Collection<String> shards) throws ShardAccessException { One2ManyListMap<String, String> node2ShardsMap = new One2ManyListMap<String, String>(); for (String shard : shards) { CircularList<String> nodeList = _shardsToNodeMap.get(shard); if (nodeList == null) { continue; } if(nodeList.isEmpty()) { throw new ShardAccessException(shard); } String node; synchronized (nodeList) { node = nodeList.getNext(); } node2ShardsMap.add(node, shard); } return node2ShardsMap.asMap(); }
BasicNodeSelectionPolicy implements INodeSelectionPolicy { public Map<String, List<String>> createNode2ShardsMap(Collection<String> shards) throws ShardAccessException { One2ManyListMap<String, String> node2ShardsMap = new One2ManyListMap<String, String>(); for (String shard : shards) { CircularList<String> nodeList = _shardsToNodeMap.get(shard); if (nodeList == null) { continue; } if(nodeList.isEmpty()) { throw new ShardAccessException(shard); } String node; synchronized (nodeList) { node = nodeList.getNext(); } node2ShardsMap.add(node, shard); } return node2ShardsMap.asMap(); } }
BasicNodeSelectionPolicy implements INodeSelectionPolicy { public Map<String, List<String>> createNode2ShardsMap(Collection<String> shards) throws ShardAccessException { One2ManyListMap<String, String> node2ShardsMap = new One2ManyListMap<String, String>(); for (String shard : shards) { CircularList<String> nodeList = _shardsToNodeMap.get(shard); if (nodeList == null) { continue; } if(nodeList.isEmpty()) { throw new ShardAccessException(shard); } String node; synchronized (nodeList) { node = nodeList.getNext(); } node2ShardsMap.add(node, shard); } return node2ShardsMap.asMap(); }  }
BasicNodeSelectionPolicy implements INodeSelectionPolicy { public Map<String, List<String>> createNode2ShardsMap(Collection<String> shards) throws ShardAccessException { One2ManyListMap<String, String> node2ShardsMap = new One2ManyListMap<String, String>(); for (String shard : shards) { CircularList<String> nodeList = _shardsToNodeMap.get(shard); if (nodeList == null) { continue; } if(nodeList.isEmpty()) { throw new ShardAccessException(shard); } String node; synchronized (nodeList) { node = nodeList.getNext(); } node2ShardsMap.add(node, shard); } return node2ShardsMap.asMap(); }  void update(String shard, Collection<String> nodes); @Override Collection<String> getShardNodes(String shard); @Override List<String> remove(String shard); void removeNode(String node); Map<String, List<String>> createNode2ShardsMap(Collection<String> shards); @Override String toString(); }
BasicNodeSelectionPolicy implements INodeSelectionPolicy { public Map<String, List<String>> createNode2ShardsMap(Collection<String> shards) throws ShardAccessException { One2ManyListMap<String, String> node2ShardsMap = new One2ManyListMap<String, String>(); for (String shard : shards) { CircularList<String> nodeList = _shardsToNodeMap.get(shard); if (nodeList == null) { continue; } if(nodeList.isEmpty()) { throw new ShardAccessException(shard); } String node; synchronized (nodeList) { node = nodeList.getNext(); } node2ShardsMap.add(node, shard); } return node2ShardsMap.asMap(); }  void update(String shard, Collection<String> nodes); @Override Collection<String> getShardNodes(String shard); @Override List<String> remove(String shard); void removeNode(String node); Map<String, List<String>> createNode2ShardsMap(Collection<String> shards); @Override String toString();  }