Skip to content

Commit

Permalink
its: test for task with client1 (#825)
Browse files Browse the repository at this point in the history
  • Loading branch information
brig authored Nov 6, 2023
1 parent 8d61544 commit f40fb6b
Show file tree
Hide file tree
Showing 10 changed files with 248 additions and 0 deletions.
1 change: 1 addition & 0 deletions it/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<module>tasks/dependency-manager-test</module>
<module>tasks/serialization-test</module>
<module>tasks/suspend-test</module>
<module>tasks/client1-test</module>

<module>common</module>
<module>server</module>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
project.version = ${project.version}
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,29 @@
* =====
*/

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public final class ITConstants {

public static final String PROJECT_VERSION;
public static final long DEFAULT_TEST_TIMEOUT = 120000;

static {
PROJECT_VERSION = getProperties("version.properties").getProperty("project.version");
}

private static Properties getProperties(String path) {
try (InputStream in = ClassLoader.getSystemResourceAsStream(path)) {
Properties props = new Properties();
props.load(in);
return props;
} catch (IOException e) {
throw new RuntimeException(e);
}
}

private ITConstants() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@
import ca.ibodrov.concord.testcontainers.Payload;
import ca.ibodrov.concord.testcontainers.ProcessListQuery;
import ca.ibodrov.concord.testcontainers.junit5.ConcordRule;
import com.google.common.base.Charsets;
import com.google.common.io.Resources;
import com.walmartlabs.concord.client.FormListEntry;
import com.walmartlabs.concord.client.FormSubmitResponse;
import com.walmartlabs.concord.client.ProcessCheckpointEntry;
import com.walmartlabs.concord.client.ProcessEntry;
import com.walmartlabs.concord.client.ProcessEntry.StatusEnum;
import com.walmartlabs.concord.it.common.JGitUtils;
Expand All @@ -35,8 +38,10 @@
import org.junit.jupiter.api.Timeout;
import org.junit.jupiter.api.extension.RegisterExtension;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Collections;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -517,6 +522,22 @@ public void testEmptyExclusiveGroup() throws Exception {
proc.assertLog(".*Invalid exclusive mode.*");
}

@Test
public void testTaskWithClient1() throws Exception {
String concordYml = resourceToString(ProcessIT.class.getResource("client1Task/concord.yml"))
.replaceAll("PROJECT_VERSION", ITConstants.PROJECT_VERSION);

Payload payload = new Payload().concordYml(concordYml);

ConcordProcess proc = concord.processes().start(payload);
proc.expectStatus(StatusEnum.FINISHED);

// ---

proc.assertLog(".*process entry: RUNNING.*");
proc.assertLog(".*Works!.*");
}

@SuppressWarnings("unchecked")
private static void assertProcessErrorMessage(ProcessEntry p, String expected) {
assertNotNull(p);
Expand All @@ -536,4 +557,8 @@ private static void assertProcessErrorMessage(ProcessEntry p, String expected) {
private static URI resource(String name) throws URISyntaxException {
return ProcessIT.class.getResource(name).toURI();
}

private static String resourceToString(URL resource) throws IOException {
return Resources.toString(resource, Charsets.UTF_8);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
configuration:
dependencies:
- "mvn://com.walmartlabs.concord.it.tasks:client1-test:PROJECT_VERSION"

flows:
default:
- task: client1Test
- log: "Works!"
Original file line number Diff line number Diff line change
Expand Up @@ -496,4 +496,20 @@ public void testForkVariablesAfterForm() throws Exception {
fork.assertLog(".*parentInstanceId: " + proc.instanceId() + ".*");
fork.assertLog(".*txId: " + fork.instanceId() + ".*");
}

@Test
public void testTaskWithClient1() throws Exception {
String concordYml = resourceToString(ProcessIT.class.getResource("client1Task/concord.yml"))
.replaceAll("PROJECT_VERSION", ITConstants.PROJECT_VERSION);

Payload payload = new Payload().concordYml(concordYml);

ConcordProcess proc = concord.processes().start(payload);
expectStatus(proc, ProcessEntry.StatusEnum.FINISHED);

// ---

proc.assertLog(".*process entry: RUNNING.*");
proc.assertLog(".*Works!.*");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
configuration:
runtime: concord-v2
dependencies:
- "mvn://com.walmartlabs.concord.it.tasks:client1-test:PROJECT_VERSION"

flows:
default:
- task: client1Test
- log: "Works!"
52 changes: 52 additions & 0 deletions it/tasks/client1-test/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.walmartlabs.concord.it</groupId>
<artifactId>parent</artifactId>
<version>2.1.1-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

<groupId>com.walmartlabs.concord.it.tasks</groupId>
<artifactId>client1-test</artifactId>
<packaging>jar</packaging>

<dependencies>
<dependency>
<groupId>com.walmartlabs.concord</groupId>
<artifactId>concord-sdk</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.walmartlabs.concord.runtime.v2</groupId>
<artifactId>concord-runtime-sdk-v2</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.walmartlabs.concord</groupId>
<artifactId>concord-client</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.eclipse.sisu</groupId>
<artifactId>sisu-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.walmartlabs.concord.it.tasks.suspendtest;

/*-
* *****
* Concord
* -----
* Copyright (C) 2017 - 2023 Walmart Inc.
* -----
* Licensed 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.
* =====
*/

import com.walmartlabs.concord.ApiClient;
import com.walmartlabs.concord.client.ApiClientConfiguration;
import com.walmartlabs.concord.client.ApiClientFactory;
import com.walmartlabs.concord.client.ProcessApi;
import com.walmartlabs.concord.client.ProcessEntry;
import com.walmartlabs.concord.sdk.Context;
import com.walmartlabs.concord.sdk.ContextUtils;
import com.walmartlabs.concord.sdk.Task;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.inject.Inject;
import javax.inject.Named;

@Named("client1Test")
public class Client1TestTask implements Task {

private static final Logger log = LoggerFactory.getLogger(Client1TestTask.class);

private final ApiClientFactory factory;

@Inject
public Client1TestTask(ApiClientFactory factory) {
this.factory = factory;
}

@Override
public void execute(Context ctx) throws Exception {
ProcessApi api = new ProcessApi(factory.create(ApiClientConfiguration.builder().context(ctx).build()));
ProcessEntry p = api.get(ContextUtils.getTxId(ctx));
log.info("process entry: {}", p.getStatus());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.walmartlabs.concord.it.tasks.suspendtest;

/*-
* *****
* Concord
* -----
* Copyright (C) 2017 - 2023 Walmart Inc.
* -----
* Licensed 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.
* =====
*/

import com.walmartlabs.concord.ApiClient;
import com.walmartlabs.concord.client.ApiClientFactory;
import com.walmartlabs.concord.client.ProcessApi;
import com.walmartlabs.concord.client.ProcessEntry;
import com.walmartlabs.concord.runtime.v2.sdk.Context;
import com.walmartlabs.concord.runtime.v2.sdk.Task;
import com.walmartlabs.concord.runtime.v2.sdk.TaskResult;
import com.walmartlabs.concord.runtime.v2.sdk.Variables;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.inject.Inject;
import javax.inject.Named;

@Named("client1Test")
public class Client1TestTaskV2 implements Task {

private static final Logger log = LoggerFactory.getLogger(Client1TestTaskV2.class);

private final Context ctx;
private final ApiClient apiClient;
private final ApiClientFactory factory;

@Inject
public Client1TestTaskV2(Context ctx, ApiClient apiClient, ApiClientFactory factory) {
this.ctx = ctx;
this.apiClient = apiClient;
this.factory = factory;
}

@Override
public TaskResult execute(Variables input) throws Exception {
ProcessApi api = new ProcessApi(apiClient);

ProcessEntry p = api.get(ctx.processInstanceId());
log.info("process entry: {}", p.getStatus());

return TaskResult.success();
}
}

0 comments on commit f40fb6b

Please sign in to comment.