private TServer newThriftServer(TServerSocket socket, int poolSize, HiveConf conf)
      throws Exception {
    HiveConf serverConf = new HiveConf(conf);
    String derbyPath = getDerbyPath();
    LOG.info("DerbyPath: {}", derbyPath);
    String derbyUrl = "jdbc:derby:;databaseName=" + derbyPath + ";create=true";
    // when test iceberg with hive catalog, Exception `java.sql.SQLSyntaxErrorException: Table/View
    // 'HIVE_LOCKS' does
    // not exist.` will throw, this is a bug of hive scheamtools, see
    // https://issues.apache.org/jira/browse/HIVE-21302.
    // so we set up metastore first to avoid this bug.
    setupMetastoreDB(derbyUrl);

    serverConf.set(HiveConf.ConfVars.METASTORECONNECTURLKEY.varname, derbyUrl);
    baseHandler = HMS_HANDLER_CTOR.newInstance("new db based metaserver", serverConf);
    IHMSHandler handler = GET_BASE_HMS_HANDLER.invoke(serverConf, baseHandler, false);

    SynchronousQueue<Runnable> executorQueue = new SynchronousQueue<Runnable>();
    AtomicInteger threadCount = new AtomicInteger(0);
    ThreadPoolExecutor hiveThriftServerThreadPool =
        new ThreadPoolExecutor(
            1,
            poolSize,
            60,
            TimeUnit.SECONDS,
            executorQueue,
            r -> {
              Thread thread = new Thread(r);
              String threadName = "hms-pool-" + threadCount.incrementAndGet();
              thread.setName(threadName);
              LOG.info("HMSMockServer create thread: {}", threadName);
              return thread;
            },
            new ThreadPoolExecutor.AbortPolicy());

    TThreadPoolServer.Args args =
        new TThreadPoolServer.Args(socket)
            .processor(new TSetIpAddressProcessor<>(handler))
            .transportFactory(new TTransportFactory())
            .protocolFactory(new TBinaryProtocol.Factory())
            .executorService(hiveThriftServerThreadPool);

    return new TThreadPoolServer(args);
  }
Starts a TestHiveMetastore with a provided connection pool size.

@param poolSize The number of threads in the executor pool
amoro-common/src/test/java/org/apache/amoro/hive/HMSMockServer.java