Program: 13270
Project: 13270
Buggy source:
@Test public void testDistributedMergeTask() throws Exception {
  ClusterService clusterService=cluster().getInstance(ClusterService.class);
  Functions functions=cluster().getInstance(Functions.class);
  AggregationFunction countAggregation=(AggregationFunction)functions.get(new FunctionIdent(CountAggregation.NAME,ImmutableList.<DataType>of()));
  TransportMergeNodeAction transportMergeNodeAction=cluster().getInstance(TransportMergeNodeAction.class);
  Set<String> nodes=new HashSet<>();
  for (  DiscoveryNode discoveryNode : clusterService.state().nodes()) {
    nodes.add(discoveryNode.getId());
  }
  MergeNode mergeNode=new MergeNode("String_Node_Str",2);
  mergeNode.contextId(UUID.randomUUID());
  mergeNode.executionNodes(nodes);
  mergeNode.inputTypes(Arrays.asList(DataType.NULL,DataType.STRING));
  GroupProjection groupProjection=new GroupProjection();
  groupProjection.keys(Arrays.<Symbol>asList(new InputColumn(1)));
  groupProjection.values(Arrays.asList(new Aggregation(countAggregation.info(),ImmutableList.<Symbol>of(new InputColumn(0)),Aggregation.Step.PARTIAL,Aggregation.Step.FINAL)));
  TopNProjection topNProjection=new TopNProjection(10,0,Arrays.<Symbol>asList(new InputColumn(1)),new boolean[]{false});
  topNProjection.outputs(Arrays.<Symbol>asList(new InputColumn(0),new InputColumn(1)));
  mergeNode.projections(Arrays.asList(groupProjection,topNProjection));
  DataType.Streamer<?>[] mapperOutputStreamer=new DataType.Streamer[]{new AggregationStateStreamer(countAggregation),DataType.STRING.streamer()};
  NoopListener noopListener=new NoopListener();
  DistributedMergeTask task=new DistributedMergeTask(transportMergeNodeAction,mergeNode);
  task.start();
  Iterator<String> iterator=nodes.iterator();
  String firstNode=iterator.next();
  DistributedResultRequest request1=new DistributedResultRequest(mergeNode.contextId(),mapperOutputStreamer);
  request1.rows(new Object[][]{new Object[]{new CountAggregation.CountAggState(){
{
      value=1;
    }
  }
,new BytesRef("String_Node_Str")}});
  DistributedResultRequest request2=new DistributedResultRequest(mergeNode.contextId(),mapperOutputStreamer);
  request2.rows(new Object[][]{new Object[]{new CountAggregation.CountAggState(){
{
      value=1;
    }
  }
,new BytesRef("String_Node_Str")},new Object[]{new CountAggregation.CountAggState(){
{
      value=3;
    }
  }
,new BytesRef("String_Node_Str")},new Object[]{new CountAggregation.CountAggState(){
{
      value=3;
    }
  }
,new BytesRef("String_Node_Str")}});
  transportMergeNodeAction.mergeRows(firstNode,request1,noopListener);
  transportMergeNodeAction.mergeRows(firstNode,request2,noopListener);
  DistributedResultRequest request3=new DistributedResultRequest(mergeNode.contextId(),mapperOutputStreamer);
  request3.rows(new Object[][]{new Object[]{new CountAggregation.CountAggState(){
{
      value=10;
    }
  }
,new BytesRef("String_Node_Str")},new Object[]{new CountAggregation.CountAggState(){
{
      value=20;
    }
  }
,new BytesRef("String_Node_Str")}});
  DistributedResultRequest request4=new DistributedResultRequest(mergeNode.contextId(),mapperOutputStreamer);
  request4.rows(new Object[][]{new Object[]{new CountAggregation.CountAggState(){
{
      value=10;
    }
  }
,new BytesRef("String_Node_Str")},new Object[]{new CountAggregation.CountAggState(){
{
      value=14;
    }
  }
,new BytesRef("String_Node_Str")}});
  String secondNode=iterator.next();
  transportMergeNodeAction.mergeRows(secondNode,request3,noopListener);
  transportMergeNodeAction.mergeRows(secondNode,request4,noopListener);
  assertThat(task.result().size(),is(2));
  Object[][] rows=task.result().get(0).get();
  assertThat(rows.length,is(2));
  assertThat((BytesRef)rows[0][0],is(new BytesRef("String_Node_Str")));
  assertThat((Long)rows[0][1],is(3L));
  assertThat((BytesRef)rows[1][0],is(new BytesRef("String_Node_Str")));
  assertThat((Long)rows[1][1],is(5L));
  rows=task.result().get(1).get();
  assertThat(rows.length,is(2));
  assertThat((BytesRef)rows[0][0],is(new BytesRef("String_Node_Str")));
  assertThat((Long)rows[0][1],is(14L));
  assertThat((BytesRef)rows[1][0],is(new BytesRef("String_Node_Str")));
  assertThat((Long)rows[1][1],is(40L));
}

