Program: 5587
Project: 5587
Buggy source:
@Test public void testSearchResultPagination() throws Exception {
  NamespaceId namespace=new NamespaceId("String_Node_Str");
  namespaceClient.create(new NamespaceMeta.Builder().setName(namespace).build());
  StreamId stream=namespace.stream("String_Node_Str");
  DatasetId dataset=namespace.dataset("String_Node_Str");
  StreamViewId view=stream.view("String_Node_Str");
  streamClient.create(stream);
  streamViewClient.createOrUpdate(view,new ViewSpecification(new FormatSpecification("String_Node_Str",null,null)));
  datasetClient.create(dataset,new DatasetInstanceConfiguration(Table.class.getName(),Collections.<String,String>emptyMap()));
  EnumSet<MetadataSearchTargetType> targets=EnumSet.allOf(MetadataSearchTargetType.class);
  String sort=AbstractSystemMetadataWriter.ENTITY_NAME_KEY + "String_Node_Str";
  MetadataSearchResponse searchResponse=searchMetadata(namespace,"String_Node_Str",targets,sort,0,1,0,null);
  List<MetadataSearchResultRecord> expectedResults=ImmutableList.of(new MetadataSearchResultRecord(dataset));
  List<String> expectedCursors=ImmutableList.of();
  Assert.assertEquals(expectedResults,new ArrayList<>(searchResponse.getResults()));
  Assert.assertEquals(expectedCursors,searchResponse.getCursors());
  searchResponse=searchMetadata(namespace,"String_Node_Str",targets,sort,0,1,2,null);
  expectedResults=ImmutableList.of(new MetadataSearchResultRecord(dataset));
  expectedCursors=ImmutableList.of(stream.getEntityName(),view.getEntityName());
  Assert.assertEquals(expectedResults,new ArrayList<>(searchResponse.getResults()));
  Assert.assertEquals(expectedCursors,searchResponse.getCursors());
  searchResponse=searchMetadata(namespace,"String_Node_Str",targets,sort,1,1,2,null);
  expectedResults=ImmutableList.of(new MetadataSearchResultRecord(stream));
  expectedCursors=ImmutableList.of(view.getEntityName());
  Assert.assertEquals(expectedResults,new ArrayList<>(searchResponse.getResults()));
  Assert.assertEquals(expectedCursors,searchResponse.getCursors());
  searchResponse=searchMetadata(namespace,"String_Node_Str",targets,sort,2,1,2,null);
  expectedResults=ImmutableList.of(new MetadataSearchResultRecord(view));
  Assert.assertEquals(expectedResults,new ArrayList<>(searchResponse.getResults()));
  Assert.assertTrue(searchResponse.getCursors().isEmpty());
  searchResponse=searchMetadata(namespace,"String_Node_Str",targets,sort,3,1,2,null);
  Assert.assertTrue(searchResponse.getResults().isEmpty());
  Assert.assertTrue(searchResponse.getCursors().isEmpty());
  searchResponse=searchMetadata(namespace,"String_Node_Str",targets,sort,0,Integer.MAX_VALUE,4,null);
  expectedResults=ImmutableList.of(new MetadataSearchResultRecord(dataset),new MetadataSearchResultRecord(stream),new MetadataSearchResultRecord(view));
  Assert.assertEquals(expectedResults,new ArrayList<>(searchResponse.getResults()));
  Assert.assertTrue(searchResponse.getCursors().isEmpty());
  namespaceClient.delete(namespace);
}

Fixed version (ground truth):
public void testSearchResultPagination() throws Exception {
  NamespaceId namespace=new NamespaceId("String_Node_Str");
  namespaceClient.create(new NamespaceMeta.Builder().setName(namespace).build());
  StreamId stream=namespace.stream("String_Node_Str");
  DatasetId dataset=namespace.dataset("String_Node_Str");
  StreamViewId view=stream.view("String_Node_Str");
  streamClient.create(stream);
  streamViewClient.createOrUpdate(view,new ViewSpecification(new FormatSpecification("String_Node_Str",null,null)));
  datasetClient.create(dataset,new DatasetInstanceConfiguration(Table.class.getName(),Collections.<String,String>emptyMap()));
  EnumSet<MetadataSearchTargetType> targets=EnumSet.allOf(MetadataSearchTargetType.class);
  String sort=AbstractSystemMetadataWriter.ENTITY_NAME_KEY + "String_Node_Str";
  MetadataSearchResponse searchResponse=searchMetadata(namespace,"String_Node_Str",targets,sort,0,1,0,null);
  List<MetadataSearchResultRecord> expectedResults=ImmutableList.of(new MetadataSearchResultRecord(dataset));
  List<String> expectedCursors=ImmutableList.of();
  Assert.assertEquals(expectedResults,new ArrayList<>(searchResponse.getResults()));
  Assert.assertEquals(expectedCursors,searchResponse.getCursors());
  searchResponse=searchMetadata(namespace,"String_Node_Str",targets,sort,0,1,2,null);
  expectedResults=ImmutableList.of(new MetadataSearchResultRecord(dataset));
  expectedCursors=ImmutableList.of(stream.getEntityName(),view.getEntityName());
  Assert.assertEquals(expectedResults,new ArrayList<>(searchResponse.getResults()));
  Assert.assertEquals(expectedCursors,searchResponse.getCursors());
  searchResponse=searchMetadata(namespace,"String_Node_Str",targets,sort,1,1,2,null);
  expectedResults=ImmutableList.of(new MetadataSearchResultRecord(stream));
  expectedCursors=ImmutableList.of(view.getEntityName());
  Assert.assertEquals(expectedResults,new ArrayList<>(searchResponse.getResults()));
  Assert.assertEquals(expectedCursors,searchResponse.getCursors());
  searchResponse=searchMetadata(namespace,"String_Node_Str",targets,sort,2,1,2,null);
  expectedResults=ImmutableList.of(new MetadataSearchResultRecord(view));
  Assert.assertEquals(expectedResults,new ArrayList<>(searchResponse.getResults()));
  Assert.assertTrue(searchResponse.getCursors().isEmpty());
  searchResponse=searchMetadata(namespace,"String_Node_Str",targets,sort,3,1,2,null);
  Assert.assertTrue(searchResponse.getResults().isEmpty());
  Assert.assertTrue(searchResponse.getCursors().isEmpty());
  searchResponse=searchMetadata(namespace,"String_Node_Str",targets,sort,0,Integer.MAX_VALUE,4,null);
  expectedResults=ImmutableList.of(new MetadataSearchResultRecord(dataset),new MetadataSearchResultRecord(stream),new MetadataSearchResultRecord(view));
  Assert.assertEquals(expectedResults,new ArrayList<>(searchResponse.getResults()));
  Assert.assertTrue(searchResponse.getCursors().isEmpty());
  namespaceClient.delete(namespace);
}