Program: 5670
Project: 5670
Buggy source:
@Test public void testSearchResultSorting() 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);
  TimeUnit.MILLISECONDS.sleep(1);
  streamViewClient.createOrUpdate(view,new ViewSpecification(new FormatSpecification("String_Node_Str",null,null)));
  TimeUnit.MILLISECONDS.sleep(1);
  datasetClient.create(dataset,new DatasetInstanceConfiguration(Table.class.getName(),Collections.<String,String>emptyMap()));
  EnumSet<MetadataSearchTargetType> targets=EnumSet.allOf(MetadataSearchTargetType.class);
  try {
    searchMetadata(namespace,"String_Node_Str",targets,AbstractSystemMetadataWriter.ENTITY_NAME_KEY);
    Assert.fail();
  }
 catch (  BadRequestException e) {
  }
  try {
    searchMetadata(namespace,"String_Node_Str",targets,"String_Node_Str");
    Assert.fail();
  }
 catch (  BadRequestException e) {
  }
  try {
    searchMetadata(namespace,"String_Node_Str",targets,AbstractSystemMetadataWriter.ENTITY_NAME_KEY + "String_Node_Str");
    Assert.fail();
  }
 catch (  BadRequestException e) {
  }
  try {
    searchMetadata(NamespaceId.DEFAULT,"String_Node_Str",EnumSet.allOf(MetadataSearchTargetType.class),null,1,"String_Node_Str");
    Assert.fail();
  }
 catch (  BadRequestException e) {
  }
  Set<MetadataSearchResultRecord> searchResults=searchMetadata(namespace,"String_Node_Str",targets,AbstractSystemMetadataWriter.ENTITY_NAME_KEY + "String_Node_Str");
  List<MetadataSearchResultRecord> expected=ImmutableList.of(new MetadataSearchResultRecord(dataset),new MetadataSearchResultRecord(stream),new MetadataSearchResultRecord(view));
  Assert.assertEquals(expected,new ArrayList<>(searchResults));
  searchResults=searchMetadata(namespace,"String_Node_Str",targets,AbstractSystemMetadataWriter.ENTITY_NAME_KEY + "String_Node_Str");
  expected=ImmutableList.of(new MetadataSearchResultRecord(view),new MetadataSearchResultRecord(stream),new MetadataSearchResultRecord(dataset));
  Assert.assertEquals(expected,new ArrayList<>(searchResults));
  searchResults=searchMetadata(namespace,"String_Node_Str",targets,AbstractSystemMetadataWriter.CREATION_TIME_KEY + "String_Node_Str");
  expected=ImmutableList.of(new MetadataSearchResultRecord(stream),new MetadataSearchResultRecord(view),new MetadataSearchResultRecord(dataset));
  Assert.assertEquals(expected,new ArrayList<>(searchResults));
  searchResults=searchMetadata(namespace,"String_Node_Str",targets,AbstractSystemMetadataWriter.CREATION_TIME_KEY + "String_Node_Str");
  expected=ImmutableList.of(new MetadataSearchResultRecord(dataset),new MetadataSearchResultRecord(view),new MetadataSearchResultRecord(stream));
  Assert.assertEquals(expected,new ArrayList<>(searchResults));
  namespaceClient.delete(namespace);
}

Fixed version (ground truth):
@Test public void testSearchResultSorting() 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);
  TimeUnit.MILLISECONDS.sleep(1);
  streamViewClient.createOrUpdate(view,new ViewSpecification(new FormatSpecification("String_Node_Str",null,null)));
  TimeUnit.MILLISECONDS.sleep(1);
  datasetClient.create(dataset,new DatasetInstanceConfiguration(Table.class.getName(),Collections.<String,String>emptyMap()));
  EnumSet<MetadataSearchTargetType> targets=EnumSet.allOf(MetadataSearchTargetType.class);
  Set<MetadataSearchResultRecord> searchResults=searchMetadata(namespace,"String_Node_Str",targets,AbstractSystemMetadataWriter.ENTITY_NAME_KEY + "String_Node_Str");
  List<MetadataSearchResultRecord> expected=ImmutableList.of(new MetadataSearchResultRecord(dataset),new MetadataSearchResultRecord(stream),new MetadataSearchResultRecord(view));
  Assert.assertEquals(expected,new ArrayList<>(searchResults));
  searchResults=searchMetadata(namespace,"String_Node_Str",targets,AbstractSystemMetadataWriter.ENTITY_NAME_KEY + "String_Node_Str");
  expected=ImmutableList.of(new MetadataSearchResultRecord(view),new MetadataSearchResultRecord(stream),new MetadataSearchResultRecord(dataset));
  Assert.assertEquals(expected,new ArrayList<>(searchResults));
  searchResults=searchMetadata(namespace,"String_Node_Str",targets,AbstractSystemMetadataWriter.CREATION_TIME_KEY + "String_Node_Str");
  expected=ImmutableList.of(new MetadataSearchResultRecord(stream),new MetadataSearchResultRecord(view),new MetadataSearchResultRecord(dataset));
  Assert.assertEquals(expected,new ArrayList<>(searchResults));
  searchResults=searchMetadata(namespace,"String_Node_Str",targets,AbstractSystemMetadataWriter.CREATION_TIME_KEY + "String_Node_Str");
  expected=ImmutableList.of(new MetadataSearchResultRecord(dataset),new MetadataSearchResultRecord(view),new MetadataSearchResultRecord(stream));
  Assert.assertEquals(expected,new ArrayList<>(searchResults));
  namespaceClient.delete(namespace);
}