public void renameDirectory(Path source, Path target, Runnable runWhenPathNotExist) {
        if (pathExists(target)) {
            throw new StarRocksConnectorException("Unable to rename from %s to %s. msg: target directory already exists",
                    source, target);
        }

        if (!pathExists(target.getParent())) {
            createDirectory(target.getParent(), conf);
        }

        runWhenPathNotExist.run();

        try {
            if (!FileSystem.get(source.toUri(), conf).rename(source, target)) {
                throw new StarRocksConnectorException("Failed to rename %s to %s: rename returned false", source, target);
            }
        } catch (IOException e) {
            throw new StarRocksConnectorException("Failed to rename %s to %s, msg: %s", source, target, e.getMessage());
        }
    }
@Test
    public void testRenameDirFailed() {
        HiveRemoteFileIO hiveRemoteFileIO = new HiveRemoteFileIO(new Configuration());
        FileSystem fs = new MockedRemoteFileSystem(HDFS_HIVE_TABLE);
        hiveRemoteFileIO.setFileSystem(fs);
        FeConstants.runningUnitTest = true;
        ExecutorService executorToRefresh = Executors.newSingleThreadExecutor();
        ExecutorService executorToLoad = Executors.newSingleThreadExecutor();
        CachingRemoteFileIO cachingFileIO = new CachingRemoteFileIO(hiveRemoteFileIO, executorToRefresh, 10, 10, 10);
        RemoteFileOperations ops = new RemoteFileOperations(cachingFileIO, executorToLoad, executorToLoad,
                false, true, new Configuration());

        Path writePath = new Path("hdfs://hadoop01:9000/tmp/starrocks/queryid");
        Path targetPath = new Path("hdfs://hadoop01:9000/user/hive/warehouse/test.db/t1");
        FileSystem mockedFs = new MockedRemoteFileSystem(HDFS_HIVE_TABLE) {
            @Override
            public boolean exists(Path path) {
                if (path.equals(targetPath.getParent())) {
                    return true;
                } else {
                    return false;
                }
            }
        };

        new MockUp<FileSystem>() {
            @Mock
            public FileSystem get(URI uri, Configuration conf) throws IOException {
                return mockedFs;
            }
        };

        ExceptionChecker.expectThrowsWithMsg(
                StarRocksConnectorException.class,
                "Failed to rename",
                () -> ops.renameDirectory(writePath, targetPath, () -> {
                }));
    }