Skip to content

Commit 8f523a6

Browse files
committed
ci: enable workflows java tests
Signed-off-by: Grant Timmerman <timmerman+devrel@google.com>
1 parent b3262b5 commit 8f523a6

File tree

1 file changed

+36
-39
lines changed

1 file changed

+36
-39
lines changed

workflows/cloud-client/src/test/java/com/example/workflows/WorkflowsQuickstartTest.java

+36-39
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
import org.junit.Test;
99

1010
import com.google.cloud.workflows.v1.WorkflowName;
11+
12+
import java.io.IOException;
13+
1114
import static com.example.workflows.WorkflowsQuickstart.workflowsQuickstart;
1215
import static org.junit.Assert.*;
1316

@@ -31,55 +34,49 @@ public static void beforeClass() {
3134
}
3235

3336
@Test
34-
public void testQuickstart() {
35-
System.out.println("testing!!");
36-
System.out.println("testing!!");
37-
System.out.println("testing!!");
38-
System.out.println("testing!!");
37+
public void testQuickstart() throws IOException, InterruptedException {
3938
System.out.println("testing!!");
39+
4040
// Deploy the workflow
4141
deployWorkflow(projectId, LOCATION_ID, WORKFLOW_ID);
4242

4343
// Run the workflow we deployed
44-
// String res = workflowsQuickstart(projectId, LOCATION_ID, WORKFLOW_ID);
45-
//
46-
// // A very basic assertion that we have some result.
47-
// assertNotNull("Result should not be null", res);
48-
// assertNotEquals("Result should not be empty", res, "");
44+
String res = workflowsQuickstart(projectId, LOCATION_ID, WORKFLOW_ID);
45+
46+
// A very basic assertion that we have some result.
47+
assertNotNull("Result should not be null", res);
48+
assertNotEquals("Result should not be empty", res, "");
4949
}
5050

51-
private boolean deployWorkflow(String projectId, String location, String workflowId) {
51+
private boolean deployWorkflow(String projectId, String location, String workflowId) throws IOException, InterruptedException {
5252
// Create a new workflow if it doesn't exist
5353
if (!workflowExists(projectId, location, workflowId)) {
5454
System.out.println("START DEPLOY");
55-
try (WorkflowsClient workflowsClient = WorkflowsClient.create()) {
56-
// Deploy workflow
57-
Workflow workflow = Workflow.newBuilder()
58-
.setName(workflowId)
59-
.setSourceContents(WORKFLOW_SOURCE)
60-
.build();
61-
workflowsClient.createWorkflowAsync(location, workflow, workflowId);
62-
63-
// Wait until workflow is active
64-
Workflow deployedWorkflow = null;
65-
66-
System.out.println("DEPLOY START");
67-
// Wait for the deployment to finish
68-
do {
69-
System.out.println("SLEEP");
70-
deployedWorkflow = workflowsClient.getWorkflow(WorkflowName.newBuilder()
71-
.setProject(projectId)
72-
.setLocation(location)
73-
.setWorkflow(workflowId)
74-
.build());
75-
Thread.sleep(2_000);
76-
} while (deployedWorkflow == null || deployedWorkflow.getState().equals(Workflow.State.ACTIVE));
77-
78-
// Return true if the workflow is now active
79-
return deployedWorkflow.getState() != Workflow.State.ACTIVE;
80-
} catch (Exception e) {
81-
System.out.printf("Error deploying workflow: %s\n", e);
82-
}
55+
WorkflowsClient workflowsClient = WorkflowsClient.create();
56+
// Deploy workflow
57+
Workflow workflow = Workflow.newBuilder()
58+
.setName(workflowId)
59+
.setSourceContents(WORKFLOW_SOURCE)
60+
.build();
61+
workflowsClient.createWorkflowAsync(location, workflow, workflowId);
62+
63+
// Wait until workflow is active
64+
Workflow deployedWorkflow = null;
65+
66+
System.out.println("DEPLOY START");
67+
// Wait for the deployment to finish
68+
do {
69+
System.out.println("SLEEP");
70+
deployedWorkflow = workflowsClient.getWorkflow(WorkflowName.newBuilder()
71+
.setProject(projectId)
72+
.setLocation(location)
73+
.setWorkflow(workflowId)
74+
.build());
75+
Thread.sleep(2_000);
76+
} while (deployedWorkflow == null || deployedWorkflow.getState().equals(Workflow.State.ACTIVE));
77+
78+
// Return true if the workflow is now active
79+
return deployedWorkflow.getState() != Workflow.State.ACTIVE;
8380
}
8481
return false;
8582
}

0 commit comments

Comments
 (0)