zstan commented on code in PR #4699: URL: https://github.com/apache/ignite-3/pull/4699#discussion_r1839893806
########## modules/sql-engine/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItComputeSystemViewTest.java: ########## @@ -0,0 +1,309 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.sql.engine; + +import static java.util.concurrent.CompletableFuture.completedFuture; +import static org.apache.ignite.compute.JobStatus.CANCELED; +import static org.apache.ignite.compute.JobStatus.EXECUTING; +import static org.apache.ignite.internal.TestWrappers.unwrapIgniteImpl; +import static org.apache.ignite.internal.sql.engine.util.Commons.closeQuiet; +import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willBe; +import static org.apache.ignite.internal.testframework.matchers.JobStateMatcher.jobStateWithStatus; +import static org.apache.ignite.internal.testframework.matchers.TaskStateMatcher.taskStateWithStatus; +import static org.awaitility.Awaitility.await; +import static org.hamcrest.CoreMatchers.hasItem; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.greaterThanOrEqualTo; +import static org.hamcrest.Matchers.hasLength; +import static org.hamcrest.Matchers.lessThanOrEqualTo; + +import java.time.Instant; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.UUID; +import java.util.concurrent.CompletableFuture; +import org.apache.ignite.Ignite; +import org.apache.ignite.client.IgniteClient; +import org.apache.ignite.compute.ComputeJob; +import org.apache.ignite.compute.JobDescriptor; +import org.apache.ignite.compute.JobExecution; +import org.apache.ignite.compute.JobExecutionContext; +import org.apache.ignite.compute.JobTarget; +import org.apache.ignite.compute.TaskDescriptor; +import org.apache.ignite.compute.TaskStatus; +import org.apache.ignite.compute.task.MapReduceJob; +import org.apache.ignite.compute.task.MapReduceTask; +import org.apache.ignite.compute.task.TaskExecution; +import org.apache.ignite.compute.task.TaskExecutionContext; +import org.apache.ignite.internal.hlc.ClockService; +import org.apache.ignite.internal.sql.BaseSqlIntegrationTest; +import org.apache.ignite.internal.sql.engine.util.MetadataMatcher; +import org.apache.ignite.internal.testframework.IgniteTestUtils; +import org.apache.ignite.network.ClusterNode; +import org.apache.ignite.sql.ColumnType; +import org.hamcrest.Matchers; +import org.jetbrains.annotations.Nullable; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +/** + * End-to-end tests to verify {@code COMPUTE_TASKS} system view. + */ +public class ItComputeSystemViewTest extends BaseSqlIntegrationTest { + @Override + protected int initialNodes() { + return 2; + } + + @ParameterizedTest + @ValueSource(booleans = {true, false}) + public void checkMeta(boolean isClient) { + String query = "SELECT * FROM SYSTEM.COMPUTE_TASKS"; + + Ignite entryNode = isClient ? IgniteClient.builder().addresses("localhost").build() : CLUSTER.node(0); + Ignite targetNode = CLUSTER.node(0); + + JobDescriptor<Void, Void> job = JobDescriptor.builder(InfiniteJob.class).units(List.of()).build(); + JobExecution<Void> execution = entryNode.compute().submit(JobTarget.node(clusterNode(targetNode)), job, null); + + await().until(execution::stateAsync, willBe(jobStateWithStatus(EXECUTING))); + + try { + // Verify metadata. + assertQuery(query) + .withDefaultSchema("SYSTEM") + .columnMetadata( + new MetadataMatcher().name("COORDINATOR_NODE_ID").type(ColumnType.STRING).nullable(false), + new MetadataMatcher().name("ID").type(ColumnType.STRING).precision(36).nullable(true), + new MetadataMatcher().name("STATUS").type(ColumnType.STRING).nullable(true), + new MetadataMatcher().name("CREATE_TIME").type(ColumnType.TIMESTAMP).nullable(true), + new MetadataMatcher().name("START_TIME").type(ColumnType.TIMESTAMP).nullable(true), + new MetadataMatcher().name("FINISH_TIME").type(ColumnType.TIMESTAMP).nullable(true) + ) + .check(); + } finally { + execution.cancelAsync(); + + await().until(execution::stateAsync, willBe(jobStateWithStatus(CANCELED))); + + closeQuiet(entryNode); + } + } + + @ParameterizedTest + @ValueSource(booleans = {true, false}) + void viewRunningJobs(boolean isClient) { + Ignite entryNode = isClient ? IgniteClient.builder().addresses("localhost").build() : CLUSTER.node(0); + Ignite targetNode = CLUSTER.node(0); + + try { + ClockService clockService = unwrapIgniteImpl(targetNode).clockService(); + + long tsBefore = clockService.now().getPhysical(); + + JobDescriptor<Void, Void> job = JobDescriptor.builder(InfiniteJob.class).units(List.of()).build(); + JobExecution<Void> execution = entryNode.compute().submit(JobTarget.node(clusterNode(targetNode)), job, null); + + await().until(execution::stateAsync, willBe(jobStateWithStatus(EXECUTING))); + + long tsAfter = clockService.now().getPhysical(); + + String query = "SELECT * FROM SYSTEM.COMPUTE_TASKS WHERE STATUS = ?"; + + List<List<Object>> res = sql(0, query, EXECUTING.name()); + + verifyQueryInfo(res.get(0), List.of(targetNode.name()), EXECUTING.name(), tsBefore, tsAfter); + + IgniteTestUtils.await(execution.cancelAsync()); + + await().until(execution::stateAsync, willBe(jobStateWithStatus(CANCELED))); + + // Second Job call on different node. + job = JobDescriptor.builder(InfiniteJob.class).units(List.of()).build(); + + tsBefore = clockService.now().getPhysical(); + + targetNode = CLUSTER.node(1); + + execution = entryNode.compute().submit(JobTarget.node(clusterNode(targetNode)), job, null); + + await().until(execution::stateAsync, willBe(jobStateWithStatus(EXECUTING))); + + tsAfter = clockService.now().getPhysical(); + + query = "SELECT * FROM SYSTEM.COMPUTE_TASKS WHERE COORDINATOR_NODE_ID = ? AND STATUS = ?"; + + res = sql(0, query, targetNode.name(), EXECUTING.name()); + + verifyQueryInfo(res.get(0), List.of(targetNode.name()), EXECUTING.name(), tsBefore, tsAfter); + + IgniteTestUtils.await(execution.cancelAsync()); + + await().until(execution::stateAsync, willBe(jobStateWithStatus(CANCELED))); Review Comment: in such a case we need to check inner compute api invariants, i don\`t like it .. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@ignite.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org