Program: 5434
Project: 5434
Buggy source:
@Test public void testPagination() throws Exception {
  final MetadataDataset dataset=getDataset(DatasetFrameworkTestUtil.NAMESPACE_ID.dataset("String_Node_Str"),MetadataScope.SYSTEM);
  TransactionExecutor txnl=dsFrameworkUtil.newInMemoryTransactionExecutor((TransactionAware)dataset);
  final String flowName="String_Node_Str";
  final String dsName="String_Node_Str";
  final String appName="String_Node_Str";
  txnl.execute(new TransactionExecutor.Subroutine(){
    @Override public void apply() throws Exception {
      dataset.setProperty(flow1,AbstractSystemMetadataWriter.ENTITY_NAME_KEY,flowName);
      dataset.setProperty(dataset1,AbstractSystemMetadataWriter.ENTITY_NAME_KEY,dsName);
      dataset.setProperty(app1,AbstractSystemMetadataWriter.ENTITY_NAME_KEY,appName);
    }
  }
);
  final String namespaceId=flow1.getNamespace();
  final EnumSet<EntityTypeSimpleName> targets=EnumSet.allOf(EntityTypeSimpleName.class);
  final MetadataEntry flowEntry=new MetadataEntry(flow1,AbstractSystemMetadataWriter.ENTITY_NAME_KEY,flowName);
  final MetadataEntry dsEntry=new MetadataEntry(dataset1,AbstractSystemMetadataWriter.ENTITY_NAME_KEY,dsName);
  final MetadataEntry appEntry=new MetadataEntry(app1,AbstractSystemMetadataWriter.ENTITY_NAME_KEY,appName);
  txnl.execute(new TransactionExecutor.Subroutine(){
    @Override public void apply() throws Exception {
      SearchResults searchResults=dataset.search(namespaceId,"String_Node_Str",targets,SortInfo.DEFAULT,0,3,1,null,false);
      Assert.assertEquals(ImmutableList.of(flowEntry,dsEntry,dsEntry,dsEntry,appEntry,appEntry,appEntry,appEntry),searchResults.getResults());
      SortInfo nameAsc=new SortInfo(AbstractSystemMetadataWriter.ENTITY_NAME_KEY,SortInfo.SortOrder.ASC);
      searchResults=dataset.search(namespaceId,"String_Node_Str",targets,nameAsc,0,2,0,null,false);
      Assert.assertEquals(ImmutableList.of(flowEntry,dsEntry),searchResults.getResults());
      searchResults=dataset.search(namespaceId,"String_Node_Str",targets,nameAsc,1,2,0,null,false);
      Assert.assertEquals(ImmutableList.of(dsEntry,appEntry),searchResults.getResults());
      SortInfo nameDesc=new SortInfo(AbstractSystemMetadataWriter.ENTITY_NAME_KEY,SortInfo.SortOrder.DESC);
      searchResults=dataset.search(namespaceId,"String_Node_Str",targets,nameDesc,0,2,0,null,false);
      Assert.assertEquals(ImmutableList.of(appEntry,dsEntry),searchResults.getResults());
      searchResults=dataset.search(namespaceId,"String_Node_Str",targets,nameDesc,2,1,0,null,false);
      Assert.assertEquals(ImmutableList.of(flowEntry),searchResults.getResults());
      searchResults=dataset.search(namespaceId,"String_Node_Str",targets,nameAsc,2,0,0,null,false);
      Assert.assertTrue(searchResults.getResults().isEmpty());
      searchResults=dataset.search(namespaceId,"String_Node_Str",targets,nameDesc,1,0,0,null,false);
      Assert.assertTrue(searchResults.getResults().isEmpty());
      searchResults=dataset.search(namespaceId,"String_Node_Str",targets,nameAsc,4,0,0,null,false);
      Assert.assertTrue(searchResults.getResults().isEmpty());
      searchResults=dataset.search(namespaceId,"String_Node_Str",targets,nameDesc,100,0,0,null,false);
      Assert.assertTrue(searchResults.getResults().isEmpty());
      searchResults=dataset.search(namespaceId,"String_Node_Str",targets,nameAsc,0,1,3,null,false);
      Assert.assertEquals(ImmutableList.of(flowEntry,dsEntry,appEntry),searchResults.getResults());
      Assert.assertEquals(ImmutableList.of(dsName,appName),searchResults.getCursors());
      searchResults=dataset.search(namespaceId,"String_Node_Str",targets,nameAsc,0,1,3,searchResults.getCursors().get(0),false);
      Assert.assertEquals(ImmutableList.of(dsEntry,appEntry),searchResults.getResults());
      Assert.assertEquals(ImmutableList.of(appName),searchResults.getCursors());
      searchResults=dataset.search(namespaceId,"String_Node_Str",targets,nameAsc,0,1,3,searchResults.getCursors().get(0),false);
      Assert.assertEquals(ImmutableList.of(appEntry),searchResults.getResults());
      Assert.assertEquals(ImmutableList.of(),searchResults.getCursors());
      searchResults=dataset.search(namespaceId,"String_Node_Str",targets,nameAsc,0,2,3,null,false);
      Assert.assertEquals(ImmutableList.of(flowEntry,dsEntry,appEntry),searchResults.getResults());
      Assert.assertEquals(ImmutableList.of(appName),searchResults.getCursors());
      searchResults=dataset.search(namespaceId,"String_Node_Str",targets,nameAsc,3,1,2,null,false);
      Assert.assertEquals(ImmutableList.of(),searchResults.getResults());
      Assert.assertEquals(ImmutableList.of(),searchResults.getCursors());
    }
  }
);
}

