@Test
public void oneDependencyWithMoreDimensionedVariants() throws Exception {
String idPrefix = newIdPrefix();
final SchemaId dummyVtag = ids.getSchemaId(UUID.randomUUID());
final RecordId dependant = ids.newRecordId(idPrefix + "master", ImmutableMap.of("bar", "x"));
final RecordId dependency = ids.newRecordId(idPrefix + "master", ImmutableMap.of("bar", "x", "foo", "y"));
// the dependant depends on the dependencyField of the dependency via a "+foo" dereferencing rule
final HashMap<DependencyEntry, Set<SchemaId>> dependencies =
new HashMap<DependencyEntry, Set<SchemaId>>();
dependencies.put(new DependencyEntry(absId(dependency),
ImmutableSet.of("foo")), Sets.<SchemaId>newHashSet());
derefMap.updateDependants(absId(dependant), dummyVtag, dependencies);
// consistency check
final Set<DependencyEntry> found = derefMap.findDependencies(absId(dependant), dummyVtag);
assertEquals(1, found.size());
final DependencyEntry foundDependencyEntry = found.iterator().next();
assertEquals(absId(ids.newRecordId(idPrefix + "master", ImmutableMap.of("bar", "x"))), foundDependencyEntry.getDependency());
assertEquals(Sets.newHashSet("foo"), foundDependencyEntry.getMoreDimensionedVariants());
// check that the dependant is found as only dependant of the dependency (without specifying a field)
DependantRecordIdsIterator dependants = derefMap.findDependantsOf(absId(dependency));
assertTrue(dependants.hasNext());
assertEquals(absId(dependant), dependants.next());
assertFalse(dependants.hasNext());
// check that other records (which would in reality not yet exist at index time) that match the "+foo" rule
// are returned as dependants of our dependant (such that in reality reindexation of the dependant happens)
final RecordId shouldTriggerOurDependant =
ids.newRecordId(idPrefix + "master", ImmutableMap.of("bar", "x", "foo", "another-value"));
dependants = derefMap.findDependantsOf(absId(shouldTriggerOurDependant));
assertTrue(dependants.hasNext());
assertEquals(absId(dependant), dependants.next());
assertFalse(dependants.hasNext());
// doesn't have the foo property
final RecordId shouldNotTriggerOurDependant1 = ids.newRecordId(idPrefix + "master", ImmutableMap.of("bar", "x"));
assertFalse(derefMap.findDependantsOf(absId(shouldNotTriggerOurDependant1)).hasNext());
// doesn't have the bar property
final RecordId shouldNotTriggerOurDependant2 = ids.newRecordId(idPrefix + "master", ImmutableMap.of("foo", "x"));
assertFalse(derefMap.findDependantsOf(absId(shouldNotTriggerOurDependant2)).hasNext());
// wrong value for the bar property
final RecordId shouldNotTriggerOurDependant3 =
ids.newRecordId(idPrefix + "master", ImmutableMap.of("bar", "y", "foo", "another-value"));
assertFalse(derefMap.findDependantsOf(absId(shouldNotTriggerOurDependant3)).hasNext());
// additional unmatched property
final RecordId shouldNotTriggerOurDependant4 =
ids.newRecordId(idPrefix + "master", ImmutableMap.of("bar", "x", "foo", "another-value", "baz", "z"));
assertFalse(derefMap.findDependantsOf(absId(shouldNotTriggerOurDependant4)).hasNext());
// another master
final RecordId shouldNotTriggerOurDependant5 =
ids.newRecordId(idPrefix + "another-master", ImmutableMap.of("bar", "x", "foo", "another-value"));
assertFalse(derefMap.findDependantsOf(absId(shouldNotTriggerOurDependant5)).hasNext());
// wrong properties
final RecordId shouldNotTriggerOurDependant6 = ids.newRecordId(idPrefix + "master", ImmutableMap.of("a", "b", "c", "d"));
assertFalse(derefMap.findDependantsOf(absId(shouldNotTriggerOurDependant6)).hasNext());
// no properties
final RecordId shouldNotTriggerOurDependant7 = ids.newRecordId(idPrefix + "master", ImmutableMap.<String, String>of());
assertFalse(derefMap.findDependantsOf(absId(shouldNotTriggerOurDependant7)).hasNext());
}