@Test
    public void testEventQueueOperationsStartedMetric() throws Throwable {
        try (
            LocalLogManagerTestEnv logEnv = new LocalLogManagerTestEnv.Builder(3).
                                                build();
            QuorumControllerTestEnv controlEnv = new QuorumControllerTestEnv.Builder(logEnv).
                                                     build()
        ) {
            QuorumController active = controlEnv.activeController();
            Map<Integer, Long> brokerEpochs = registerBrokersAndUnfence(active, 3);

            // Test that a new operation increments operationsStarted. We retry this if needed
            // to handle the case where another operation is performed in between loading
            // expectedOperationsStarted and running the new control event.
            TestUtils.retryOnExceptionWithTimeout(30_000, () -> {
                long expectedOperationsStarted = active.controllerMetrics().operationsStarted() + 1;
                CompletableFuture<Long> actualOperationsStarted = new CompletableFuture<>();
                active.appendControlEvent("checkOperationsStarted", () ->
                    actualOperationsStarted.complete(active.controllerMetrics().operationsStarted())
                );
                assertEquals(expectedOperationsStarted, actualOperationsStarted.get());
            });
        }
    }
Test the event queue operations started metric.
metadata/src/test/java/org/apache/kafka/controller/QuorumControllerMetricsIntegrationTest.java