Fixed version (ground truth):
@Test public void testDistributedMergeTask() throws Exception {
  ClusterService clusterService=cluster().getInstance(ClusterService.class);
  Functions functions=cluster().getInstance(Functions.class);
  AggregationFunction countAggregation=(AggregationFunction)functions.get(new FunctionIdent(CountAggregation.NAME,ImmutableList.<DataType>of()));
  TransportMergeNodeAction transportMergeNodeAction=cluster().getInstance(TransportMergeNodeAction.class);
  Set<String> nodes=new HashSet<>();
  for (  DiscoveryNode discoveryNode : clusterService.state().nodes()) {
    nodes.add(discoveryNode.getId());
  }
  MergeNode mergeNode=new MergeNode("String_Node_Str",2);
  mergeNode.contextId(UUID.randomUUID());
  mergeNode.executionNodes(nodes);
  mergeNode.inputTypes(Arrays.asList(DataType.NULL,DataType.STRING));
  GroupProjection groupProjection=new GroupProjection();
  groupProjection.keys(Arrays.<Symbol>asList(new InputColumn(1)));
  groupProjection.values(Arrays.asList(new Aggregation(countAggregation.info(),ImmutableList.<Symbol>of(new InputColumn(0)),Aggregation.Step.PARTIAL,Aggregation.Step.FINAL)));
  TopNProjection topNProjection=new TopNProjection(10,0,Arrays.<Symbol>asList(new InputColumn(1)),new boolean[]{false});
  topNProjection.outputs(Arrays.<Symbol>asList(new InputColumn(0),new InputColumn(1)));
  mergeNode.projections(Arrays.asList(groupProjection,topNProjection));
  mergeNode.outputTypes(Arrays.asList(DataType.STRING,DataType.NULL));
  DataType.Streamer<?>[] mapperOutputStreamer=new DataType.Streamer[]{new AggregationStateStreamer(countAggregation),DataType.STRING.streamer()};
  NoopListener noopListener=new NoopListener();
  DistributedMergeTask task=new DistributedMergeTask(transportMergeNodeAction,mergeNode);
  task.start();
  Iterator<String> iterator=nodes.iterator();
  String firstNode=iterator.next();
  DistributedResultRequest request1=new DistributedResultRequest(mergeNode.contextId(),mapperOutputStreamer);
  request1.rows(new Object[][]{new Object[]{new CountAggregation.CountAggState(){
{
      value=1;
    }
  }
,new BytesRef("String_Node_Str")}});
  DistributedResultRequest request2=new DistributedResultRequest(mergeNode.contextId(),mapperOutputStreamer);
  request2.rows(new Object[][]{new Object[]{new CountAggregation.CountAggState(){
{
      value=1;
    }
  }
,new BytesRef("String_Node_Str")},new Object[]{new CountAggregation.CountAggState(){
{
      value=3;
    }
  }
,new BytesRef("String_Node_Str")},new Object[]{new CountAggregation.CountAggState(){
{
      value=3;
    }
  }
,new BytesRef("String_Node_Str")}});
  transportMergeNodeAction.mergeRows(firstNode,request1,noopListener);
  transportMergeNodeAction.mergeRows(firstNode,request2,noopListener);
  DistributedResultRequest request3=new DistributedResultRequest(mergeNode.contextId(),mapperOutputStreamer);
  request3.rows(new Object[][]{new Object[]{new CountAggregation.CountAggState(){
{
      value=10;
    }
  }
,new BytesRef("String_Node_Str")},new Object[]{new CountAggregation.CountAggState(){
{
      value=20;
    }
  }
,new BytesRef("String_Node_Str")}});
  DistributedResultRequest request4=new DistributedResultRequest(mergeNode.contextId(),mapperOutputStreamer);
  request4.rows(new Object[][]{new Object[]{new CountAggregation.CountAggState(){
{
      value=10;
    }
  }
,new BytesRef("String_Node_Str")},new Object[]{new CountAggregation.CountAggState(){
{
      value=14;
    }
  }
,new BytesRef("String_Node_Str")}});
  String secondNode=iterator.next();
  transportMergeNodeAction.mergeRows(secondNode,request3,noopListener);
  transportMergeNodeAction.mergeRows(secondNode,request4,noopListener);
  assertThat(task.result().size(),is(2));
  Object[][] rows=task.result().get(0).get();
  assertThat(rows.length,is(2));
  assertThat((BytesRef)rows[0][0],is(new BytesRef("String_Node_Str")));
  assertThat((Long)rows[0][1],is(3L));
  assertThat((BytesRef)rows[1][0],is(new BytesRef("String_Node_Str")));
  assertThat((Long)rows[1][1],is(5L));
  rows=task.result().get(1).get();
  assertThat(rows.length,is(2));
  assertThat((BytesRef)rows[0][0],is(new BytesRef("String_Node_Str")));
  assertThat((Long)rows[0][1],is(14L));
  assertThat((BytesRef)rows[1][0],is(new BytesRef("String_Node_Str")));
  assertThat((Long)rows[1][1],is(40L));
}