public static void throwTooManyActivePersistentQueriesException(
      final KsqlExecutionContext executionContext,
      final KsqlConfig ksqlConfig,
      final String statementStr
  ) {
    final String sanitizedMessage = String.format(
        "Not executing statement(s) as it would cause the number "
            + "of active, persistent queries to exceed the configured limit. "
            + "Use the TERMINATE command to terminate existing queries, "
            + "or increase the '%s' setting via the 'ksql-server.properties' file. "
            + "Current persistent query count: %d. Configured limit: %d.",
        KsqlConfig.KSQL_ACTIVE_PERSISTENT_QUERY_LIMIT_CONFIG,
        executionContext.getPersistentQueries().size(),
        getQueryLimit(ksqlConfig)
    );
    final String unloggedMessage = String.format(
        "Not executing statement(s) '%s' as it would cause the number "
            + "of active, persistent queries to exceed the configured limit. "
            + "Use the TERMINATE command to terminate existing queries, "
            + "or increase the '%s' setting via the 'ksql-server.properties' file. "
            + "Current persistent query count: %d. Configured limit: %d.",
        statementStr,
        KsqlConfig.KSQL_ACTIVE_PERSISTENT_QUERY_LIMIT_CONFIG,
        executionContext.getPersistentQueries().size(),
        getQueryLimit(ksqlConfig)
    );
    throw new KsqlStatementException(
        sanitizedMessage,
        unloggedMessage,
        statementStr,
        KsqlStatementException.Problem.REQUEST
    );
  }
@Test
  public void shouldThrowWhenAsked() {
    // Given:
    final String statementStr = "my statement";
    givenActivePersistentQueries(3);
    givenQueryLimit(2);

    // When:
    final KsqlStatementException e = assertThrows(
        KsqlStatementException.class,
        () -> QueryCapacityUtil.throwTooManyActivePersistentQueriesException(
        ksqlEngine, ksqlConfig, statementStr)
    );

    // Then:
    assertThat(e.getUnloggedMessage(), containsString(
        "Not executing statement(s) 'my statement' as it would cause the number "
            + "of active, persistent queries to exceed the configured limit. "
            + "Use the TERMINATE command to terminate existing queries, "
            + "or increase the 'ksql.query.persistent.active.limit' setting "
            + "via the 'ksql-server.properties' file. "
            + "Current persistent query count: 3. Configured limit: 2."));
    assertThat(e.getMessage(), containsString(
        "Not executing statement(s) as it would cause the number "
            + "of active, persistent queries to exceed the configured limit. "
            + "Use the TERMINATE command to terminate existing queries, "
            + "or increase the 'ksql.query.persistent.active.limit' setting "
            + "via the 'ksql-server.properties' file. "
            + "Current persistent query count: 3. Configured limit: 2."));
    assertThat(e.getSqlStatement(), containsString("my statement"));
  }