// make sure first expected values are correct
assertTrue(table.checkAndSave(batchUpdate2, expectedValues,null));
// make sure check and save truly saves the data after checking the expected
// values
RowResult r = table.getRow(row);
byte[][] columns = batchUpdate2.getColumns();
for(int i = 0;i < columns.length;i++) {
assertTrue(Bytes.equals(r.get(columns[i]).getValue(),batchUpdate2.get(columns[i])));
}
// make sure that the old expected values fail
assertFalse(table.checkAndSave(batchUpdate3, expectedValues,null));
// row doesn't exist, so doesn't matter the expected
// values (unless they are empty)
assertFalse(table.checkAndSave(batchUpdate4, badExpectedValues, null));
assertTrue(table.checkAndSave(batchUpdate4, expectedNoValues, null));
// make sure check and save saves the data when expected values were empty and the row
// didn't exist
r = table.getRow(row1);
columns = batchUpdate4.getColumns();
for(int i = 0; i < columns.length;i++) {
assertTrue(Bytes.equals(r.get(columns[i]).getValue(),batchUpdate4.get(columns[i])));
}
// since the row isn't empty anymore, those expected (empty) values
// are not valid anymore, so check and save method doesn't save.
assertFalse(table.checkAndSave(batchUpdate4, expectedNoValues, null));
// the row exists, but the columns don't. since the expected values are
// for columns without value, checkAndSave must be successful.
assertTrue(table.checkAndSave(batchUpdate5, expectedNoValues1, null));
// make sure checkAndSave saved values for batchUpdate5.
r = table.getRow(row);
columns = batchUpdate5.getColumns();
for(int i = 0; i < columns.length;i++) {
assertTrue(Bytes.equals(r.get(columns[i]).getValue(),batchUpdate5.get(columns[i])));
}
// since the condition wasn't changed, the following checkAndSave
// must also be successful.
assertTrue(table.checkAndSave(batchUpdate, expectedNoValues1, null));
// make sure checkAndSave saved values for batchUpdate1
r = table.getRow(row);
columns = batchUpdate.getColumns();
for(int i = 0; i < columns.length;i++) {
assertTrue(Bytes.equals(r.get(columns[i]).getValue(),batchUpdate.get(columns[i])));
}
// one failing condition must make the following checkAndSave fail
// the failing condition is a column to be empty, however, it has a value.
HbaseMapWritable<byte[],byte[]> expectedValues1 =
new HbaseMapWritable<byte[],byte[]>();
expectedValues1.put(Bytes.toBytes(COLUMN_FAMILY_STR+0), new byte[] {});
expectedValues1.put(Bytes.toBytes(COLUMN_FAMILY_STR+"EMPTY+ROW"), new byte[] {});
assertFalse(table.checkAndSave(batchUpdate5, expectedValues1, null));
// assure the values on the row remain the same
r = table.getRow(row);
columns = batchUpdate.getColumns();
for(int i = 0; i < columns.length;i++) {
assertTrue(Bytes.equals(r.get(columns[i]).getValue(),batchUpdate.get(columns[i])));
}
}