Search in sources :

Example 26 with TestingPrestoServer

use of com.facebook.presto.server.testing.TestingPrestoServer in project presto by prestodb.

the class TestHiveRecoverableExecution method testRecoverableGroupedExecution.

private void testRecoverableGroupedExecution(DistributedQueryRunner queryRunner, int writerConcurrency, boolean optimizedPartitionUpdateSerializationEnabled, List<String> preQueries, @Language("SQL") String queryWithoutFailure, @Language("SQL") String queryWithFailure, int expectedUpdateCount, List<String> postQueries) throws Exception {
    waitUntilAllNodesAreHealthy(queryRunner, new Duration(10, SECONDS));
    Session recoverableSession = createRecoverableSession(writerConcurrency, optimizedPartitionUpdateSerializationEnabled);
    for (@Language("SQL") String postQuery : postQueries) {
        queryRunner.execute(recoverableSession, postQuery);
    }
    try {
        for (@Language("SQL") String preQuery : preQueries) {
            queryRunner.execute(recoverableSession, preQuery);
        }
        // test no failure case
        Stopwatch noRecoveryStopwatch = Stopwatch.createStarted();
        assertEquals(queryRunner.execute(recoverableSession, queryWithoutFailure).getUpdateCount(), OptionalLong.of(expectedUpdateCount));
        log.info("Query with no recovery took %sms", noRecoveryStopwatch.elapsed(MILLISECONDS));
        // cancel all queries and tasks to make sure we are dealing only with a single running query
        cancelAllQueries(queryRunner);
        cancelAllTasks(queryRunner);
        // test failure case
        Stopwatch recoveryStopwatch = Stopwatch.createStarted();
        ListenableFuture<MaterializedResult> result = executor.submit(() -> queryRunner.execute(recoverableSession, queryWithFailure));
        List<TestingPrestoServer> workers = queryRunner.getServers().stream().filter(server -> !server.isCoordinator()).collect(toList());
        shuffle(workers);
        TestingPrestoServer worker1 = workers.get(0);
        // kill worker1 right away, to make sure recoverable execution works in cases when the task hasn't been yet submitted
        worker1.stopResponding();
        // kill worker2 only after the task has been scheduled
        TestingPrestoServer worker2 = workers.get(1);
        sleep(1000);
        worker2.stopResponding();
        assertEquals(result.get(1000, SECONDS).getUpdateCount(), OptionalLong.of(expectedUpdateCount));
        log.info("Query with recovery took %sms", recoveryStopwatch.elapsed(MILLISECONDS));
    } finally {
        queryRunner.getServers().forEach(TestingPrestoServer::startResponding);
        cancelAllQueries(queryRunner);
        cancelAllTasks(queryRunner);
        for (@Language("SQL") String postQuery : postQueries) {
            queryRunner.execute(recoverableSession, postQuery);
        }
    }
}
Also used : Collections.shuffle(java.util.Collections.shuffle) TestingPrestoServer(com.facebook.presto.server.testing.TestingPrestoServer) TimeoutException(java.util.concurrent.TimeoutException) Test(org.testng.annotations.Test) DistributedQueryRunner(com.facebook.presto.tests.DistributedQueryRunner) Duration(io.airlift.units.Duration) RECOVERABLE_GROUPED_EXECUTION(com.facebook.presto.SystemSessionProperties.RECOVERABLE_GROUPED_EXECUTION) Thread.sleep(java.lang.Thread.sleep) TASK_WRITER_COUNT(com.facebook.presto.SystemSessionProperties.TASK_WRITER_COUNT) EXCHANGE_MATERIALIZATION_STRATEGY(com.facebook.presto.SystemSessionProperties.EXCHANGE_MATERIALIZATION_STRATEGY) TASK_PARTITIONED_WRITER_COUNT(com.facebook.presto.SystemSessionProperties.TASK_PARTITIONED_WRITER_COUNT) ImmutableMap(com.google.common.collect.ImmutableMap) BeforeClass(org.testng.annotations.BeforeClass) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) String.format(java.lang.String.format) List(java.util.List) HASH_PARTITION_COUNT(com.facebook.presto.SystemSessionProperties.HASH_PARTITION_COUNT) CONCURRENT_LIFESPANS_PER_NODE(com.facebook.presto.SystemSessionProperties.CONCURRENT_LIFESPANS_PER_NODE) Optional(java.util.Optional) VIRTUAL_BUCKET_COUNT(com.facebook.presto.hive.HiveSessionProperties.VIRTUAL_BUCKET_COUNT) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) MoreExecutors.listeningDecorator(com.google.common.util.concurrent.MoreExecutors.listeningDecorator) Logger(com.facebook.airlift.log.Logger) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) DataProvider(org.testng.annotations.DataProvider) TPCH_BUCKETED_SCHEMA(com.facebook.presto.hive.HiveQueryRunner.TPCH_BUCKETED_SCHEMA) Stopwatch(com.google.common.base.Stopwatch) PARTITIONING_PROVIDER_CATALOG(com.facebook.presto.SystemSessionProperties.PARTITIONING_PROVIDER_CATALOG) ALL(com.facebook.presto.spi.security.SelectedRole.Type.ALL) ORDERS(io.airlift.tpch.TpchTable.ORDERS) Assert.assertEquals(org.testng.Assert.assertEquals) ROLE(com.facebook.presto.spi.security.SelectedRole.Type.ROLE) OptionalLong(java.util.OptionalLong) OPTIMIZED_PARTITION_UPDATE_SERIALIZATION_ENABLED(com.facebook.presto.hive.HiveSessionProperties.OPTIMIZED_PARTITION_UPDATE_SERIALIZATION_ENABLED) ImmutableList(com.google.common.collect.ImmutableList) Identity(com.facebook.presto.spi.security.Identity) GROUPED_EXECUTION(com.facebook.presto.SystemSessionProperties.GROUPED_EXECUTION) AfterClass(org.testng.annotations.AfterClass) SelectedRole(com.facebook.presto.spi.security.SelectedRole) HIVE_CATALOG(com.facebook.presto.hive.HiveQueryRunner.HIVE_CATALOG) Language(org.intellij.lang.annotations.Language) Session(com.facebook.presto.Session) MAX_STAGE_RETRIES(com.facebook.presto.SystemSessionProperties.MAX_STAGE_RETRIES) TestingSession.testSessionBuilder(com.facebook.presto.testing.TestingSession.testSessionBuilder) AllNodes(com.facebook.presto.metadata.AllNodes) MaterializedResult(com.facebook.presto.testing.MaterializedResult) Collectors.toList(java.util.stream.Collectors.toList) Executors.newCachedThreadPool(java.util.concurrent.Executors.newCachedThreadPool) COLOCATED_JOIN(com.facebook.presto.SystemSessionProperties.COLOCATED_JOIN) REDISTRIBUTE_WRITES(com.facebook.presto.SystemSessionProperties.REDISTRIBUTE_WRITES) SECONDS(java.util.concurrent.TimeUnit.SECONDS) SCALE_WRITERS(com.facebook.presto.SystemSessionProperties.SCALE_WRITERS) Language(org.intellij.lang.annotations.Language) Stopwatch(com.google.common.base.Stopwatch) TestingPrestoServer(com.facebook.presto.server.testing.TestingPrestoServer) Duration(io.airlift.units.Duration) MaterializedResult(com.facebook.presto.testing.MaterializedResult) Session(com.facebook.presto.Session)

