Program: 5234
Project: 5234
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,EnumSet.allOf(EntityScope.class));
      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,EnumSet.allOf(EntityScope.class));
      Assert.assertEquals(ImmutableList.of(flowEntry,dsEntry),searchResults.getResults());
      Assert.assertEquals(2,searchResults.getAllResults().size());
      searchResults=dataset.search(namespaceId,"String_Node_Str",targets,nameAsc,1,2,0,null,false,EnumSet.allOf(EntityScope.class));
      Assert.assertEquals(ImmutableList.of(dsEntry,appEntry),searchResults.getResults());
      Assert.assertEquals(3,searchResults.getAllResults().size());
      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,EnumSet.allOf(EntityScope.class));
      Assert.assertEquals(ImmutableList.of(appEntry,dsEntry),searchResults.getResults());
      Assert.assertEquals(2,searchResults.getAllResults().size());
      searchResults=dataset.search(namespaceId,"String_Node_Str",targets,nameDesc,2,1,0,null,false,EnumSet.allOf(EntityScope.class));
      Assert.assertEquals(ImmutableList.of(flowEntry),searchResults.getResults());
      Assert.assertEquals(3,searchResults.getAllResults().size());
      searchResults=dataset.search(namespaceId,"String_Node_Str",targets,nameAsc,2,0,0,null,false,EnumSet.allOf(EntityScope.class));
      Assert.assertTrue(searchResults.getResults().isEmpty());
      Assert.assertEquals(2,searchResults.getAllResults().size());
      searchResults=dataset.search(namespaceId,"String_Node_Str",targets,nameDesc,1,0,0,null,false,EnumSet.allOf(EntityScope.class));
      Assert.assertTrue(searchResults.getResults().isEmpty());
      Assert.assertEquals(1,searchResults.getAllResults().size());
      searchResults=dataset.search(namespaceId,"String_Node_Str",targets,nameAsc,4,0,0,null,false,EnumSet.allOf(EntityScope.class));
      Assert.assertTrue(searchResults.getResults().isEmpty());
      Assert.assertEquals(3,searchResults.getAllResults().size());
      searchResults=dataset.search(namespaceId,"String_Node_Str",targets,nameDesc,100,0,0,null,false,EnumSet.allOf(EntityScope.class));
      Assert.assertTrue(searchResults.getResults().isEmpty());
      Assert.assertEquals(3,searchResults.getAllResults().size());
      searchResults=dataset.search(namespaceId,"String_Node_Str",targets,nameAsc,0,1,3,null,false,EnumSet.allOf(EntityScope.class));
      Assert.assertEquals(ImmutableList.of(flowEntry),searchResults.getResults());
      Assert.assertEquals(ImmutableList.of(dsName,appName),searchResults.getCursors());
      Assert.assertEquals(3,searchResults.getAllResults().size());
      searchResults=dataset.search(namespaceId,"String_Node_Str",targets,nameAsc,0,1,3,searchResults.getCursors().get(0),false,EnumSet.allOf(EntityScope.class));
      Assert.assertEquals(ImmutableList.of(dsEntry),searchResults.getResults());
      Assert.assertEquals(ImmutableList.of(appName),searchResults.getCursors());
      Assert.assertEquals(2,searchResults.getAllResults().size());
      searchResults=dataset.search(namespaceId,"String_Node_Str",targets,nameAsc,0,1,3,searchResults.getCursors().get(0),false,EnumSet.allOf(EntityScope.class));
      Assert.assertEquals(ImmutableList.of(appEntry),searchResults.getResults());
      Assert.assertEquals(ImmutableList.of(),searchResults.getCursors());
      Assert.assertEquals(1,searchResults.getAllResults().size());
      searchResults=dataset.search(namespaceId,"String_Node_Str",targets,nameAsc,0,2,3,null,false,EnumSet.allOf(EntityScope.class));
      Assert.assertEquals(ImmutableList.of(flowEntry,dsEntry),searchResults.getResults());
      Assert.assertEquals(ImmutableList.of(appName),searchResults.getCursors());
      Assert.assertEquals(3,searchResults.getAllResults().size());
      searchResults=dataset.search(namespaceId,"String_Node_Str",targets,nameAsc,3,1,2,null,false,EnumSet.allOf(EntityScope.class));
      Assert.assertEquals(ImmutableList.of(),searchResults.getResults());
      Assert.assertEquals(ImmutableList.of(),searchResults.getCursors());
      Assert.assertEquals(3,searchResults.getAllResults().size());
    }
  }
);
}

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,EnumSet.allOf(EntityScope.class));
      Assert.assertEquals(ImmutableList.of(flowEntry,dsEntry,dsEntry,dsEntry,appEntry,appEntry,appEntry,appEntry),searchResults.getResultsFromOffset());
      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,EnumSet.allOf(EntityScope.class));
      Assert.assertEquals(ImmutableList.of(flowEntry,dsEntry),searchResults.getResultsFromOffset());
      Assert.assertEquals(2,searchResults.getResultsFromBeginning().size());
      searchResults=dataset.search(namespaceId,"String_Node_Str",targets,nameAsc,1,2,0,null,false,EnumSet.allOf(EntityScope.class));
      Assert.assertEquals(ImmutableList.of(dsEntry,appEntry),searchResults.getResultsFromOffset());
      Assert.assertEquals(3,searchResults.getResultsFromBeginning().size());
      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,EnumSet.allOf(EntityScope.class));
      Assert.assertEquals(ImmutableList.of(appEntry,dsEntry),searchResults.getResultsFromOffset());
      Assert.assertEquals(2,searchResults.getResultsFromBeginning().size());
      searchResults=dataset.search(namespaceId,"String_Node_Str",targets,nameDesc,2,1,0,null,false,EnumSet.allOf(EntityScope.class));
      Assert.assertEquals(ImmutableList.of(flowEntry),searchResults.getResultsFromOffset());
      Assert.assertEquals(3,searchResults.getResultsFromBeginning().size());
      searchResults=dataset.search(namespaceId,"String_Node_Str",targets,nameAsc,2,0,0,null,false,EnumSet.allOf(EntityScope.class));
      Assert.assertTrue(searchResults.getResultsFromOffset().isEmpty());
      Assert.assertEquals(2,searchResults.getResultsFromBeginning().size());
      searchResults=dataset.search(namespaceId,"String_Node_Str",targets,nameDesc,1,0,0,null,false,EnumSet.allOf(EntityScope.class));
      Assert.assertTrue(searchResults.getResultsFromOffset().isEmpty());
      Assert.assertEquals(1,searchResults.getResultsFromBeginning().size());
      searchResults=dataset.search(namespaceId,"String_Node_Str",targets,nameAsc,4,0,0,null,false,EnumSet.allOf(EntityScope.class));
      Assert.assertTrue(searchResults.getResultsFromOffset().isEmpty());
      Assert.assertEquals(3,searchResults.getResultsFromBeginning().size());
      searchResults=dataset.search(namespaceId,"String_Node_Str",targets,nameDesc,100,0,0,null,false,EnumSet.allOf(EntityScope.class));
      Assert.assertTrue(searchResults.getResultsFromOffset().isEmpty());
      Assert.assertEquals(3,searchResults.getResultsFromBeginning().size());
      searchResults=dataset.search(namespaceId,"String_Node_Str",targets,nameAsc,0,1,3,null,false,EnumSet.allOf(EntityScope.class));
      Assert.assertEquals(ImmutableList.of(flowEntry),searchResults.getResultsFromOffset());
      Assert.assertEquals(ImmutableList.of(dsName,appName),searchResults.getCursors());
      Assert.assertEquals(3,searchResults.getResultsFromBeginning().size());
      searchResults=dataset.search(namespaceId,"String_Node_Str",targets,nameAsc,0,1,3,searchResults.getCursors().get(0),false,EnumSet.allOf(EntityScope.class));
      Assert.assertEquals(ImmutableList.of(dsEntry),searchResults.getResultsFromOffset());
      Assert.assertEquals(ImmutableList.of(appName),searchResults.getCursors());
      Assert.assertEquals(2,searchResults.getResultsFromBeginning().size());
      searchResults=dataset.search(namespaceId,"String_Node_Str",targets,nameAsc,0,1,3,searchResults.getCursors().get(0),false,EnumSet.allOf(EntityScope.class));
      Assert.assertEquals(ImmutableList.of(appEntry),searchResults.getResultsFromOffset());
      Assert.assertEquals(ImmutableList.of(),searchResults.getCursors());
      Assert.assertEquals(1,searchResults.getResultsFromBeginning().size());
      searchResults=dataset.search(namespaceId,"String_Node_Str",targets,nameAsc,0,2,3,null,false,EnumSet.allOf(EntityScope.class));
      Assert.assertEquals(ImmutableList.of(flowEntry,dsEntry),searchResults.getResultsFromOffset());
      Assert.assertEquals(ImmutableList.of(appName),searchResults.getCursors());
      Assert.assertEquals(3,searchResults.getResultsFromBeginning().size());
      searchResults=dataset.search(namespaceId,"String_Node_Str",targets,nameAsc,3,1,2,null,false,EnumSet.allOf(EntityScope.class));
      Assert.assertEquals(ImmutableList.of(),searchResults.getResultsFromOffset());
      Assert.assertEquals(ImmutableList.of(),searchResults.getCursors());
      Assert.assertEquals(3,searchResults.getResultsFromBeginning().size());
    }
  }
);
}