Search in sources :

Example 1 with HttpRemoteTaskFactory

use of com.facebook.presto.server.HttpRemoteTaskFactory 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

OutputBuffers (com.facebook.presto.OutputBuffers)1 OutputBuffers.createInitialEmptyOutputBuffers (com.facebook.presto.OutputBuffers.createInitialEmptyOutputBuffers)1 TEST_SESSION (com.facebook.presto.SessionTestUtils.TEST_SESSION)1 NodeVersion (com.facebook.presto.client.NodeVersion)1 PRESTO_MAX_WAIT (com.facebook.presto.client.PrestoHeaders.PRESTO_MAX_WAIT)1 PRESTO_TASK_INSTANCE_ID (com.facebook.presto.client.PrestoHeaders.PRESTO_TASK_INSTANCE_ID)1 NodeTaskMap (com.facebook.presto.execution.NodeTaskMap)1 QueryManagerConfig (com.facebook.presto.execution.QueryManagerConfig)1 RemoteTask (com.facebook.presto.execution.RemoteTask)1 TaskId (com.facebook.presto.execution.TaskId)1 TaskInfo (com.facebook.presto.execution.TaskInfo)1 TaskManagerConfig (com.facebook.presto.execution.TaskManagerConfig)1 TaskState (com.facebook.presto.execution.TaskState)1 TaskStatus (com.facebook.presto.execution.TaskStatus)1 TaskTestUtils (com.facebook.presto.execution.TaskTestUtils)1 TestSqlTaskManager (com.facebook.presto.execution.TestSqlTaskManager)1 PrestoNode (com.facebook.presto.metadata.PrestoNode)1 HttpRemoteTaskFactory (com.facebook.presto.server.HttpRemoteTaskFactory)1 TaskUpdateRequest (com.facebook.presto.server.TaskUpdateRequest)1 REMOTE_TASK_MISMATCH (com.facebook.presto.spi.StandardErrorCode.REMOTE_TASK_MISMATCH)1