You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gravitino.apache.org by "jerryshao (via GitHub)" <gi...@apache.org> on 2025/08/11 06:37:45 UTC
[PR] [#7937] test(core): Add ITs for job system [gravitino]
jerryshao opened a new pull request, #8015:
URL: https://github.com/apache/gravitino/pull/8015
### What changes were proposed in this pull request?
Add the integration tests to the job system, also fix the issues during the tests.
### Why are the changes needed?
Fix: #7937
### Does this PR introduce _any_ user-facing change?
No.
### How was this patch tested?
Add the tests.
--
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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#7937] test(core): Add ITs for job system [gravitino]
Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on PR #8015:
URL: https://github.com/apache/gravitino/pull/8015#issuecomment-3183436930
> Can you please approve this PR? Thanks.
OK, let's merge it first, @mchades. Maybe he is busy with his tasks.
--
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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#7937] test(core): Add ITs for job system [gravitino]
Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #8015:
URL: https://github.com/apache/gravitino/pull/8015#discussion_r2272851435
##########
core/src/main/java/org/apache/gravitino/SupportsRelationOperations.java:
##########
@@ -38,8 +38,6 @@ enum Type {
ROLE_USER_REL,
/** Role and group relationship */
ROLE_GROUP_REL,
- /** Job template and job relationship */
- JOB_TEMPLATE_JOB_REL,
Review Comment:
I see.
--
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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#7937] test(core): Add ITs for job system [gravitino]
Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on PR #8015:
URL: https://github.com/apache/gravitino/pull/8015#issuecomment-3182919981
There is a problem in `JobOperations`, you can fix it by the way
https://github.com/apache/gravitino/blob/0ac8ac2a81c524c1b00e7a0b779ea73cecb9edac/server/src/main/java/org/apache/gravitino/server/web/rest/JobOperations.java#L202-L209
--
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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#7937] test(core): Add ITs for job system [gravitino]
Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on code in PR #8015:
URL: https://github.com/apache/gravitino/pull/8015#discussion_r2272213751
##########
core/src/main/java/org/apache/gravitino/SupportsRelationOperations.java:
##########
@@ -38,8 +38,6 @@ enum Type {
ROLE_USER_REL,
/** Role and group relationship */
ROLE_GROUP_REL,
- /** Job template and job relationship */
- JOB_TEMPLATE_JOB_REL,
Review Comment:
Yes, because of the bug in entity cache, I use a different way to implement the job and job template store, not using this interface.
--
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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#7937] test(core): Add ITs for job system [gravitino]
Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on PR #8015:
URL: https://github.com/apache/gravitino/pull/8015#issuecomment-3183339787
> @yuqi1129 do you have further comments? @mchades please also take a look.
I have no more valueable comments.
--
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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#7937] test(core): Add ITs for job system [gravitino]
Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on PR #8015:
URL: https://github.com/apache/gravitino/pull/8015#issuecomment-3177815298
@yuqi1129 @mchades please help to review this PR, thanks.
--
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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#7937] test(core): Add ITs for job system [gravitino]
Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on PR #8015:
URL: https://github.com/apache/gravitino/pull/8015#issuecomment-3183431022
Can you please approve this PR? Thanks.
--
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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#7937] test(core): Add ITs for job system [gravitino]
Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on PR #8015:
URL: https://github.com/apache/gravitino/pull/8015#issuecomment-3183333143
@yuqi1129 do you have further comments? @mchades please also take a look.
--
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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#7937] test(core): Add ITs for job system [gravitino]
Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #8015:
URL: https://github.com/apache/gravitino/pull/8015#discussion_r2272682768
##########
clients/client-java/src/test/java/org/apache/gravitino/client/integration/test/JobIT.java:
##########
@@ -0,0 +1,356 @@
+/*
+ * 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.gravitino.client.integration.test;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Lists;
+import java.io.File;
+import java.nio.file.Files;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+import org.apache.commons.io.FileUtils;
+import org.apache.gravitino.client.GravitinoMetalake;
+import org.apache.gravitino.exceptions.JobTemplateAlreadyExistsException;
+import org.apache.gravitino.exceptions.NoSuchJobException;
+import org.apache.gravitino.exceptions.NoSuchJobTemplateException;
+import org.apache.gravitino.integration.test.util.BaseIT;
+import org.apache.gravitino.integration.test.util.GravitinoITUtils;
+import org.apache.gravitino.job.JobHandle;
+import org.apache.gravitino.job.JobTemplate;
+import org.apache.gravitino.job.ShellJobTemplate;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.testcontainers.shaded.org.awaitility.Awaitility;
+
+public class JobIT extends BaseIT {
+
+ private static final String METALAKE_NAME = GravitinoITUtils.genRandomName("job_it_metalake");
+
+ private File testStagingDir;
+ private String testEntryScriptPath;
+ private String testLibScriptPath;
+ private ShellJobTemplate.Builder builder;
+ private GravitinoMetalake metalake;
+
+ @BeforeAll
+ @Override
+ public void startIntegrationTest() throws Exception {
+ testStagingDir = Files.createTempDirectory("test_staging_dir").toFile();
+ testEntryScriptPath = generateTestEntryScript();
+ testLibScriptPath = generateTestLibScript();
+
+ builder =
+ ShellJobTemplate.builder()
+ .withComment("Test shell job template")
+ .withExecutable(testEntryScriptPath)
+ .withArguments(Lists.newArrayList("{{arg1}}", "{{arg2}}"))
+ .withEnvironments(ImmutableMap.of("ENV_VAR", "{{env_var}}"))
+ .withScripts(Lists.newArrayList(testLibScriptPath))
+ .withCustomFields(Collections.emptyMap());
+
+ Map<String, String> configs =
+ ImmutableMap.of(
+ "gravitino.job.stagingDir",
+ testStagingDir.getAbsolutePath(),
+ "gravitino.job.statusPullIntervalInMs",
+ "3000");
+ registerCustomConfigs(configs);
+ super.startIntegrationTest();
+ }
+
+ @AfterAll
+ public void tearDown() throws Exception {
+ FileUtils.deleteDirectory(testStagingDir);
+ }
+
+ @BeforeEach
+ public void setUp() {
+ // Create a metalake for testing jobs
+ metalake =
+ client.createMetalake(METALAKE_NAME, "metalake test for job", Collections.emptyMap());
+ }
+
+ @AfterEach
+ public void cleanUp() {
+ // Drop the metalake after each test
+ client.dropMetalake(METALAKE_NAME, true);
+ }
+
+ @Test
+ public void testRegisterAndListJobTemplates() {
+ JobTemplate template1 = builder.withName("test_1").build();
+ JobTemplate template2 = builder.withName("test_2").build();
+
+ Assertions.assertDoesNotThrow(() -> metalake.registerJobTemplate(template1));
+ Assertions.assertDoesNotThrow(() -> metalake.registerJobTemplate(template2));
+
+ List<JobTemplate> registeredTemplates = metalake.listJobTemplates();
+ Assertions.assertEquals(2, registeredTemplates.size());
+ Assertions.assertTrue(registeredTemplates.contains(template1));
+ Assertions.assertTrue(registeredTemplates.contains(template2));
+
+ // Test register duplicated job template
+ Assertions.assertThrows(
+ JobTemplateAlreadyExistsException.class, () -> metalake.registerJobTemplate(template1));
+ }
+
+ @Test
+ public void testRegisterAndGetJobTemplate() {
+ JobTemplate template = builder.withName("test_get").build();
+ Assertions.assertDoesNotThrow(() -> metalake.registerJobTemplate(template));
+
+ JobTemplate retrievedTemplate = metalake.getJobTemplate(template.name());
+ Assertions.assertEquals(template, retrievedTemplate);
+
+ // Test get non-existent job template
+ Assertions.assertThrows(
+ NoSuchJobTemplateException.class, () -> metalake.getJobTemplate("non_existent_template"));
+ }
+
+ @Test
+ public void testRegisterAndDeleteJobTemplate() {
+ JobTemplate template1 = builder.withName("test_1").build();
+ JobTemplate template2 = builder.withName("test_2").build();
+ Assertions.assertDoesNotThrow(() -> metalake.registerJobTemplate(template1));
+ Assertions.assertDoesNotThrow(() -> metalake.registerJobTemplate(template2));
+
+ List<JobTemplate> registeredTemplates = metalake.listJobTemplates();
+ Assertions.assertEquals(2, registeredTemplates.size());
+ Assertions.assertTrue(registeredTemplates.contains(template1));
+ Assertions.assertTrue(registeredTemplates.contains(template2));
+
+ JobTemplate result1 = metalake.getJobTemplate(template1.name());
+ JobTemplate result2 = metalake.getJobTemplate(template2.name());
+ Assertions.assertEquals(template1, result1);
+ Assertions.assertEquals(template2, result2);
+
+ // Delete the first job template
+ Assertions.assertTrue(metalake.deleteJobTemplate(template1.name()));
+ // Verify the first job template is deleted
+ Assertions.assertThrows(
+ NoSuchJobTemplateException.class, () -> metalake.getJobTemplate(template1.name()));
+ // Verify the second job template still exists
+ JobTemplate remainingTemplate = metalake.getJobTemplate(template2.name());
+ Assertions.assertEquals(template2, remainingTemplate);
+
+ // Verify the list of job templates after deletion
+ registeredTemplates = metalake.listJobTemplates();
+ Assertions.assertEquals(1, registeredTemplates.size());
+ Assertions.assertTrue(registeredTemplates.contains(template2));
+
+ // Test deleting a non-existent job template
+ Assertions.assertFalse(metalake.deleteJobTemplate(template1.name()));
+
+ // Delete the second job template
+ Assertions.assertTrue(metalake.deleteJobTemplate(template2.name()));
+
+ // Verify the second job template is deleted
+ Assertions.assertThrows(
+ NoSuchJobTemplateException.class, () -> metalake.getJobTemplate(template2.name()));
+
+ // Verify the list of job templates is empty after deleting both
+ registeredTemplates = metalake.listJobTemplates();
+ Assertions.assertTrue(registeredTemplates.isEmpty());
+ }
+
+ @Test
+ public void testRunAndListJobs() {
+ JobTemplate template = builder.withName("test_run").build();
+ Assertions.assertDoesNotThrow(() -> metalake.registerJobTemplate(template));
+
+ // Submit a job with success status
+ JobHandle jobHandle1 =
+ metalake.runJob(
+ template.name(),
+ ImmutableMap.of("arg1", "value1", "arg2", "success", "env_var", "value2"));
+ Assertions.assertEquals(JobHandle.Status.QUEUED, jobHandle1.jobStatus());
+ Assertions.assertEquals(template.name(), jobHandle1.jobTemplateName());
+
+ JobHandle jobHandle2 =
+ metalake.runJob(
+ template.name(),
+ ImmutableMap.of("arg1", "value3", "arg2", "success", "env_var", "value4"));
+ Assertions.assertEquals(JobHandle.Status.QUEUED, jobHandle2.jobStatus());
+ Assertions.assertEquals(template.name(), jobHandle2.jobTemplateName());
+
+ List<JobHandle> jobs = metalake.listJobs(template.name());
+ Assertions.assertEquals(2, jobs.size());
+ List<String> resultJobIds = jobs.stream().map(JobHandle::jobId).collect(Collectors.toList());
+ Assertions.assertTrue(resultJobIds.contains(jobHandle1.jobId()));
+ Assertions.assertTrue(resultJobIds.contains(jobHandle2.jobId()));
+
+ Awaitility.await()
+ .atMost(3, TimeUnit.MINUTES)
+ .until(
+ () -> {
+ JobHandle updatedJob1 = metalake.getJob(jobHandle1.jobId());
+ return updatedJob1.jobStatus() == JobHandle.Status.SUCCEEDED;
+ });
+
+ Awaitility.await()
+ .atMost(3, TimeUnit.MINUTES)
+ .until(
+ () -> {
+ JobHandle updatedJob2 = metalake.getJob(jobHandle2.jobId());
+ return updatedJob2.jobStatus() == JobHandle.Status.SUCCEEDED;
+ });
+
+ List<JobHandle> updatedJobs = metalake.listJobs(template.name());
+ Assertions.assertEquals(2, updatedJobs.size());
+ Set<JobHandle.Status> jobStatuses =
+ updatedJobs.stream().map(JobHandle::jobStatus).collect(Collectors.toSet());
+ Assertions.assertEquals(1, jobStatuses.size());
+ Assertions.assertTrue(jobStatuses.contains(JobHandle.Status.SUCCEEDED));
+ }
+
+ @Test
+ public void testRunAndGetJob() {
+ JobTemplate template = builder.withName("test_run_get").build();
+ Assertions.assertDoesNotThrow(() -> metalake.registerJobTemplate(template));
+
+ // Submit a job with success status
+ JobHandle jobHandle =
+ metalake.runJob(
+ template.name(),
+ ImmutableMap.of("arg1", "value1", "arg2", "success", "env_var", "value2"));
+ Assertions.assertEquals(JobHandle.Status.QUEUED, jobHandle.jobStatus());
+ Assertions.assertEquals(template.name(), jobHandle.jobTemplateName());
+
+ Awaitility.await()
+ .atMost(3, TimeUnit.MINUTES)
+ .until(
+ () -> {
+ JobHandle updatedJob = metalake.getJob(jobHandle.jobId());
+ return updatedJob.jobStatus() == JobHandle.Status.SUCCEEDED;
+ });
+
+ JobHandle retrievedJob = metalake.getJob(jobHandle.jobId());
+ Assertions.assertEquals(jobHandle.jobId(), retrievedJob.jobId());
+ Assertions.assertEquals(JobHandle.Status.SUCCEEDED, retrievedJob.jobStatus());
+
+ // Test run a failed job
+ JobHandle failedJobHandle =
+ metalake.runJob(
+ template.name(),
+ ImmutableMap.of("arg1", "value1", "arg2", "fail", "env_var", "value2"));
+ Assertions.assertEquals(JobHandle.Status.QUEUED, failedJobHandle.jobStatus());
+
+ Awaitility.await()
+ .atMost(3, TimeUnit.MINUTES)
+ .until(
+ () -> {
+ JobHandle updatedFailedJob = metalake.getJob(failedJobHandle.jobId());
+ return updatedFailedJob.jobStatus() == JobHandle.Status.FAILED;
+ });
+
+ JobHandle retrievedFailedJob = metalake.getJob(failedJobHandle.jobId());
+ Assertions.assertEquals(failedJobHandle.jobId(), retrievedFailedJob.jobId());
+ Assertions.assertEquals(JobHandle.Status.FAILED, retrievedFailedJob.jobStatus());
+
+ // Test get a non-existent job
+ Assertions.assertThrows(NoSuchJobException.class, () -> metalake.getJob("non_existent_job_id"));
+ }
+
+ @Test
+ public void testRunAndCancelJob() {
+ JobTemplate template = builder.withName("test_run_cancel").build();
+ Assertions.assertDoesNotThrow(() -> metalake.registerJobTemplate(template));
+
+ // Submit a job with success status
+ JobHandle jobHandle =
+ metalake.runJob(
+ template.name(),
+ ImmutableMap.of("arg1", "value1", "arg2", "success", "env_var", "value2"));
+ Assertions.assertEquals(JobHandle.Status.QUEUED, jobHandle.jobStatus());
+ Assertions.assertEquals(template.name(), jobHandle.jobTemplateName());
+
+ // Cancel the job
+ metalake.cancelJob(jobHandle.jobId());
+
+ Awaitility.await()
+ .atMost(3, TimeUnit.MINUTES)
+ .until(
+ () -> {
+ JobHandle updatedJob = metalake.getJob(jobHandle.jobId());
+ return updatedJob.jobStatus() == JobHandle.Status.CANCELLED;
+ });
+
+ JobHandle retrievedJob = metalake.getJob(jobHandle.jobId());
+ Assertions.assertEquals(jobHandle.jobId(), retrievedJob.jobId());
+ Assertions.assertEquals(JobHandle.Status.CANCELLED, retrievedJob.jobStatus());
+
+ // Test cancel a non-existent job
+ Assertions.assertThrows(
+ NoSuchJobException.class, () -> metalake.cancelJob("non_existent_job_id"));
+ }
+
+ private String generateTestEntryScript() {
+ String content =
Review Comment:
I see. This module will be built with the target `JDK8` and will use `JDK17` for source compatibility, allowing us to use JDK17 syntax. Anyway, this is not a major issue; leaving it as is or not does not matter too much.
--
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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#7937] test(core): Add ITs for job system [gravitino]
Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #8015:
URL: https://github.com/apache/gravitino/pull/8015#discussion_r2271875272
##########
core/src/main/java/org/apache/gravitino/SupportsRelationOperations.java:
##########
@@ -38,8 +38,6 @@ enum Type {
ROLE_USER_REL,
/** Role and group relationship */
ROLE_GROUP_REL,
- /** Job template and job relationship */
- JOB_TEMPLATE_JOB_REL,
Review Comment:
Is it no longer in use?
##########
core/src/main/java/org/apache/gravitino/job/JobManager.java:
##########
@@ -313,19 +321,25 @@ public List<JobEntity> listJobs(String metalake, Optional<String> jobTemplateNam
NameIdentifier jobTemplateIdent =
NameIdentifierUtil.ofJobTemplate(metalake, jobTemplateName.get());
+ // If jobTemplateName is present, we need to list the jobs associated with the job.
+ // Using a mock namespace from job template identifier to get the jobs associated
+ // with job template.
+ String[] elements =
+ Stream.concat(
Review Comment:
ArrayUtils.add(jobTemplateIdent.namespace().levels(), jobTemplateIdent.name());
##########
clients/client-java/src/test/java/org/apache/gravitino/client/integration/test/JobIT.java:
##########
@@ -0,0 +1,356 @@
+/*
+ * 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.gravitino.client.integration.test;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Lists;
+import java.io.File;
+import java.nio.file.Files;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+import org.apache.commons.io.FileUtils;
+import org.apache.gravitino.client.GravitinoMetalake;
+import org.apache.gravitino.exceptions.JobTemplateAlreadyExistsException;
+import org.apache.gravitino.exceptions.NoSuchJobException;
+import org.apache.gravitino.exceptions.NoSuchJobTemplateException;
+import org.apache.gravitino.integration.test.util.BaseIT;
+import org.apache.gravitino.integration.test.util.GravitinoITUtils;
+import org.apache.gravitino.job.JobHandle;
+import org.apache.gravitino.job.JobTemplate;
+import org.apache.gravitino.job.ShellJobTemplate;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.testcontainers.shaded.org.awaitility.Awaitility;
+
+public class JobIT extends BaseIT {
+
+ private static final String METALAKE_NAME = GravitinoITUtils.genRandomName("job_it_metalake");
+
+ private File testStagingDir;
+ private String testEntryScriptPath;
+ private String testLibScriptPath;
+ private ShellJobTemplate.Builder builder;
+ private GravitinoMetalake metalake;
+
+ @BeforeAll
+ @Override
+ public void startIntegrationTest() throws Exception {
+ testStagingDir = Files.createTempDirectory("test_staging_dir").toFile();
+ testEntryScriptPath = generateTestEntryScript();
+ testLibScriptPath = generateTestLibScript();
+
+ builder =
+ ShellJobTemplate.builder()
+ .withComment("Test shell job template")
+ .withExecutable(testEntryScriptPath)
+ .withArguments(Lists.newArrayList("{{arg1}}", "{{arg2}}"))
+ .withEnvironments(ImmutableMap.of("ENV_VAR", "{{env_var}}"))
+ .withScripts(Lists.newArrayList(testLibScriptPath))
+ .withCustomFields(Collections.emptyMap());
+
+ Map<String, String> configs =
+ ImmutableMap.of(
+ "gravitino.job.stagingDir",
+ testStagingDir.getAbsolutePath(),
+ "gravitino.job.statusPullIntervalInMs",
+ "3000");
+ registerCustomConfigs(configs);
+ super.startIntegrationTest();
+ }
+
+ @AfterAll
+ public void tearDown() throws Exception {
+ FileUtils.deleteDirectory(testStagingDir);
+ }
+
+ @BeforeEach
+ public void setUp() {
+ // Create a metalake for testing jobs
+ metalake =
+ client.createMetalake(METALAKE_NAME, "metalake test for job", Collections.emptyMap());
+ }
+
+ @AfterEach
+ public void cleanUp() {
+ // Drop the metalake after each test
+ client.dropMetalake(METALAKE_NAME, true);
+ }
+
+ @Test
+ public void testRegisterAndListJobTemplates() {
+ JobTemplate template1 = builder.withName("test_1").build();
+ JobTemplate template2 = builder.withName("test_2").build();
+
+ Assertions.assertDoesNotThrow(() -> metalake.registerJobTemplate(template1));
+ Assertions.assertDoesNotThrow(() -> metalake.registerJobTemplate(template2));
+
+ List<JobTemplate> registeredTemplates = metalake.listJobTemplates();
+ Assertions.assertEquals(2, registeredTemplates.size());
+ Assertions.assertTrue(registeredTemplates.contains(template1));
+ Assertions.assertTrue(registeredTemplates.contains(template2));
+
+ // Test register duplicated job template
+ Assertions.assertThrows(
+ JobTemplateAlreadyExistsException.class, () -> metalake.registerJobTemplate(template1));
+ }
+
+ @Test
+ public void testRegisterAndGetJobTemplate() {
+ JobTemplate template = builder.withName("test_get").build();
+ Assertions.assertDoesNotThrow(() -> metalake.registerJobTemplate(template));
+
+ JobTemplate retrievedTemplate = metalake.getJobTemplate(template.name());
+ Assertions.assertEquals(template, retrievedTemplate);
+
+ // Test get non-existent job template
+ Assertions.assertThrows(
+ NoSuchJobTemplateException.class, () -> metalake.getJobTemplate("non_existent_template"));
+ }
+
+ @Test
+ public void testRegisterAndDeleteJobTemplate() {
+ JobTemplate template1 = builder.withName("test_1").build();
+ JobTemplate template2 = builder.withName("test_2").build();
+ Assertions.assertDoesNotThrow(() -> metalake.registerJobTemplate(template1));
+ Assertions.assertDoesNotThrow(() -> metalake.registerJobTemplate(template2));
+
+ List<JobTemplate> registeredTemplates = metalake.listJobTemplates();
+ Assertions.assertEquals(2, registeredTemplates.size());
+ Assertions.assertTrue(registeredTemplates.contains(template1));
+ Assertions.assertTrue(registeredTemplates.contains(template2));
+
+ JobTemplate result1 = metalake.getJobTemplate(template1.name());
+ JobTemplate result2 = metalake.getJobTemplate(template2.name());
+ Assertions.assertEquals(template1, result1);
+ Assertions.assertEquals(template2, result2);
+
+ // Delete the first job template
+ Assertions.assertTrue(metalake.deleteJobTemplate(template1.name()));
+ // Verify the first job template is deleted
+ Assertions.assertThrows(
+ NoSuchJobTemplateException.class, () -> metalake.getJobTemplate(template1.name()));
+ // Verify the second job template still exists
+ JobTemplate remainingTemplate = metalake.getJobTemplate(template2.name());
+ Assertions.assertEquals(template2, remainingTemplate);
+
+ // Verify the list of job templates after deletion
+ registeredTemplates = metalake.listJobTemplates();
+ Assertions.assertEquals(1, registeredTemplates.size());
+ Assertions.assertTrue(registeredTemplates.contains(template2));
+
+ // Test deleting a non-existent job template
+ Assertions.assertFalse(metalake.deleteJobTemplate(template1.name()));
+
+ // Delete the second job template
+ Assertions.assertTrue(metalake.deleteJobTemplate(template2.name()));
+
+ // Verify the second job template is deleted
+ Assertions.assertThrows(
+ NoSuchJobTemplateException.class, () -> metalake.getJobTemplate(template2.name()));
+
+ // Verify the list of job templates is empty after deleting both
+ registeredTemplates = metalake.listJobTemplates();
+ Assertions.assertTrue(registeredTemplates.isEmpty());
+ }
+
+ @Test
+ public void testRunAndListJobs() {
+ JobTemplate template = builder.withName("test_run").build();
+ Assertions.assertDoesNotThrow(() -> metalake.registerJobTemplate(template));
+
+ // Submit a job with success status
+ JobHandle jobHandle1 =
+ metalake.runJob(
+ template.name(),
+ ImmutableMap.of("arg1", "value1", "arg2", "success", "env_var", "value2"));
+ Assertions.assertEquals(JobHandle.Status.QUEUED, jobHandle1.jobStatus());
+ Assertions.assertEquals(template.name(), jobHandle1.jobTemplateName());
+
+ JobHandle jobHandle2 =
+ metalake.runJob(
+ template.name(),
+ ImmutableMap.of("arg1", "value3", "arg2", "success", "env_var", "value4"));
+ Assertions.assertEquals(JobHandle.Status.QUEUED, jobHandle2.jobStatus());
+ Assertions.assertEquals(template.name(), jobHandle2.jobTemplateName());
+
+ List<JobHandle> jobs = metalake.listJobs(template.name());
+ Assertions.assertEquals(2, jobs.size());
+ List<String> resultJobIds = jobs.stream().map(JobHandle::jobId).collect(Collectors.toList());
+ Assertions.assertTrue(resultJobIds.contains(jobHandle1.jobId()));
+ Assertions.assertTrue(resultJobIds.contains(jobHandle2.jobId()));
+
+ Awaitility.await()
+ .atMost(3, TimeUnit.MINUTES)
+ .until(
+ () -> {
+ JobHandle updatedJob1 = metalake.getJob(jobHandle1.jobId());
+ return updatedJob1.jobStatus() == JobHandle.Status.SUCCEEDED;
+ });
+
+ Awaitility.await()
+ .atMost(3, TimeUnit.MINUTES)
+ .until(
+ () -> {
+ JobHandle updatedJob2 = metalake.getJob(jobHandle2.jobId());
+ return updatedJob2.jobStatus() == JobHandle.Status.SUCCEEDED;
+ });
+
+ List<JobHandle> updatedJobs = metalake.listJobs(template.name());
+ Assertions.assertEquals(2, updatedJobs.size());
+ Set<JobHandle.Status> jobStatuses =
+ updatedJobs.stream().map(JobHandle::jobStatus).collect(Collectors.toSet());
+ Assertions.assertEquals(1, jobStatuses.size());
+ Assertions.assertTrue(jobStatuses.contains(JobHandle.Status.SUCCEEDED));
+ }
+
+ @Test
+ public void testRunAndGetJob() {
+ JobTemplate template = builder.withName("test_run_get").build();
+ Assertions.assertDoesNotThrow(() -> metalake.registerJobTemplate(template));
+
+ // Submit a job with success status
+ JobHandle jobHandle =
+ metalake.runJob(
+ template.name(),
+ ImmutableMap.of("arg1", "value1", "arg2", "success", "env_var", "value2"));
+ Assertions.assertEquals(JobHandle.Status.QUEUED, jobHandle.jobStatus());
+ Assertions.assertEquals(template.name(), jobHandle.jobTemplateName());
+
+ Awaitility.await()
+ .atMost(3, TimeUnit.MINUTES)
+ .until(
+ () -> {
+ JobHandle updatedJob = metalake.getJob(jobHandle.jobId());
+ return updatedJob.jobStatus() == JobHandle.Status.SUCCEEDED;
+ });
+
+ JobHandle retrievedJob = metalake.getJob(jobHandle.jobId());
+ Assertions.assertEquals(jobHandle.jobId(), retrievedJob.jobId());
+ Assertions.assertEquals(JobHandle.Status.SUCCEEDED, retrievedJob.jobStatus());
+
+ // Test run a failed job
+ JobHandle failedJobHandle =
+ metalake.runJob(
+ template.name(),
+ ImmutableMap.of("arg1", "value1", "arg2", "fail", "env_var", "value2"));
+ Assertions.assertEquals(JobHandle.Status.QUEUED, failedJobHandle.jobStatus());
+
+ Awaitility.await()
+ .atMost(3, TimeUnit.MINUTES)
+ .until(
+ () -> {
+ JobHandle updatedFailedJob = metalake.getJob(failedJobHandle.jobId());
+ return updatedFailedJob.jobStatus() == JobHandle.Status.FAILED;
+ });
+
+ JobHandle retrievedFailedJob = metalake.getJob(failedJobHandle.jobId());
+ Assertions.assertEquals(failedJobHandle.jobId(), retrievedFailedJob.jobId());
+ Assertions.assertEquals(JobHandle.Status.FAILED, retrievedFailedJob.jobStatus());
+
+ // Test get a non-existent job
+ Assertions.assertThrows(NoSuchJobException.class, () -> metalake.getJob("non_existent_job_id"));
+ }
+
+ @Test
+ public void testRunAndCancelJob() {
+ JobTemplate template = builder.withName("test_run_cancel").build();
+ Assertions.assertDoesNotThrow(() -> metalake.registerJobTemplate(template));
+
+ // Submit a job with success status
+ JobHandle jobHandle =
+ metalake.runJob(
+ template.name(),
+ ImmutableMap.of("arg1", "value1", "arg2", "success", "env_var", "value2"));
+ Assertions.assertEquals(JobHandle.Status.QUEUED, jobHandle.jobStatus());
+ Assertions.assertEquals(template.name(), jobHandle.jobTemplateName());
+
+ // Cancel the job
+ metalake.cancelJob(jobHandle.jobId());
+
+ Awaitility.await()
+ .atMost(3, TimeUnit.MINUTES)
+ .until(
+ () -> {
+ JobHandle updatedJob = metalake.getJob(jobHandle.jobId());
+ return updatedJob.jobStatus() == JobHandle.Status.CANCELLED;
+ });
+
+ JobHandle retrievedJob = metalake.getJob(jobHandle.jobId());
+ Assertions.assertEquals(jobHandle.jobId(), retrievedJob.jobId());
+ Assertions.assertEquals(JobHandle.Status.CANCELLED, retrievedJob.jobStatus());
+
+ // Test cancel a non-existent job
+ Assertions.assertThrows(
+ NoSuchJobException.class, () -> metalake.cancelJob("non_existent_job_id"));
+ }
+
+ private String generateTestEntryScript() {
+ String content =
Review Comment:
Since only JDK17 is allowed to compile the project, I believe we can use the following JDK17 feature
```
"""
Content here
"""
```
to improve the code below.
--
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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#7937] test(core): Add ITs for job system [gravitino]
Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on code in PR #8015:
URL: https://github.com/apache/gravitino/pull/8015#discussion_r2272665529
##########
clients/client-java/src/test/java/org/apache/gravitino/client/integration/test/JobIT.java:
##########
@@ -0,0 +1,356 @@
+/*
+ * 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.gravitino.client.integration.test;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Lists;
+import java.io.File;
+import java.nio.file.Files;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+import org.apache.commons.io.FileUtils;
+import org.apache.gravitino.client.GravitinoMetalake;
+import org.apache.gravitino.exceptions.JobTemplateAlreadyExistsException;
+import org.apache.gravitino.exceptions.NoSuchJobException;
+import org.apache.gravitino.exceptions.NoSuchJobTemplateException;
+import org.apache.gravitino.integration.test.util.BaseIT;
+import org.apache.gravitino.integration.test.util.GravitinoITUtils;
+import org.apache.gravitino.job.JobHandle;
+import org.apache.gravitino.job.JobTemplate;
+import org.apache.gravitino.job.ShellJobTemplate;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.testcontainers.shaded.org.awaitility.Awaitility;
+
+public class JobIT extends BaseIT {
+
+ private static final String METALAKE_NAME = GravitinoITUtils.genRandomName("job_it_metalake");
+
+ private File testStagingDir;
+ private String testEntryScriptPath;
+ private String testLibScriptPath;
+ private ShellJobTemplate.Builder builder;
+ private GravitinoMetalake metalake;
+
+ @BeforeAll
+ @Override
+ public void startIntegrationTest() throws Exception {
+ testStagingDir = Files.createTempDirectory("test_staging_dir").toFile();
+ testEntryScriptPath = generateTestEntryScript();
+ testLibScriptPath = generateTestLibScript();
+
+ builder =
+ ShellJobTemplate.builder()
+ .withComment("Test shell job template")
+ .withExecutable(testEntryScriptPath)
+ .withArguments(Lists.newArrayList("{{arg1}}", "{{arg2}}"))
+ .withEnvironments(ImmutableMap.of("ENV_VAR", "{{env_var}}"))
+ .withScripts(Lists.newArrayList(testLibScriptPath))
+ .withCustomFields(Collections.emptyMap());
+
+ Map<String, String> configs =
+ ImmutableMap.of(
+ "gravitino.job.stagingDir",
+ testStagingDir.getAbsolutePath(),
+ "gravitino.job.statusPullIntervalInMs",
+ "3000");
+ registerCustomConfigs(configs);
+ super.startIntegrationTest();
+ }
+
+ @AfterAll
+ public void tearDown() throws Exception {
+ FileUtils.deleteDirectory(testStagingDir);
+ }
+
+ @BeforeEach
+ public void setUp() {
+ // Create a metalake for testing jobs
+ metalake =
+ client.createMetalake(METALAKE_NAME, "metalake test for job", Collections.emptyMap());
+ }
+
+ @AfterEach
+ public void cleanUp() {
+ // Drop the metalake after each test
+ client.dropMetalake(METALAKE_NAME, true);
+ }
+
+ @Test
+ public void testRegisterAndListJobTemplates() {
+ JobTemplate template1 = builder.withName("test_1").build();
+ JobTemplate template2 = builder.withName("test_2").build();
+
+ Assertions.assertDoesNotThrow(() -> metalake.registerJobTemplate(template1));
+ Assertions.assertDoesNotThrow(() -> metalake.registerJobTemplate(template2));
+
+ List<JobTemplate> registeredTemplates = metalake.listJobTemplates();
+ Assertions.assertEquals(2, registeredTemplates.size());
+ Assertions.assertTrue(registeredTemplates.contains(template1));
+ Assertions.assertTrue(registeredTemplates.contains(template2));
+
+ // Test register duplicated job template
+ Assertions.assertThrows(
+ JobTemplateAlreadyExistsException.class, () -> metalake.registerJobTemplate(template1));
+ }
+
+ @Test
+ public void testRegisterAndGetJobTemplate() {
+ JobTemplate template = builder.withName("test_get").build();
+ Assertions.assertDoesNotThrow(() -> metalake.registerJobTemplate(template));
+
+ JobTemplate retrievedTemplate = metalake.getJobTemplate(template.name());
+ Assertions.assertEquals(template, retrievedTemplate);
+
+ // Test get non-existent job template
+ Assertions.assertThrows(
+ NoSuchJobTemplateException.class, () -> metalake.getJobTemplate("non_existent_template"));
+ }
+
+ @Test
+ public void testRegisterAndDeleteJobTemplate() {
+ JobTemplate template1 = builder.withName("test_1").build();
+ JobTemplate template2 = builder.withName("test_2").build();
+ Assertions.assertDoesNotThrow(() -> metalake.registerJobTemplate(template1));
+ Assertions.assertDoesNotThrow(() -> metalake.registerJobTemplate(template2));
+
+ List<JobTemplate> registeredTemplates = metalake.listJobTemplates();
+ Assertions.assertEquals(2, registeredTemplates.size());
+ Assertions.assertTrue(registeredTemplates.contains(template1));
+ Assertions.assertTrue(registeredTemplates.contains(template2));
+
+ JobTemplate result1 = metalake.getJobTemplate(template1.name());
+ JobTemplate result2 = metalake.getJobTemplate(template2.name());
+ Assertions.assertEquals(template1, result1);
+ Assertions.assertEquals(template2, result2);
+
+ // Delete the first job template
+ Assertions.assertTrue(metalake.deleteJobTemplate(template1.name()));
+ // Verify the first job template is deleted
+ Assertions.assertThrows(
+ NoSuchJobTemplateException.class, () -> metalake.getJobTemplate(template1.name()));
+ // Verify the second job template still exists
+ JobTemplate remainingTemplate = metalake.getJobTemplate(template2.name());
+ Assertions.assertEquals(template2, remainingTemplate);
+
+ // Verify the list of job templates after deletion
+ registeredTemplates = metalake.listJobTemplates();
+ Assertions.assertEquals(1, registeredTemplates.size());
+ Assertions.assertTrue(registeredTemplates.contains(template2));
+
+ // Test deleting a non-existent job template
+ Assertions.assertFalse(metalake.deleteJobTemplate(template1.name()));
+
+ // Delete the second job template
+ Assertions.assertTrue(metalake.deleteJobTemplate(template2.name()));
+
+ // Verify the second job template is deleted
+ Assertions.assertThrows(
+ NoSuchJobTemplateException.class, () -> metalake.getJobTemplate(template2.name()));
+
+ // Verify the list of job templates is empty after deleting both
+ registeredTemplates = metalake.listJobTemplates();
+ Assertions.assertTrue(registeredTemplates.isEmpty());
+ }
+
+ @Test
+ public void testRunAndListJobs() {
+ JobTemplate template = builder.withName("test_run").build();
+ Assertions.assertDoesNotThrow(() -> metalake.registerJobTemplate(template));
+
+ // Submit a job with success status
+ JobHandle jobHandle1 =
+ metalake.runJob(
+ template.name(),
+ ImmutableMap.of("arg1", "value1", "arg2", "success", "env_var", "value2"));
+ Assertions.assertEquals(JobHandle.Status.QUEUED, jobHandle1.jobStatus());
+ Assertions.assertEquals(template.name(), jobHandle1.jobTemplateName());
+
+ JobHandle jobHandle2 =
+ metalake.runJob(
+ template.name(),
+ ImmutableMap.of("arg1", "value3", "arg2", "success", "env_var", "value4"));
+ Assertions.assertEquals(JobHandle.Status.QUEUED, jobHandle2.jobStatus());
+ Assertions.assertEquals(template.name(), jobHandle2.jobTemplateName());
+
+ List<JobHandle> jobs = metalake.listJobs(template.name());
+ Assertions.assertEquals(2, jobs.size());
+ List<String> resultJobIds = jobs.stream().map(JobHandle::jobId).collect(Collectors.toList());
+ Assertions.assertTrue(resultJobIds.contains(jobHandle1.jobId()));
+ Assertions.assertTrue(resultJobIds.contains(jobHandle2.jobId()));
+
+ Awaitility.await()
+ .atMost(3, TimeUnit.MINUTES)
+ .until(
+ () -> {
+ JobHandle updatedJob1 = metalake.getJob(jobHandle1.jobId());
+ return updatedJob1.jobStatus() == JobHandle.Status.SUCCEEDED;
+ });
+
+ Awaitility.await()
+ .atMost(3, TimeUnit.MINUTES)
+ .until(
+ () -> {
+ JobHandle updatedJob2 = metalake.getJob(jobHandle2.jobId());
+ return updatedJob2.jobStatus() == JobHandle.Status.SUCCEEDED;
+ });
+
+ List<JobHandle> updatedJobs = metalake.listJobs(template.name());
+ Assertions.assertEquals(2, updatedJobs.size());
+ Set<JobHandle.Status> jobStatuses =
+ updatedJobs.stream().map(JobHandle::jobStatus).collect(Collectors.toSet());
+ Assertions.assertEquals(1, jobStatuses.size());
+ Assertions.assertTrue(jobStatuses.contains(JobHandle.Status.SUCCEEDED));
+ }
+
+ @Test
+ public void testRunAndGetJob() {
+ JobTemplate template = builder.withName("test_run_get").build();
+ Assertions.assertDoesNotThrow(() -> metalake.registerJobTemplate(template));
+
+ // Submit a job with success status
+ JobHandle jobHandle =
+ metalake.runJob(
+ template.name(),
+ ImmutableMap.of("arg1", "value1", "arg2", "success", "env_var", "value2"));
+ Assertions.assertEquals(JobHandle.Status.QUEUED, jobHandle.jobStatus());
+ Assertions.assertEquals(template.name(), jobHandle.jobTemplateName());
+
+ Awaitility.await()
+ .atMost(3, TimeUnit.MINUTES)
+ .until(
+ () -> {
+ JobHandle updatedJob = metalake.getJob(jobHandle.jobId());
+ return updatedJob.jobStatus() == JobHandle.Status.SUCCEEDED;
+ });
+
+ JobHandle retrievedJob = metalake.getJob(jobHandle.jobId());
+ Assertions.assertEquals(jobHandle.jobId(), retrievedJob.jobId());
+ Assertions.assertEquals(JobHandle.Status.SUCCEEDED, retrievedJob.jobStatus());
+
+ // Test run a failed job
+ JobHandle failedJobHandle =
+ metalake.runJob(
+ template.name(),
+ ImmutableMap.of("arg1", "value1", "arg2", "fail", "env_var", "value2"));
+ Assertions.assertEquals(JobHandle.Status.QUEUED, failedJobHandle.jobStatus());
+
+ Awaitility.await()
+ .atMost(3, TimeUnit.MINUTES)
+ .until(
+ () -> {
+ JobHandle updatedFailedJob = metalake.getJob(failedJobHandle.jobId());
+ return updatedFailedJob.jobStatus() == JobHandle.Status.FAILED;
+ });
+
+ JobHandle retrievedFailedJob = metalake.getJob(failedJobHandle.jobId());
+ Assertions.assertEquals(failedJobHandle.jobId(), retrievedFailedJob.jobId());
+ Assertions.assertEquals(JobHandle.Status.FAILED, retrievedFailedJob.jobStatus());
+
+ // Test get a non-existent job
+ Assertions.assertThrows(NoSuchJobException.class, () -> metalake.getJob("non_existent_job_id"));
+ }
+
+ @Test
+ public void testRunAndCancelJob() {
+ JobTemplate template = builder.withName("test_run_cancel").build();
+ Assertions.assertDoesNotThrow(() -> metalake.registerJobTemplate(template));
+
+ // Submit a job with success status
+ JobHandle jobHandle =
+ metalake.runJob(
+ template.name(),
+ ImmutableMap.of("arg1", "value1", "arg2", "success", "env_var", "value2"));
+ Assertions.assertEquals(JobHandle.Status.QUEUED, jobHandle.jobStatus());
+ Assertions.assertEquals(template.name(), jobHandle.jobTemplateName());
+
+ // Cancel the job
+ metalake.cancelJob(jobHandle.jobId());
+
+ Awaitility.await()
+ .atMost(3, TimeUnit.MINUTES)
+ .until(
+ () -> {
+ JobHandle updatedJob = metalake.getJob(jobHandle.jobId());
+ return updatedJob.jobStatus() == JobHandle.Status.CANCELLED;
+ });
+
+ JobHandle retrievedJob = metalake.getJob(jobHandle.jobId());
+ Assertions.assertEquals(jobHandle.jobId(), retrievedJob.jobId());
+ Assertions.assertEquals(JobHandle.Status.CANCELLED, retrievedJob.jobStatus());
+
+ // Test cancel a non-existent job
+ Assertions.assertThrows(
+ NoSuchJobException.class, () -> metalake.cancelJob("non_existent_job_id"));
+ }
+
+ private String generateTestEntryScript() {
+ String content =
Review Comment:
The client module needs to be compatible with jdk8, I think it is fine leave as it is.
--
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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#7937] test(core): Add ITs for job system [gravitino]
Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 merged PR #8015:
URL: https://github.com/apache/gravitino/pull/8015
--
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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org