Search in sources :

Example 96 with Duration

use of io.airlift.units.Duration in project presto by prestodb.

the class TestSplitConcurrencyController method testRapidAdjustForQuickSplits.

@Test
public void testRapidAdjustForQuickSplits() {
    SplitConcurrencyController controller = new SplitConcurrencyController(10, new Duration(1, SECONDS));
    for (int i = 0; i < 9; i++) {
        controller.update(MILLISECONDS.toNanos(200), 1, 10 - i);
        controller.splitFinished(MILLISECONDS.toNanos(100), 1, 10 - i);
        assertEquals(controller.getTargetConcurrency(), 10 - i - 1);
    }
    controller.update(SECONDS.toNanos(30), 0, 1);
    for (int i = 0; i < 10; i++) {
        controller.update(SECONDS.toNanos(200), 0, i + 1);
        controller.splitFinished(MILLISECONDS.toNanos(100), 0, i + 1);
        assertEquals(controller.getTargetConcurrency(), i + 2);
    }
}
Also used : Duration(io.airlift.units.Duration) Test(org.testng.annotations.Test)

Example 97 with Duration

use of io.airlift.units.Duration in project presto by prestodb.

the class TestServerConfig method testExplicitPropertyMappings.

@Test
public void testExplicitPropertyMappings() {
    Map<String, String> properties = new ImmutableMap.Builder<String, String>().put("coordinator", "false").put("presto.version", "test").put("datasources", "jmx").put("http.include-exception-in-response", "false").put("shutdown.grace-period", "5m").build();
    ServerConfig expected = new ServerConfig().setCoordinator(false).setPrestoVersion("test").setDataSources("jmx").setIncludeExceptionInResponse(false).setGracePeriod(new Duration(5, MINUTES));
    assertFullMapping(properties, expected);
}
Also used : Duration(io.airlift.units.Duration) Test(org.testng.annotations.Test)

Example 98 with Duration

use of io.airlift.units.Duration in project presto by prestodb.

the class TestBackoff method testMaxFailureInterval.

@Test
public void testMaxFailureInterval() {
    TestingTicker ticker = new TestingTicker();
    Backoff backoff = new Backoff(new Duration(5, SECONDS), new Duration(15, SECONDS), ticker, new Duration(10, MILLISECONDS));
    ticker.increment(10, MICROSECONDS);
    ticker.increment(6, SECONDS);
    assertTrue(backoff.failure());
    assertEquals(backoff.getFailureCount(), 1);
    assertEquals(backoff.getTimeSinceLastSuccess().roundTo(SECONDS), 6);
    backoff.success();
    // Check that we will tolerate failures for longer than the min, if the query has been running that long
    ticker.increment(6, SECONDS);
    assertFalse(backoff.failure());
    assertEquals(backoff.getFailureCount(), 1);
    assertEquals(backoff.getTimeSinceLastSuccess().roundTo(SECONDS), 6);
    ticker.increment(1, SECONDS);
    // Check that we won't tolerate failures for longer than the query has been running
    assertTrue(backoff.failure());
    assertEquals(backoff.getFailureCount(), 2);
    assertEquals(backoff.getTimeSinceLastSuccess().roundTo(SECONDS), 7);
    ticker.increment(20, SECONDS);
    backoff.success();
    ticker.increment(20, SECONDS);
    // Check that we won't tolerate failures for longer than the max, even if the query has been running for a long time
    assertTrue(backoff.failure());
    assertEquals(backoff.getFailureCount(), 1);
    assertEquals(backoff.getTimeSinceLastSuccess().roundTo(SECONDS), 20);
}
Also used : TestingTicker(io.airlift.testing.TestingTicker) Duration(io.airlift.units.Duration) Test(org.testng.annotations.Test)

Example 99 with Duration

use of io.airlift.units.Duration in project presto by prestodb.

the class TestBackoff method testStartRequest.

@Test
public void testStartRequest() {
    TestingTicker ticker = new TestingTicker();
    Backoff backoff = new Backoff(new Duration(15, SECONDS), new Duration(15, SECONDS), ticker, new Duration(10, MILLISECONDS));
    ticker.increment(10, MICROSECONDS);
    assertEquals(backoff.getFailureCount(), 0);
    assertEquals(backoff.getTimeSinceLastSuccess().roundTo(SECONDS), 0);
    ticker.increment(14, SECONDS);
    backoff.startRequest();
    ticker.increment(14, SECONDS);
    assertFalse(backoff.failure());
    assertEquals(backoff.getFailureCount(), 1);
    assertEquals(backoff.getTimeSinceLastSuccess().roundTo(SECONDS), 28);
    ticker.increment(1, SECONDS);
    assertTrue(backoff.failure());
    assertEquals(backoff.getFailureCount(), 2);
    assertEquals(backoff.getTimeSinceLastSuccess().roundTo(SECONDS), 29);
}
Also used : TestingTicker(io.airlift.testing.TestingTicker) Duration(io.airlift.units.Duration) Test(org.testng.annotations.Test)

