@Test
public void testExportWithRS() throws Exception {

    ArrayList<ServerName> serverNameList;
    List<HRegionInfo> regionInfoList;
    ServerName rs1, rs2;
    List<String> assignmentList;
    String expFileName = "export_test.exp";
    splitTable("a".getBytes());
    splitTable("b".getBytes());
    serverNameList = getServerNameList();
    rs1 = serverNameList.get(0);
    rs2 = serverNameList.get(1);
    // move all regions to rs1 except 1
    regionInfoList = getRegionInfoList(tableName);
    for (HRegionInfo hRegionInfo : regionInfoList)
        move(hRegionInfo, rs1);
    HRegionInfo firstRegion = regionInfoList.get(0);
    move(firstRegion, rs2);
    assertEquals(regionInfoList.size() - 1, getRegionInfoList(rs1, tableName).size());
    assertEquals(1, getRegionInfoList(rs2, tableName).size());
    boolean balancerRunning = false;
    try {
        String[] argsParam;
        Args args;
        Assign command;
        balancerRunning = admin.setBalancerRunning(false, true);
        // export with full RS name
        argsParam = new String[]{"zookeeper", "export", expFileName, "--rs=" + rs1.getServerName()};
        args = new ManagerArgs(argsParam);
        command = new Assign(admin, args);
        command.run();
        assignmentList = readExportFile(expFileName);
        assertEquals(AssignAction.getProcessedCount(), assignmentList.size());
        for (String assignment : assignmentList) {
            assertFalse(firstRegion.getEncodedName() + " must not be exported.",
                assignment.contains(firstRegion.getEncodedName()));
        }
        // export with regex RS name
        String regex = rs2.getServerName().substring(0, rs2.getServerName().indexOf(',')) + ".*";
        argsParam = new String[]{"zookeeper", "export", expFileName, "--rs=" + regex};
        args = new ManagerArgs(argsParam);
        command = new Assign(admin, args);
        command.run();
        assignmentList = readExportFile(expFileName);
        assertEquals(AssignAction.getProcessedCount(), assignmentList.size());
        int actual = 0;
        for (String assignment : assignmentList) {
            if (assignment.contains(firstRegion.getEncodedName()))
                actual++;
        }
        assertEquals(firstRegion.getEncodedName() + " must be exported.", 1, actual);
    } finally {
        if (balancerRunning)
            admin.setBalancerRunning(true, true);
        Files.delete(Paths.get(expFileName));
    }
}