Program: 6367
Project: 6367
Buggy source:
private void doTestHistory(MetadataDataset dataset,Id.NamespacedId targetId,String prefix) throws Exception {
  Map<Long,MetadataHistoryEntry> expected=new HashMap<>();
  MetadataHistoryEntry completeRecord=new MetadataHistoryEntry(targetId);
  expected.put(System.currentTimeMillis(),completeRecord);
  Assert.assertEquals(ImmutableSet.of(completeRecord),dataset.getSnapshotBeforeTime(ImmutableSet.of(targetId),System.currentTimeMillis()));
  Assert.assertEquals(getFirst(dataset.getSnapshotBeforeTime(ImmutableSet.of(targetId),System.currentTimeMillis())),new MetadataHistoryEntry(targetId,dataset.getProperties(targetId),dataset.getTags(targetId)));
  TimeUnit.MILLISECONDS.sleep(1);
  completeRecord=new MetadataHistoryEntry(targetId,toProps(prefix,"String_Node_Str","String_Node_Str"),toTags(prefix,"String_Node_Str","String_Node_Str"));
  addMetadataHistory(dataset,completeRecord);
  long time=System.currentTimeMillis();
  expected.put(time,completeRecord);
  Assert.assertEquals(ImmutableSet.of(completeRecord),dataset.getSnapshotBeforeTime(ImmutableSet.of(targetId),time));
  Assert.assertEquals(getFirst(dataset.getSnapshotBeforeTime(ImmutableSet.of(targetId),System.currentTimeMillis())),new MetadataHistoryEntry(targetId,dataset.getProperties(targetId),dataset.getTags(targetId)));
  TimeUnit.MILLISECONDS.sleep(1);
  dataset.setProperty(targetId,prefix + "String_Node_Str","String_Node_Str");
  dataset.addTags(targetId,prefix + "String_Node_Str");
  completeRecord=new MetadataHistoryEntry(targetId,toProps(prefix,"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str"),toTags(prefix,"String_Node_Str","String_Node_Str","String_Node_Str"));
  time=System.currentTimeMillis();
  expected.put(time,completeRecord);
  Assert.assertEquals(ImmutableSet.of(completeRecord),dataset.getSnapshotBeforeTime(ImmutableSet.of(targetId),time));
  Assert.assertEquals(getFirst(dataset.getSnapshotBeforeTime(ImmutableSet.of(targetId),System.currentTimeMillis())),new MetadataHistoryEntry(targetId,dataset.getProperties(targetId),dataset.getTags(targetId)));
  TimeUnit.MILLISECONDS.sleep(1);
  dataset.setProperty(targetId,prefix + "String_Node_Str","String_Node_Str");
  dataset.addTags(targetId,prefix + "String_Node_Str");
  completeRecord=new MetadataHistoryEntry(targetId,toProps(prefix,"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str"),toTags(prefix,"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str"));
  time=System.currentTimeMillis();
  expected.put(time,completeRecord);
  Assert.assertEquals(ImmutableSet.of(completeRecord),dataset.getSnapshotBeforeTime(ImmutableSet.of(targetId),time));
  Assert.assertEquals(getFirst(dataset.getSnapshotBeforeTime(ImmutableSet.of(targetId),System.currentTimeMillis())),new MetadataHistoryEntry(targetId,dataset.getProperties(targetId),dataset.getTags(targetId)));
  TimeUnit.MILLISECONDS.sleep(1);
  dataset.setProperty(targetId,prefix + "String_Node_Str","String_Node_Str");
  dataset.addTags(targetId,prefix + "String_Node_Str");
  completeRecord=new MetadataHistoryEntry(targetId,toProps(prefix,"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str"),toTags(prefix,"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str"));
  time=System.currentTimeMillis();
  expected.put(time,completeRecord);
  Assert.assertEquals(ImmutableSet.of(completeRecord),dataset.getSnapshotBeforeTime(ImmutableSet.of(targetId),time));
  Assert.assertEquals(getFirst(dataset.getSnapshotBeforeTime(ImmutableSet.of(targetId),System.currentTimeMillis())),new MetadataHistoryEntry(targetId,dataset.getProperties(targetId),dataset.getTags(targetId)));
  TimeUnit.MILLISECONDS.sleep(1);
  dataset.removeProperties(targetId,prefix + "String_Node_Str");
  dataset.removeTags(targetId,prefix + "String_Node_Str");
  dataset.removeTags(targetId,prefix + "String_Node_Str");
  completeRecord=new MetadataHistoryEntry(targetId,toProps(prefix,"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str"),toTags(prefix,"String_Node_Str","String_Node_Str"));
  time=System.currentTimeMillis();
  expected.put(time,completeRecord);
  Assert.assertEquals(ImmutableSet.of(completeRecord),dataset.getSnapshotBeforeTime(ImmutableSet.of(targetId),time));
  Assert.assertEquals(getFirst(dataset.getSnapshotBeforeTime(ImmutableSet.of(targetId),System.currentTimeMillis())),new MetadataHistoryEntry(targetId,dataset.getProperties(targetId),dataset.getTags(targetId)));
  TimeUnit.MILLISECONDS.sleep(1);
  dataset.removeProperties(targetId);
  dataset.removeTags(targetId);
  completeRecord=new MetadataHistoryEntry(targetId);
  time=System.currentTimeMillis();
  expected.put(time,completeRecord);
  Assert.assertEquals(ImmutableSet.of(completeRecord),dataset.getSnapshotBeforeTime(ImmutableSet.of(targetId),time));
  Assert.assertEquals(getFirst(dataset.getSnapshotBeforeTime(ImmutableSet.of(targetId),System.currentTimeMillis())),new MetadataHistoryEntry(targetId,dataset.getProperties(targetId),dataset.getTags(targetId)));
  TimeUnit.MILLISECONDS.sleep(1);
  dataset.setProperty(targetId,prefix + "String_Node_Str","String_Node_Str");
  dataset.addTags(targetId,prefix + "String_Node_Str");
  completeRecord=new MetadataHistoryEntry(targetId,toProps(prefix,"String_Node_Str","String_Node_Str"),toTags(prefix,"String_Node_Str"));
  time=System.currentTimeMillis();
  expected.put(time,completeRecord);
  Assert.assertEquals(ImmutableSet.of(completeRecord),dataset.getSnapshotBeforeTime(ImmutableSet.of(targetId),time));
  Assert.assertEquals(getFirst(dataset.getSnapshotBeforeTime(ImmutableSet.of(targetId),System.currentTimeMillis())),new MetadataHistoryEntry(targetId,dataset.getProperties(targetId),dataset.getTags(targetId)));
  TimeUnit.MILLISECONDS.sleep(1);
  for (  Map.Entry<Long,MetadataHistoryEntry> entry : expected.entrySet()) {
    Assert.assertEquals(entry.getValue(),getFirst(dataset.getSnapshotBeforeTime(ImmutableSet.of(targetId),entry.getKey())));
  }
  Assert.assertEquals(ImmutableSet.of(completeRecord),dataset.getSnapshotBeforeTime(ImmutableSet.of(targetId),System.currentTimeMillis()));
  Assert.assertEquals(getFirst(dataset.getSnapshotBeforeTime(ImmutableSet.of(targetId),System.currentTimeMillis())),new MetadataHistoryEntry(targetId,dataset.getProperties(targetId),dataset.getTags(targetId)));
}

