@Test
  public void testCustomWarehouseLocations() throws Throwable {
    List<String> withClauseOptions = getStagingLocationConfig(primary.repldDir, false);
    String dbWhManagedLoc = new Path(primary.warehouseRoot.getParent(), "customManagedLoc").toUri().getPath();
    String dbWhExternalLoc = new Path(primary.externalTableWarehouseRoot.getParent(),
            "customExternalLoc").toUri().getPath();
    String srcDb = "srcDb";
    WarehouseInstance.Tuple tuple = primary
            .run("create database " + srcDb + " LOCATION '" + dbWhExternalLoc + "' MANAGEDLOCATION '" + dbWhManagedLoc
                    + "' WITH DBPROPERTIES ( '" + SOURCE_OF_REPLICATION + "' = '1,2,3')")
            .run("use " + srcDb)
            .run("create table t1 (id int)")
            .run("insert into table t1 values (500)")
            .run("create external table t2 (id int)")
            .run("insert into table t2 values (1000)")
            .run("create table tp1 (id int) partitioned by (p int)")
            .run("insert into tp1 partition(p=1) values(10)")
            .run("insert into tp1 partition(p=2) values(20)")
            .dump(srcDb, withClauseOptions);

    replica.load(replicatedDbName, srcDb, withClauseOptions)
            .run("use " + replicatedDbName)
            .run("show tables like 't1'")
            .verifyResult("t1")
            .run("select id from t1")
            .verifyResult("500")
            .run("show tables like 't2'")
            .verifyResult("t2")
            .run("select id from t2")
            .verifyResult("1000")
            .run("show tables like 'tp1'")
            .verifyResult("tp1")
            .run("select id from tp1")
            .verifyResults(new String[]{"10", "20"});
    List<String> listOfTables = new ArrayList<>();
    listOfTables.addAll(Arrays.asList("t1", "t2", "tp1"));
    verifyCustomDBLocations(srcDb, listOfTables, dbWhManagedLoc, dbWhExternalLoc, true);
    primary.run("use " + srcDb)
            .run("insert into table t1 values (1000)")
            .run("insert into table t2 values (2000)")
            .run("insert into tp1 partition(p=1) values(30)")
            .run("insert into tp1 partition(p=2) values(40)")
            .dump(srcDb, withClauseOptions);
    replica.load(replicatedDbName, srcDb, withClauseOptions)
            .run("use " + replicatedDbName)
            .run("show tables like 't1'")
            .verifyResult("t1")
            .run("select id from t1")
            .verifyResults(new String[]{"500", "1000"})
            .run("show tables like 't2'")
            .verifyResult("t2")
            .run("select id from t2")
            .verifyResults(new String[]{"1000", "2000"})
            .run("show tables like 'tp1'")
            .verifyResult("tp1")
            .run("select id from tp1")
            .verifyResults(new String[]{"10", "20", "30", "40"});
    primary.run("use " + srcDb)
            .run("insert into table t1 values (2000)")
            .run("insert into table t2 values (3000)")
            .run("create table t3 (id int)")
            .run("insert into table t3 values (3000)")
            .run("create external table t4 (id int)")
            .run("insert into table t4 values (4000)")
            .run("insert into tp1 partition(p=1) values(50)")
            .run("insert into tp1 partition(p=2) values(60)")
            .run("create table tp2 (id int) partitioned by (p int)")
            .run("insert into tp2 partition(p=1) values(100)")
            .run("insert into tp2 partition(p=2) values(200)")
            .dump(srcDb, withClauseOptions);
    replica.load(replicatedDbName, srcDb, withClauseOptions)
            .run("use " + replicatedDbName)
            .run("show tables like 't1'")
            .verifyResult("t1")
            .run("select id from t1")
            .verifyResults(new String[]{"500", "1000", "2000"})
            .run("show tables like 't2'")
            .verifyResult("t2")
            .run("select id from t2")
            .verifyResults(new String[]{"1000", "2000", "3000"})
            .run("show tables like 't3'")
            .verifyResult("t3")
            .run("select id from t3")
            .verifyResults(new String[]{"3000"})
            .run("show tables like 't4'")
            .verifyResult("t4")
            .run("select id from t4")
            .verifyResults(new String[]{"4000"})
            .run("select id from tp1")
            .verifyResults(new String[]{"10", "20", "30", "40", "50", "60"})
            .run("show tables like 'tp1'")
            .verifyResult("tp1")
            .run("select id from tp2")
            .verifyResults(new String[]{"100", "200"});
    listOfTables.addAll(Arrays.asList("t3", "t4", "tp2"));
    verifyCustomDBLocations(srcDb, listOfTables, dbWhManagedLoc, dbWhExternalLoc, true);
  }
Test replication scenarios with staging on replica.
itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/parse/TestReplicationScenariosExclusiveReplica.java