use of io.cdap.cdap.internal.app.runtime.workflow.BasicWorkflowToken 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);
}
use of io.cdap.cdap.internal.app.runtime.workflow.BasicWorkflowToken in project cdap by caskdata.
the class SparkExecutionServiceTest method testWorkflowToken.
@Test
public void testWorkflowToken() throws Exception {
ProgramRunId programRunId = new ProgramRunId("ns", "app", ProgramType.SPARK, "test", RunIds.generate().getId());
// Start a service with empty workflow token
BasicWorkflowToken token = new BasicWorkflowToken(10);
token.setCurrentNode("spark");
SparkExecutionService service = new SparkExecutionService(locationFactory, InetAddress.getLoopbackAddress().getCanonicalHostName(), programRunId, token);
service.startAndWait();
try {
SparkExecutionClient client = new SparkExecutionClient(service.getBaseURI(), programRunId);
// Update token via heartbeat
BasicWorkflowToken clientToken = new BasicWorkflowToken(10);
clientToken.setCurrentNode("spark");
for (int i = 0; i < 5; i++) {
clientToken.put("key", "value" + i);
client.heartbeat(clientToken);
// The server side token should get updated
Assert.assertEquals(Value.of("value" + i), token.get("key", "spark"));
}
clientToken.put("completed", "true");
client.completed(clientToken);
} finally {
service.stopAndWait();
}
// The token on the service side should get updated after the completed call.
Map<String, Value> values = token.getAllFromNode("spark");
Map<String, Value> expected = ImmutableMap.of("key", Value.of("value4"), "completed", Value.of("true"));
Assert.assertEquals(expected, values);
}
use of io.cdap.cdap.internal.app.runtime.workflow.BasicWorkflowToken in project cdap by caskdata.
the class TriggeringScheduleInfoAdapterTest method testSerDeserScheduleInfo.
@Test
public void testSerDeserScheduleInfo() {
BasicWorkflowToken token = new BasicWorkflowToken(1);
token.setCurrentNode("node");
token.put("tokenKey", "tokenVal");
List<TriggerInfo> triggerInfos = ImmutableList.of(new DefaultProgramStatusTriggerInfo("ns", Specifications.from(new WorkflowAppWithFork()).getName(), ProgramType.WORKFLOW, WorkflowAppWithFork.WorkflowWithFork.class.getSimpleName(), RunIds.generate(), ProgramStatus.COMPLETED, token, Collections.emptyMap()), new DefaultPartitionTriggerInfo("ns", "ds", 10, 11), new DefaultTimeTriggerInfo("1 * * * *", 0L));
TriggeringScheduleInfo scheduleInfo = new DefaultTriggeringScheduleInfo("schedule", "description", triggerInfos, ImmutableMap.of("key", "value"));
String scheduleInfoJson = GSON.toJson(scheduleInfo);
TriggeringScheduleInfo deserializedScheduleInfo = GSON.fromJson(scheduleInfoJson, TriggeringScheduleInfo.class);
Assert.assertEquals(scheduleInfoJson, GSON.toJson(deserializedScheduleInfo));
DefaultProgramStatusTriggerInfo expectedProgramStatusTriggerInfo = (DefaultProgramStatusTriggerInfo) triggerInfos.get(0);
DefaultProgramStatusTriggerInfo deserializedProgramStatusTriggerInfo = (DefaultProgramStatusTriggerInfo) deserializedScheduleInfo.getTriggerInfos().get(0);
Assert.assertEquals(expectedProgramStatusTriggerInfo.getApplicationName(), deserializedProgramStatusTriggerInfo.getApplicationName());
Assert.assertEquals(expectedProgramStatusTriggerInfo.getWorkflowToken().getAll(), deserializedProgramStatusTriggerInfo.getWorkflowToken().getAll());
}
Aggregations