@Test
public void testPreFlushScannerOpen() throws Exception {

  // only test in MiniCluster
  if (TEST_UTIL != null) {
    ZooKeeperWatcher zk = new ZooKeeperWatcher(conf, "test", null, true);
    HBaseAdmin admin = new HBaseAdmin(connection);
    prewriteTestDataForPreFlushAndPreCompact();
    // no zk path
    ZKUtil.deleteNodeFailSilent(zk, ThemisMasterObserver.getThemisExpiredTsZNodePath(zk));
    admin.flush(TABLENAME);
    Assert.assertEquals(6, getRowByScan().size());
    deleteOldDataAndUpdateTs();
    // invalid value of cleanTs
    prewriteTestDataForPreFlushAndPreCompact();
    ZKUtil.createSetData(zk, ThemisMasterObserver.getThemisExpiredTsZNodePath(zk),
      Bytes.toBytes(String.valueOf(Long.MIN_VALUE)));
    admin.flush(TABLENAME);
    Assert.assertEquals(6, getRowByScan().size());
    deleteOldDataAndUpdateTs();
    // cleanTs is too new
    prewriteTestDataForPreFlushAndPreCompact();
    ZKUtil.createSetData(zk, ThemisMasterObserver.getThemisExpiredTsZNodePath(zk),
      Bytes.toBytes(String.valueOf(prewriteTs + 1)));
    admin.flush(TABLENAME);
    Assert.assertEquals(6, getRowByScan().size());
    deleteOldDataAndUpdateTs();
    // clean old data
    prewriteTestDataForPreFlushAndPreCompact();
    ZKUtil.createSetData(zk, ThemisMasterObserver.getThemisExpiredTsZNodePath(zk),
      Bytes.toBytes(String.valueOf(prewriteTs + 5)));
    admin.flush(TABLENAME);
    Result result = getRowByScan();
    Assert.assertEquals(3, result.size());
    Assert.assertNotNull(result.getValue(FAMILY, QUALIFIER));
    Column deleteColumn = ColumnUtil.getDeleteColumn(COLUMN);
    Assert.assertNotNull(result.getValue(deleteColumn.getFamily(), deleteColumn.getQualifier()));
    Column putColumn = ColumnUtil.getPutColumn(COLUMN);
    Assert.assertNotNull(result.getValue(putColumn.getFamily(), putColumn.getQualifier()));
    deleteOldDataAndUpdateTs();
    admin.close();
    zk.close();
  }
}