Example 27 with TestingPrestoServer

use of com.facebook.presto.server.testing.TestingPrestoServer in project presto by prestodb.

the class TestServer method setup.

@BeforeMethod
public void setup() throws Exception {
    server = new TestingPrestoServer();
    client = new JettyHttpClient();
}
Also used : JettyHttpClient(com.facebook.airlift.http.client.jetty.JettyHttpClient) TestingPrestoServer(com.facebook.presto.server.testing.TestingPrestoServer) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 28 with TestingPrestoServer

use of com.facebook.presto.server.testing.TestingPrestoServer in project presto by prestodb.

the class DistributedQueryRunner method isConnectorVisibleToAllNodes.

private boolean isConnectorVisibleToAllNodes(ConnectorId connectorId) {
    if (!externalWorkers.isEmpty()) {
        return true;
    }
    for (TestingPrestoServer server : servers) {
        server.refreshNodes();
        Set<InternalNode> activeNodesWithConnector = server.getActiveNodesWithConnector(connectorId);
        if (activeNodesWithConnector.size() != servers.size()) {
            return false;
        }
    }
    return true;
}
Also used : TestingPrestoServer(com.facebook.presto.server.testing.TestingPrestoServer) InternalNode(com.facebook.presto.metadata.InternalNode)

Example 29 with TestingPrestoServer