Fixed version (ground truth):
@Test public void testPagination() throws Exception {
  final MetadataDataset dataset=getDataset(DatasetFrameworkTestUtil.NAMESPACE_ID.dataset("String_Node_Str"),MetadataScope.SYSTEM);
  TransactionExecutor txnl=dsFrameworkUtil.newInMemoryTransactionExecutor((TransactionAware)dataset);
  final String flowName="String_Node_Str";
  final String dsName="String_Node_Str";
  final String appName="String_Node_Str";
  txnl.execute(new TransactionExecutor.Subroutine(){
    @Override public void apply() throws Exception {
      dataset.setProperty(flow1,AbstractSystemMetadataWriter.ENTITY_NAME_KEY,flowName);
      dataset.setProperty(dataset1,AbstractSystemMetadataWriter.ENTITY_NAME_KEY,dsName);
      dataset.setProperty(app1,AbstractSystemMetadataWriter.ENTITY_NAME_KEY,appName);
    }
  }
);
  final String namespaceId=flow1.getNamespace();
  final EnumSet<EntityTypeSimpleName> targets=EnumSet.allOf(EntityTypeSimpleName.class);
  final MetadataEntry flowEntry=new MetadataEntry(flow1,AbstractSystemMetadataWriter.ENTITY_NAME_KEY,flowName);
  final MetadataEntry dsEntry=new MetadataEntry(dataset1,AbstractSystemMetadataWriter.ENTITY_NAME_KEY,dsName);
  final MetadataEntry appEntry=new MetadataEntry(app1,AbstractSystemMetadataWriter.ENTITY_NAME_KEY,appName);
  txnl.execute(new TransactionExecutor.Subroutine(){
    @Override public void apply() throws Exception {
      SearchResults searchResults=dataset.search(namespaceId,"String_Node_Str",targets,SortInfo.DEFAULT,0,3,1,null,false);
      Assert.assertEquals(ImmutableList.of(flowEntry,dsEntry,dsEntry,dsEntry,appEntry,appEntry,appEntry,appEntry),searchResults.getResults());
      SortInfo nameAsc=new SortInfo(AbstractSystemMetadataWriter.ENTITY_NAME_KEY,SortInfo.SortOrder.ASC);
      searchResults=dataset.search(namespaceId,"String_Node_Str",targets,nameAsc,0,2,0,null,false);
      Assert.assertEquals(ImmutableList.of(flowEntry,dsEntry),searchResults.getResults());
      Assert.assertEquals(ImmutableList.of(flowEntry,dsEntry,appEntry),searchResults.getAllResults());
      searchResults=dataset.search(namespaceId,"String_Node_Str",targets,nameAsc,1,2,0,null,false);
      Assert.assertEquals(ImmutableList.of(dsEntry,appEntry),searchResults.getResults());
      Assert.assertEquals(ImmutableList.of(flowEntry,dsEntry,appEntry),searchResults.getAllResults());
      SortInfo nameDesc=new SortInfo(AbstractSystemMetadataWriter.ENTITY_NAME_KEY,SortInfo.SortOrder.DESC);
      searchResults=dataset.search(namespaceId,"String_Node_Str",targets,nameDesc,0,2,0,null,false);
      Assert.assertEquals(ImmutableList.of(appEntry,dsEntry),searchResults.getResults());
      Assert.assertEquals(ImmutableList.of(appEntry,dsEntry,flowEntry),searchResults.getAllResults());
      searchResults=dataset.search(namespaceId,"String_Node_Str",targets,nameDesc,2,1,0,null,false);
      Assert.assertEquals(ImmutableList.of(flowEntry),searchResults.getResults());
      Assert.assertEquals(ImmutableList.of(appEntry,dsEntry,flowEntry),searchResults.getAllResults());
      searchResults=dataset.search(namespaceId,"String_Node_Str",targets,nameAsc,2,0,0,null,false);
      Assert.assertTrue(searchResults.getResults().isEmpty());
      Assert.assertEquals(ImmutableList.of(flowEntry,dsEntry,appEntry),searchResults.getAllResults());
      searchResults=dataset.search(namespaceId,"String_Node_Str",targets,nameDesc,1,0,0,null,false);
      Assert.assertTrue(searchResults.getResults().isEmpty());
      Assert.assertEquals(ImmutableList.of(appEntry,dsEntry,flowEntry),searchResults.getAllResults());
      searchResults=dataset.search(namespaceId,"String_Node_Str",targets,nameAsc,4,0,0,null,false);
      Assert.assertTrue(searchResults.getResults().isEmpty());
      Assert.assertEquals(ImmutableList.of(flowEntry,dsEntry,appEntry),searchResults.getAllResults());
      searchResults=dataset.search(namespaceId,"String_Node_Str",targets,nameDesc,100,0,0,null,false);
      Assert.assertTrue(searchResults.getResults().isEmpty());
      Assert.assertEquals(ImmutableList.of(appEntry,dsEntry,flowEntry),searchResults.getAllResults());
      searchResults=dataset.search(namespaceId,"String_Node_Str",targets,nameAsc,0,1,3,null,false);
      Assert.assertEquals(ImmutableList.of(flowEntry),searchResults.getResults());
      Assert.assertEquals(ImmutableList.of(dsName,appName),searchResults.getCursors());
      searchResults=dataset.search(namespaceId,"String_Node_Str",targets,nameAsc,0,1,3,searchResults.getCursors().get(0),false);
      Assert.assertEquals(ImmutableList.of(dsEntry),searchResults.getResults());
      Assert.assertEquals(ImmutableList.of(appName),searchResults.getCursors());
      searchResults=dataset.search(namespaceId,"String_Node_Str",targets,nameAsc,0,1,3,searchResults.getCursors().get(0),false);
      Assert.assertEquals(ImmutableList.of(appEntry),searchResults.getResults());
      Assert.assertEquals(ImmutableList.of(),searchResults.getCursors());
      searchResults=dataset.search(namespaceId,"String_Node_Str",targets,nameAsc,0,2,3,null,false);
      Assert.assertEquals(ImmutableList.of(flowEntry,dsEntry),searchResults.getResults());
      Assert.assertEquals(ImmutableList.of(appName),searchResults.getCursors());
      searchResults=dataset.search(namespaceId,"String_Node_Str",targets,nameAsc,3,1,2,null,false);
      Assert.assertEquals(ImmutableList.of(),searchResults.getResults());
      Assert.assertEquals(ImmutableList.of(),searchResults.getCursors());
    }
  }
);
}