use of io.cdap.cdap.internal.app.runtime.workflow.WorkflowStateWriter in project cdap by caskdata.
the class MetadataSubscriberServiceTest method testWorkflow.
@Test
public void testWorkflow() throws InterruptedException, ExecutionException, TimeoutException {
ProgramRunId workflowRunId = workflow1.run(RunIds.generate());
// Try to read, should have nothing
Store store = getInjector().getInstance(DefaultStore.class);
WorkflowToken workflowToken = store.getWorkflowToken(workflow1, workflowRunId.getRun());
Assert.assertNull(workflowToken.get("key"));
BasicWorkflowToken token = new BasicWorkflowToken(1024);
token.setCurrentNode("node1");
token.put("key", "value");
// Publish some workflow states
WorkflowStateWriter workflowStateWriter = getInjector().getInstance(MessagingWorkflowStateWriter.class);
workflowStateWriter.setWorkflowToken(workflowRunId, token);
workflowStateWriter.addWorkflowNodeState(workflowRunId, new WorkflowNodeStateDetail("action1", NodeStatus.RUNNING));
// Verify the WorkflowToken
Tasks.waitFor("value", () -> Optional.ofNullable(store.getWorkflowToken(workflow1, workflowRunId.getRun()).get("key")).map(Value::toString).orElse(null), 10, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS);
// Verify the workflow node state
Tasks.waitFor(NodeStatus.RUNNING, () -> store.getWorkflowNodeStates(workflowRunId).stream().findFirst().map(WorkflowNodeStateDetail::getNodeStatus).orElse(null), 10, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS);
// Update the node state
workflowStateWriter.addWorkflowNodeState(workflowRunId, new WorkflowNodeStateDetail("action1", NodeStatus.COMPLETED));
// Verify the updated node state
Tasks.waitFor(NodeStatus.COMPLETED, () -> store.getWorkflowNodeStates(workflowRunId).stream().findFirst().map(WorkflowNodeStateDetail::getNodeStatus).orElse(null), 10, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS);
}
Aggregations