use of org.jenkinsci.plugins.workflow.support.storage.SimpleXStreamFlowNodeStorage in project workflow-cps-plugin by jenkinsci.
the class ArgumentsActionImplTest method testDeserialize.
/**
* Helper function to test direct file deserialization for an execution
*/
private void testDeserialize(FlowExecution execution) throws Exception {
if (!(execution instanceof CpsFlowExecution) || !(((CpsFlowExecution) execution).getStorage() instanceof SimpleXStreamFlowNodeStorage)) {
// Test is unfortunately coupled to the implementation -- otherwise it will simply hit caches
return;
}
SimpleXStreamFlowNodeStorage storage = (SimpleXStreamFlowNodeStorage) (((CpsFlowExecution) execution).getStorage());
Method getFileM = SimpleXStreamFlowNodeStorage.class.getDeclaredMethod("getNodeFile", String.class);
getFileM.setAccessible(true);
List<FlowNode> nodes = new DepthFirstScanner().allNodes(execution.getCurrentHeads());
Collections.sort(nodes, FlowScanningUtils.ID_ORDER_COMPARATOR);
Field nodeExecutionF = FlowNode.class.getDeclaredField("exec");
nodeExecutionF.setAccessible(true);
// Read each node via deserialization from storage, and sanity check the node, the actions, and the ArgumentsAction read back right
for (FlowNode f : nodes) {
XmlFile file = (XmlFile) (getFileM.invoke(storage, f.getId()));
Object tagObj = file.read();
Assert.assertNotNull(tagObj);
// Check actions & node in the Tag object, but without getting at the private Tag class
Field actionField = tagObj.getClass().getDeclaredField("actions");
Field nodeField = tagObj.getClass().getDeclaredField("node");
actionField.setAccessible(true);
nodeField.setAccessible(true);
Action[] deserializedActions = (Action[]) actionField.get(tagObj);
FlowNode deserializedNode = (FlowNode) (nodeField.get(tagObj));
nodeExecutionF.set(deserializedNode, f.getExecution());
Assert.assertNotNull(deserializedNode);
if (f.getActions().size() > 0) {
Assert.assertNotNull(deserializedActions);
Assert.assertEquals(f.getActions().size(), deserializedActions.length);
}
ArgumentsAction expectedInfoAction = f.getPersistentAction(ArgumentsAction.class);
if (expectedInfoAction != null) {
Action deserializedInfoAction = Iterables.getFirst(Iterables.filter(Lists.newArrayList(deserializedActions), Predicates.instanceOf(ArgumentsAction.class)), null);
Assert.assertNotNull(deserializedInfoAction);
ArgumentsAction ArgumentsAction = (ArgumentsAction) deserializedInfoAction;
// Compare original and deserialized step arguments to see if they match
Assert.assertEquals(ArgumentsAction.getStepArgumentsAsString(f), ArgumentsAction.getStepArgumentsAsString(deserializedNode));
Map<String, Object> expectedParams = expectedInfoAction.getArguments();
Map<String, Object> deserializedParams = ArgumentsAction.getArguments();
Assert.assertEquals(expectedParams.size(), deserializedParams.size());
for (String s : expectedParams.keySet()) {
Object expectedVal = expectedParams.get(s);
Object actualVal = deserializedParams.get(s);
if (expectedVal instanceof Comparable) {
Assert.assertEquals(actualVal, expectedVal);
}
}
}
}
}
use of org.jenkinsci.plugins.workflow.support.storage.SimpleXStreamFlowNodeStorage in project workflow-cps-plugin by jenkinsci.
the class CpsFlowExecution method createStorage.
private TimingFlowNodeStorage createStorage() throws IOException {
FlowNodeStorage wrappedStorage;
FlowDurabilityHint hint = getDurabilityHint();
wrappedStorage = (hint.isPersistWithEveryStep()) ? new SimpleXStreamFlowNodeStorage(this, getStorageDir()) : new BulkFlowNodeStorage(this, getStorageDir());
return new TimingFlowNodeStorage(wrappedStorage);
}
Aggregations