Example 100 with Duration

use of io.airlift.units.Duration in project presto by prestodb.

the class TestHttpRemoteTask method testRemoteTaskMismatch.

// This timeout should never be reached because a daemon thread in test should fail the test and do proper cleanup.
@Test(timeOut = 30000)
public void testRemoteTaskMismatch() throws InterruptedException, ExecutionException {
    Duration idleTimeout = new Duration(3, SECONDS);
    Duration failTimeout = new Duration(20, SECONDS);
    JsonCodec<TaskStatus> taskStatusCodec = JsonCodec.jsonCodec(TaskStatus.class);
    JsonCodec<TaskInfo> taskInfoCodec = JsonCodec.jsonCodec(TaskInfo.class);
    TaskManagerConfig taskManagerConfig = new TaskManagerConfig();
    // Shorten status refresh wait and info update interval so that we can have a shorter test timeout
    taskManagerConfig.setStatusRefreshMaxWait(new Duration(idleTimeout.roundTo(MILLISECONDS) / 100, MILLISECONDS));
    taskManagerConfig.setInfoUpdateInterval(new Duration(idleTimeout.roundTo(MILLISECONDS) / 10, MILLISECONDS));
    AtomicLong lastActivityNanos = new AtomicLong(System.nanoTime());
    HttpProcessor httpProcessor = new HttpProcessor(taskStatusCodec, taskInfoCodec, lastActivityNanos);
    TestingHttpClient testingHttpClient = new TestingHttpClient(httpProcessor);
    HttpRemoteTaskFactory httpRemoteTaskFactory = new HttpRemoteTaskFactory(new QueryManagerConfig(), taskManagerConfig, testingHttpClient, new TestSqlTaskManager.MockLocationFactory(), taskStatusCodec, taskInfoCodec, JsonCodec.jsonCodec(TaskUpdateRequest.class), new RemoteTaskStats());
    RemoteTask remoteTask = httpRemoteTaskFactory.createRemoteTask(TEST_SESSION, new TaskId("test", 1, 2), new PrestoNode("node-id", URI.create("http://192.0.1.2"), new NodeVersion("version"), false), TaskTestUtils.PLAN_FRAGMENT, ImmutableMultimap.of(), createInitialEmptyOutputBuffers(OutputBuffers.BufferType.BROADCAST), new NodeTaskMap.PartitionedSplitCountTracker(i -> {
    }), true);
    httpProcessor.setInitialTaskInfo(remoteTask.getTaskInfo());
    remoteTask.start();
    CompletableFuture<Void> testComplete = new CompletableFuture<>();
    asyncRun(idleTimeout.roundTo(MILLISECONDS), failTimeout.roundTo(MILLISECONDS), lastActivityNanos, () -> testComplete.complete(null), (message, cause) -> testComplete.completeExceptionally(new AssertionError(message, cause)));
    testComplete.get();
    httpRemoteTaskFactory.stop();
    assertTrue(remoteTask.getTaskStatus().getState().isDone(), format("TaskStatus is not in a done state: %s", remoteTask.getTaskStatus()));
    assertEquals(getOnlyElement(remoteTask.getTaskStatus().getFailures()).getErrorCode(), REMOTE_TASK_MISMATCH.toErrorCode());
    assertTrue(remoteTask.getTaskInfo().getTaskStatus().getState().isDone(), format("TaskInfo is not in a done state: %s", remoteTask.getTaskInfo()));
}
Also used : OutputBuffers(com.facebook.presto.OutputBuffers) CONTENT_TYPE(javax.ws.rs.core.HttpHeaders.CONTENT_TYPE) NodeTaskMap(com.facebook.presto.execution.NodeTaskMap) TaskStatus(com.facebook.presto.execution.TaskStatus) Assert.assertEquals(org.testng.Assert.assertEquals) TaskState(com.facebook.presto.execution.TaskState) Test(org.testng.annotations.Test) CompletableFuture(java.util.concurrent.CompletableFuture) NodeVersion(com.facebook.presto.client.NodeVersion) TaskManagerConfig(com.facebook.presto.execution.TaskManagerConfig) Duration(io.airlift.units.Duration) PRESTO_TASK_INSTANCE_ID(com.facebook.presto.client.PrestoHeaders.PRESTO_TASK_INSTANCE_ID) TEST_SESSION(com.facebook.presto.SessionTestUtils.TEST_SESSION) Request(io.airlift.http.client.Request) BiConsumer(java.util.function.BiConsumer) TestingResponse(io.airlift.http.client.testing.TestingResponse) QueryManagerConfig(com.facebook.presto.execution.QueryManagerConfig) URI(java.net.URI) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) REMOTE_TASK_MISMATCH(com.facebook.presto.spi.StandardErrorCode.REMOTE_TASK_MISMATCH) TestingHttpClient(io.airlift.http.client.testing.TestingHttpClient) TestSqlTaskManager(com.facebook.presto.execution.TestSqlTaskManager) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) PrestoNode(com.facebook.presto.metadata.PrestoNode) StandardCharsets(java.nio.charset.StandardCharsets) PRESTO_MAX_WAIT(com.facebook.presto.client.PrestoHeaders.PRESTO_MAX_WAIT) String.format(java.lang.String.format) ExecutionException(java.util.concurrent.ExecutionException) AtomicLong(java.util.concurrent.atomic.AtomicLong) RemoteTask(com.facebook.presto.execution.RemoteTask) TaskTestUtils(com.facebook.presto.execution.TaskTestUtils) HttpStatus(io.airlift.http.client.HttpStatus) TaskId(com.facebook.presto.execution.TaskId) HttpRemoteTaskFactory(com.facebook.presto.server.HttpRemoteTaskFactory) ImmutableListMultimap(com.google.common.collect.ImmutableListMultimap) Response(io.airlift.http.client.Response) OutputBuffers.createInitialEmptyOutputBuffers(com.facebook.presto.OutputBuffers.createInitialEmptyOutputBuffers) Assert.assertTrue(org.testng.Assert.assertTrue) TaskUpdateRequest(com.facebook.presto.server.TaskUpdateRequest) TaskInfo(com.facebook.presto.execution.TaskInfo) SECONDS(java.util.concurrent.TimeUnit.SECONDS) JsonCodec(io.airlift.json.JsonCodec) TaskId(com.facebook.presto.execution.TaskId) TaskManagerConfig(com.facebook.presto.execution.TaskManagerConfig) TestSqlTaskManager(com.facebook.presto.execution.TestSqlTaskManager) PrestoNode(com.facebook.presto.metadata.PrestoNode) TaskInfo(com.facebook.presto.execution.TaskInfo) NodeVersion(com.facebook.presto.client.NodeVersion) CompletableFuture(java.util.concurrent.CompletableFuture) TestingHttpClient(io.airlift.http.client.testing.TestingHttpClient) HttpRemoteTaskFactory(com.facebook.presto.server.HttpRemoteTaskFactory) NodeTaskMap(com.facebook.presto.execution.NodeTaskMap) TaskUpdateRequest(com.facebook.presto.server.TaskUpdateRequest) RemoteTask(com.facebook.presto.execution.RemoteTask) Duration(io.airlift.units.Duration) TaskStatus(com.facebook.presto.execution.TaskStatus) AtomicLong(java.util.concurrent.atomic.AtomicLong) QueryManagerConfig(com.facebook.presto.execution.QueryManagerConfig) Test(org.testng.annotations.Test)

Aggregations

Duration (io.airlift.units.Duration)124 Test (org.testng.annotations.Test)66 DataSize (io.airlift.units.DataSize)35 URI (java.net.URI)12 TestingHttpClient (io.airlift.http.client.testing.TestingHttpClient)11 Session (com.facebook.presto.Session)9 DateTime (org.joda.time.DateTime)9 ImmutableMap (com.google.common.collect.ImmutableMap)8 ImmutableSet (com.google.common.collect.ImmutableSet)8 TestingTicker (io.airlift.testing.TestingTicker)8 List (java.util.List)8 PrestoException (com.facebook.presto.spi.PrestoException)7 ImmutableList (com.google.common.collect.ImmutableList)7 File (java.io.File)6 PlanNodeId (com.facebook.presto.sql.planner.plan.PlanNodeId)5 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)5 CyclicBarrier (java.util.concurrent.CyclicBarrier)5 Produces (javax.ws.rs.Produces)5 Type (com.facebook.presto.spi.type.Type)4 IOException (java.io.IOException)4