Fixed version (ground truth):
private void doTestHistory(MetadataDataset dataset,Id.NamespacedId targetId,String prefix) throws Exception {
  Map<Long,Metadata> expected=new HashMap<>();
  Metadata completeRecord=new Metadata(targetId);
  expected.put(System.currentTimeMillis(),completeRecord);
  Assert.assertEquals(ImmutableSet.of(completeRecord),dataset.getSnapshotBeforeTime(ImmutableSet.of(targetId),System.currentTimeMillis()));
  Assert.assertEquals(getFirst(dataset.getSnapshotBeforeTime(ImmutableSet.of(targetId),System.currentTimeMillis())),new Metadata(targetId,dataset.getProperties(targetId),dataset.getTags(targetId)));
  TimeUnit.MILLISECONDS.sleep(1);
  completeRecord=new Metadata(targetId,toProps(prefix,"String_Node_Str","String_Node_Str"),toTags(prefix,"String_Node_Str","String_Node_Str"));
  addMetadataHistory(dataset,completeRecord);
  long time=System.currentTimeMillis();
  expected.put(time,completeRecord);
  Assert.assertEquals(ImmutableSet.of(completeRecord),dataset.getSnapshotBeforeTime(ImmutableSet.of(targetId),time));
  Assert.assertEquals(getFirst(dataset.getSnapshotBeforeTime(ImmutableSet.of(targetId),System.currentTimeMillis())),new Metadata(targetId,dataset.getProperties(targetId),dataset.getTags(targetId)));
  TimeUnit.MILLISECONDS.sleep(1);
  dataset.setProperty(targetId,prefix + "String_Node_Str","String_Node_Str");
  dataset.addTags(targetId,prefix + "String_Node_Str");
  completeRecord=new Metadata(targetId,toProps(prefix,"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str"),toTags(prefix,"String_Node_Str","String_Node_Str","String_Node_Str"));
  time=System.currentTimeMillis();
  expected.put(time,completeRecord);
  Assert.assertEquals(ImmutableSet.of(completeRecord),dataset.getSnapshotBeforeTime(ImmutableSet.of(targetId),time));
  Assert.assertEquals(getFirst(dataset.getSnapshotBeforeTime(ImmutableSet.of(targetId),System.currentTimeMillis())),new Metadata(targetId,dataset.getProperties(targetId),dataset.getTags(targetId)));
  TimeUnit.MILLISECONDS.sleep(1);
  dataset.setProperty(targetId,prefix + "String_Node_Str","String_Node_Str");
  dataset.addTags(targetId,prefix + "String_Node_Str");
  completeRecord=new Metadata(targetId,toProps(prefix,"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str"),toTags(prefix,"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str"));
  time=System.currentTimeMillis();
  expected.put(time,completeRecord);
  Assert.assertEquals(ImmutableSet.of(completeRecord),dataset.getSnapshotBeforeTime(ImmutableSet.of(targetId),time));
  Assert.assertEquals(getFirst(dataset.getSnapshotBeforeTime(ImmutableSet.of(targetId),System.currentTimeMillis())),new Metadata(targetId,dataset.getProperties(targetId),dataset.getTags(targetId)));
  TimeUnit.MILLISECONDS.sleep(1);
  dataset.setProperty(targetId,prefix + "String_Node_Str","String_Node_Str");
  dataset.addTags(targetId,prefix + "String_Node_Str");
  completeRecord=new Metadata(targetId,toProps(prefix,"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str"),toTags(prefix,"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str"));
  time=System.currentTimeMillis();
  expected.put(time,completeRecord);
  Assert.assertEquals(ImmutableSet.of(completeRecord),dataset.getSnapshotBeforeTime(ImmutableSet.of(targetId),time));
  Assert.assertEquals(getFirst(dataset.getSnapshotBeforeTime(ImmutableSet.of(targetId),System.currentTimeMillis())),new Metadata(targetId,dataset.getProperties(targetId),dataset.getTags(targetId)));
  TimeUnit.MILLISECONDS.sleep(1);
  dataset.removeProperties(targetId,prefix + "String_Node_Str");
  dataset.removeTags(targetId,prefix + "String_Node_Str");
  dataset.removeTags(targetId,prefix + "String_Node_Str");
  completeRecord=new Metadata(targetId,toProps(prefix,"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str"),toTags(prefix,"String_Node_Str","String_Node_Str"));
  time=System.currentTimeMillis();
  expected.put(time,completeRecord);
  Assert.assertEquals(ImmutableSet.of(completeRecord),dataset.getSnapshotBeforeTime(ImmutableSet.of(targetId),time));
  Assert.assertEquals(getFirst(dataset.getSnapshotBeforeTime(ImmutableSet.of(targetId),System.currentTimeMillis())),new Metadata(targetId,dataset.getProperties(targetId),dataset.getTags(targetId)));
  TimeUnit.MILLISECONDS.sleep(1);
  dataset.removeProperties(targetId);
  dataset.removeTags(targetId);
  completeRecord=new Metadata(targetId);
  time=System.currentTimeMillis();
  expected.put(time,completeRecord);
  Assert.assertEquals(ImmutableSet.of(completeRecord),dataset.getSnapshotBeforeTime(ImmutableSet.of(targetId),time));
  Assert.assertEquals(getFirst(dataset.getSnapshotBeforeTime(ImmutableSet.of(targetId),System.currentTimeMillis())),new Metadata(targetId,dataset.getProperties(targetId),dataset.getTags(targetId)));
  TimeUnit.MILLISECONDS.sleep(1);
  dataset.setProperty(targetId,prefix + "String_Node_Str","String_Node_Str");
  dataset.addTags(targetId,prefix + "String_Node_Str");
  completeRecord=new Metadata(targetId,toProps(prefix,"String_Node_Str","String_Node_Str"),toTags(prefix,"String_Node_Str"));
  time=System.currentTimeMillis();
  expected.put(time,completeRecord);
  Assert.assertEquals(ImmutableSet.of(completeRecord),dataset.getSnapshotBeforeTime(ImmutableSet.of(targetId),time));
  Assert.assertEquals(getFirst(dataset.getSnapshotBeforeTime(ImmutableSet.of(targetId),System.currentTimeMillis())),new Metadata(targetId,dataset.getProperties(targetId),dataset.getTags(targetId)));
  TimeUnit.MILLISECONDS.sleep(1);
  for (  Map.Entry<Long,Metadata> entry : expected.entrySet()) {
    Assert.assertEquals(entry.getValue(),getFirst(dataset.getSnapshotBeforeTime(ImmutableSet.of(targetId),entry.getKey())));
  }
  Assert.assertEquals(ImmutableSet.of(completeRecord),dataset.getSnapshotBeforeTime(ImmutableSet.of(targetId),System.currentTimeMillis()));
  Assert.assertEquals(getFirst(dataset.getSnapshotBeforeTime(ImmutableSet.of(targetId),System.currentTimeMillis())),new Metadata(targetId,dataset.getProperties(targetId),dataset.getTags(targetId)));
}