@Test public void testQueryLoggingCount() { QueryManager queryManager = ((DistributedQueryRunner) getQueryRunner()).getCoordinator().getQueryManager(); executeExclusively(() -> { assertUntilTimeout( () -> assertEquals( queryManager.getQueries().stream() .map(BasicQueryInfo::getQueryId) .map(queryManager::getFullQueryInfo) .filter(info -> !info.isFinalQueryInfo()) .collect(toList()), ImmutableList.of()), new Duration(1, MINUTES)); // We cannot simply get the number of completed queries as soon as all the queries are completed, because this counter may not be up-to-date at that point. // The completed queries counter is updated in a final query info listener, which is called eventually. // Therefore, here we wait until the value of this counter gets stable. long beforeCompletedQueriesCount = waitUntilStable(() -> queryManager.getStats().getCompletedQueries().getTotalCount(), new Duration(5, SECONDS)); long beforeSubmittedQueriesCount = queryManager.getStats().getSubmittedQueries().getTotalCount(); assertUpdate("CREATE TABLE test_query_logging_count AS SELECT 1 foo_1, 2 foo_2_4", 1); assertQuery("SELECT foo_1, foo_2_4 FROM test_query_logging_count", "SELECT 1, 2"); assertUpdate("DROP TABLE test_query_logging_count"); assertQueryFails("SELECT * FROM test_query_logging_count", ".*Table .* does not exist"); // TODO: Figure out a better way of synchronization assertUntilTimeout( () -> assertEquals(queryManager.getStats().getCompletedQueries().getTotalCount() - beforeCompletedQueriesCount, 4), new Duration(1, MINUTES)); assertEquals(queryManager.getStats().getSubmittedQueries().getTotalCount() - beforeSubmittedQueriesCount, 4); }); }
@Test public void testQueryLoggingCount() { QueryManager queryManager = ((DistributedQueryRunner) getQueryRunner()).getCoordinator().getQueryManager(); executeExclusively(() -> { assertUntilTimeout( () -> assertEquals( queryManager.getQueries().stream() .map(BasicQueryInfo::getQueryId) .map(queryManager::getFullQueryInfo) .filter(info -> !info.isFinalQueryInfo()) .collect(toList()), ImmutableList.of()), new Duration(1, MINUTES)); // We cannot simply get the number of completed queries as soon as all the queries are completed, because this counter may not be up-to-date at that point. // The completed queries counter is updated in a final query info listener, which is called eventually. // Therefore, here we wait until the value of this counter gets stable. long beforeCompletedQueriesCount = waitUntilStable(() -> queryManager.getStats().getCompletedQueries().getTotalCount(), new Duration(5, SECONDS)); long beforeSubmittedQueriesCount = queryManager.getStats().getSubmittedQueries().getTotalCount(); assertUpdate("CREATE TABLE test_query_logging_count AS SELECT 1 foo_1, 2 foo_2_4", 1); assertQuery("SELECT foo_1, foo_2_4 FROM test_query_logging_count", "SELECT 1, 2"); assertUpdate("DROP TABLE test_query_logging_count"); assertQueryFails("SELECT * FROM test_query_logging_count", ".*Table .* does not exist"); // TODO: Figure out a better way of synchronization assertUntilTimeout( () -> assertEquals(queryManager.getStats().getCompletedQueries().getTotalCount() - beforeCompletedQueriesCount, 4), new Duration(1, MINUTES)); assertEquals(queryManager.getStats().getSubmittedQueries().getTotalCount() - beforeSubmittedQueriesCount, 4); }); }