Path basedir = new Path(this.hbaseRootDir, Bytes.toString(TEST_TABLE));
deleteDir(basedir);
fs.mkdirs(new Path(basedir, hri.getEncodedName()));
HLog log = new HLog(this.fs, this.dir, this.oldLogDir, this.conf);
SampleRegionWALObserver cp = getCoprocessor(log);
// TEST_FAMILY[0] shall be removed from WALEdit.
// TEST_FAMILY[1] value shall be changed.
// TEST_FAMILY[2] shall be added to WALEdit, although it's not in the put.
cp.setTestValues(TEST_TABLE, TEST_ROW, TEST_FAMILY[0], TEST_QUALIFIER[0],
TEST_FAMILY[1], TEST_QUALIFIER[1],
TEST_FAMILY[2], TEST_QUALIFIER[2]);
assertFalse(cp.isPreWALWriteCalled());
assertFalse(cp.isPostWALWriteCalled());
// TEST_FAMILY[2] is not in the put, however it shall be added by the tested
// coprocessor.
// Use a Put to create familyMap.
Put p = creatPutWith2Families(TEST_ROW);
Map<byte [], List<KeyValue>> familyMap = p.getFamilyMap();
WALEdit edit = new WALEdit();
addFamilyMapToWALEdit(familyMap, edit);
boolean foundFamily0 = false;
boolean foundFamily2 = false;
boolean modifiedFamily1 = false;
List<KeyValue> kvs = edit.getKeyValues();
for (KeyValue kv : kvs) {
if (Arrays.equals(kv.getFamily(), TEST_FAMILY[0])) {
foundFamily0 = true;
}
if (Arrays.equals(kv.getFamily(), TEST_FAMILY[2])) {
foundFamily2 = true;
}
if (Arrays.equals(kv.getFamily(), TEST_FAMILY[1])) {
if (!Arrays.equals(kv.getValue(), TEST_VALUE[1])) {
modifiedFamily1 = true;
}
}
}
assertTrue(foundFamily0);
assertFalse(foundFamily2);
assertFalse(modifiedFamily1);
// it's where WAL write cp should occur.
long now = EnvironmentEdgeManager.currentTimeMillis();
log.append(hri, hri.getTableName(), edit, now, htd);
// the edit shall have been change now by the coprocessor.
foundFamily0 = false;
foundFamily2 = false;
modifiedFamily1 = false;