use of com.facebook.presto.server.testing.TestingPrestoServer in project presto by prestodb.

the class DistributedQueryRunner method installPlugin.

@Override
public void installPlugin(Plugin plugin) {
    long start = nanoTime();
    for (TestingPrestoServer server : servers) {
        server.installPlugin(plugin);
    }
    log.info("Installed plugin %s in %s", plugin.getClass().getSimpleName(), nanosSince(start).convertToMostSuccinctTimeUnit());
}
Also used : TestingPrestoServer(com.facebook.presto.server.testing.TestingPrestoServer)

Example 30 with TestingPrestoServer

use of com.facebook.presto.server.testing.TestingPrestoServer in project presto by prestodb.

the class DistributedQueryRunner method createCatalog.

@Override
public void createCatalog(String catalogName, String connectorName, Map<String, String> properties) {
    long start = nanoTime();
    Set<ConnectorId> connectorIds = new HashSet<>();
    for (TestingPrestoServer server : servers) {
        connectorIds.add(server.createCatalog(catalogName, connectorName, properties));
    }
    ConnectorId connectorId = getOnlyElement(connectorIds);
    log.info("Created catalog %s (%s) in %s", catalogName, connectorId, nanosSince(start));
    // wait for all nodes to announce the new catalog
    start = nanoTime();
    while (!isConnectorVisibleToAllNodes(connectorId)) {
        Assertions.assertLessThan(nanosSince(start), new Duration(100, SECONDS), "waiting for connector " + connectorId + " to be initialized in every node");
        try {
            MILLISECONDS.sleep(10);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            throw new RuntimeException(e);
        }
    }
    log.info("Announced catalog %s (%s) in %s", catalogName, connectorId, nanosSince(start));
}
Also used : TestingPrestoServer(com.facebook.presto.server.testing.TestingPrestoServer) Duration(io.airlift.units.Duration) ConnectorId(com.facebook.presto.spi.ConnectorId) HashSet(java.util.HashSet)

Aggregations

TestingPrestoServer (com.facebook.presto.server.testing.TestingPrestoServer)47 Test (org.testng.annotations.Test)19 BeforeClass (org.testng.annotations.BeforeClass)16 DistributedQueryRunner (com.facebook.presto.tests.DistributedQueryRunner)13 ArrayList (java.util.ArrayList)9 JettyHttpClient (com.facebook.airlift.http.client.jetty.JettyHttpClient)7 FileResourceGroupConfigurationManagerFactory (com.facebook.presto.resourceGroups.FileResourceGroupConfigurationManagerFactory)6 NodeState (com.facebook.presto.spi.NodeState)6 QueryId (com.facebook.presto.spi.QueryId)6 Future (java.util.concurrent.Future)6 ServerInfoResource (com.facebook.presto.server.ServerInfoResource)5 BasicQueryInfo (com.facebook.presto.server.BasicQueryInfo)4 TpchPlugin (com.facebook.presto.tpch.TpchPlugin)4 ImmutableMap (com.google.common.collect.ImmutableMap)4 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)4 Response (javax.ws.rs.core.Response)4 Request (com.facebook.airlift.http.client.Request)3 TaskManager (com.facebook.presto.execution.TaskManager)3 BlackHolePlugin (com.facebook.presto.plugin.blackhole.BlackHolePlugin)3 TestShutdownAction (com.facebook.presto.server.testing.TestingPrestoServer.TestShutdownAction)3