public void testBulk() {
    String[] bulkShardActions = new String[] {BulkAction.NAME + "[s]", BulkAction.NAME + "[s][r]"};
    interceptTransportActions(bulkShardActions);

    List<String> indices = new ArrayList<>();
    BulkRequest bulkRequest = new BulkRequest();
    int numIndexRequests = iterations(1, 10);
    for (int i = 0; i < numIndexRequests; i++) {
      String indexOrAlias = randomIndexOrAlias();
      bulkRequest.add(new IndexRequest(indexOrAlias, "type", "id").source("field", "value"));
      indices.add(indexOrAlias);
    }
    int numDeleteRequests = iterations(1, 10);
    for (int i = 0; i < numDeleteRequests; i++) {
      String indexOrAlias = randomIndexOrAlias();
      bulkRequest.add(new DeleteRequest(indexOrAlias, "type", "id"));
      indices.add(indexOrAlias);
    }
    int numUpdateRequests = iterations(1, 10);
    for (int i = 0; i < numUpdateRequests; i++) {
      String indexOrAlias = randomIndexOrAlias();
      bulkRequest.add(new UpdateRequest(indexOrAlias, "type", "id").doc("field1", "value1"));
      indices.add(indexOrAlias);
    }

    internalCluster().clientNodeClient().bulk(bulkRequest).actionGet();

    clearInterceptedActions();
    assertIndicesSubset(indices, bulkShardActions);
  }
 @Override
 public void messageReceived(T request, TransportChannel channel) throws Exception {
   synchronized (InterceptingTransportService.this) {
     if (actions.contains(action)) {
       List<TransportRequest> requestList = requests.get(action);
       if (requestList == null) {
         requestList = new ArrayList<>();
         requestList.add(request);
         requests.put(action, requestList);
       } else {
         requestList.add(request);
       }
     }
   }
   requestHandler.messageReceived(request, channel);
 }
 @Before
 public void setup() {
   int numIndices = iterations(1, 5);
   for (int i = 0; i < numIndices; i++) {
     indices.add("test" + i);
   }
   for (String index : indices) {
     assertAcked(prepareCreate(index).addAlias(new Alias(index + "-alias")));
   }
   ensureGreen();
 }
  public void testMultiGet() {
    String multiGetShardAction = MultiGetAction.NAME + "[shard][s]";
    interceptTransportActions(multiGetShardAction);

    List<String> indices = new ArrayList<>();
    MultiGetRequest multiGetRequest = new MultiGetRequest();
    int numDocs = iterations(1, 30);
    for (int i = 0; i < numDocs; i++) {
      String indexOrAlias = randomIndexOrAlias();
      multiGetRequest.add(indexOrAlias, "type", Integer.toString(i));
      indices.add(indexOrAlias);
    }
    internalCluster().clientNodeClient().multiGet(multiGetRequest).actionGet();

    clearInterceptedActions();
    assertIndicesSubset(indices, multiGetShardAction);
  }
 public TransportClientNodesService addTransportAddresses(TransportAddress... transportAddresses) {
   synchronized (mutex) {
     if (closed) {
       throw new ElasticsearchIllegalStateException(
           "transport client is closed, can't add an address");
     }
     List<TransportAddress> filtered =
         Lists.newArrayListWithExpectedSize(transportAddresses.length);
     for (TransportAddress transportAddress : transportAddresses) {
       boolean found = false;
       for (DiscoveryNode otherNode : listedNodes) {
         if (otherNode.address().equals(transportAddress)) {
           found = true;
           logger.debug(
               "address [{}] already exists with [{}], ignoring...", transportAddress, otherNode);
           break;
         }
       }
       if (!found) {
         filtered.add(transportAddress);
       }
     }
     if (filtered.isEmpty()) {
       return this;
     }
     ImmutableList.Builder<DiscoveryNode> builder = ImmutableList.builder();
     builder.addAll(listedNodes());
     for (TransportAddress transportAddress : filtered) {
       DiscoveryNode node =
           new DiscoveryNode(
               "#transport#-" + tempNodeIdGenerator.incrementAndGet(),
               transportAddress,
               minCompatibilityVersion);
       logger.debug("adding address [{}]", node);
       builder.add(node);
     }
     listedNodes = builder.build();
     nodesSampler.sample();
   }
   return this;
 }