Arrêt d'un flux avant sa fin
Lorsque vous testez une partie d'un flux de messages, vous pouvez arrêter le flux avant qu'il ne se termine, à l'aide des méthodes setStopAtInputTerminal() et setStopAtOutputTerminal() sur un espion de noeud.
Avant de commencer
A propos de cette tâche
Vous pouvez utiliser la méthode setStopAtInputTerminal() sur un espion de noeud pour arrêter l'exécution d'un flux de messages sur un terminal d'entrée, comme si le terminal d'entrée n'était pas connecté. Par conséquent, le noeud et les noeuds suivants auxquels il est connecté ne sont pas évalués.
Vous pouvez également utiliser la méthode setStopAtOutputTerminal() pour arrêter l'exécution du flux de messages sur un terminal de sortie, comme si le terminal de sortie n'était pas connecté. Par conséquent, le noeud est évalué, mais les noeuds suivants ne le sont pas.
setStopAtInputTerminal() arrête la propagation au niveau du terminal d'entrée sur le noeud MQOutput :
// Define the Spy on the MQ Input which is used to inject the message
SpyObjectReference mqInputReference = new SpyObjectReference().application("ExamplesApp").
messageFlow("Example4").node("MQ Input");
NodeSpy mqInputNodeSpy = new NodeSpy(mqInputReference);
// Define the Spy on the Compute node which is used to validate the operation
SpyObjectReference computeReference = new SpyObjectReference().application("ExamplesApp").
messageFlow("Example4").node("Compute");
NodeSpy computeNodeSpy = new NodeSpy(computeReference);
// Define the Spy on the MQ Output node as we do not want this node to execute
SpyObjectReference mqOutputReference = new SpyObjectReference().application("ExamplesApp").
messageFlow("Example4").node("MQ Output");
NodeSpy mqOutputNodeSpy = new NodeSpy(mqOutputReference);
mqOutputNodeSpy.setStopAtInputTerminal("in");
// Declare a new TestMessageAssembly object for the message being sent into the node
TestMessageAssembly inputMessageAssembly = new TestMessageAssembly();
/* Loading of message assembly would be done here */
// Declare a new TestMessageAssembly object for the expected message propagated from Compute2 node
TestMessageAssembly afterComputeExpectedMessageAssembly = new TestMessageAssembly();
/* Loading of message assembly would be done here */
// Send the message assembly to the 'out' terminal of the HTTP Input node
mqInputNodeSpy.propagate(inputMessageAssembly, "out");
// Assert the Compute node is called and that the expected message is returned
assertThat(computeNodeSpy, nodeCallCountIs(1));
assertThat(computeNodeSpy, terminalPropagateCountIs("out", 1));
// Proof that the MQ Output node is not called
assertThat(mqOutputNodeSpy, nodeCallCountIs(0));
// Assert that the actual message assembly matches the expected message assembly
assertThat(actualMessageAssembly, equalsMessage(afterComputeExpectedMessageAssembly));
Vous pouvez obtenir un résultat similaire en utilisant la méthode setStopAtOutputTerminal() pour arrêter la propagation au niveau du terminal'out'du noeud Compute .