}
}
@Test
public void testMultipleRegions() {
PerRegionIndexWriteCache cache = new PerRegionIndexWriteCache();
HTableInterfaceReference t1 =
new HTableInterfaceReference(new ImmutableBytesPtr(Bytes.toBytes("t1")));
List<Mutation> mutations = Lists.<Mutation> newArrayList(p);
List<Mutation> m2 = Lists.<Mutation> newArrayList(p2);
// add each region
cache.addEdits(r1, t1, mutations);
cache.addEdits(r2, t1, m2);
// check region1
Multimap<HTableInterfaceReference, Mutation> edits = cache.getEdits(r1);
Set<Entry<HTableInterfaceReference, Collection<Mutation>>> entries = edits.asMap().entrySet();
assertEquals("Got more than one table in the the edit map!", 1, entries.size());
for (Entry<HTableInterfaceReference, Collection<Mutation>> entry : entries) {
// ensure that we are still storing a list here - otherwise it breaks the parallel writer
// implementation
final List<Mutation> stored = (List<Mutation>) entry.getValue();
assertEquals("Got an unexpected amount of mutations in the entry for region1", 1,
stored.size());
assertEquals("Got an unexpected mutation in the entry for region2", p, stored.get(0));
}
// check region2
edits = cache.getEdits(r2);
entries = edits.asMap().entrySet();
assertEquals("Got more than one table in the the edit map!", 1, entries.size());
for (Entry<HTableInterfaceReference, Collection<Mutation>> entry : entries) {
// ensure that we are still storing a list here - otherwise it breaks the parallel writer
// implementation
final List<Mutation> stored = (List<Mutation>) entry.getValue();
assertEquals("Got an unexpected amount of mutations in the entry for region2", 1,
stored.size());
assertEquals("Got an unexpected mutation in the entry for region2", p2, stored.get(0));
}
// ensure that a second get doesn't have any more edits. This ensures that we don't keep
// references around to these edits and have a memory leak
assertNull("Got an entry for a region we removed", cache.getEdits(r1));
}