Пример #1
0
 public function set($fieldName, $value)
 {
     // convert $value into something that can appear in our logs
     $convertor = new DataPrinter();
     $printable = $convertor->convertToString($value);
     // what are we doing?
     $log = usingLog()->startAction("set checkpoint field '{$fieldName}' to '{$printable}'");
     // get the checkpoint
     $checkpoint = getCheckpoint();
     // set the value
     $checkpoint->{$fieldName} = $value;
     // all done
     $log->endAction();
 }
Пример #2
0
 public function get($fieldName)
 {
     // what are we doing?
     $log = usingLog()->startAction("get value of checkpoint field '{$fieldName}'");
     // get the checkpoint
     $checkpoint = getCheckpoint();
     // does the value exist?
     if (!isset($checkpoint->{$fieldName})) {
         throw new E5xx_ActionFailed(__METHOD__);
     }
     // all done
     $log->endAction();
     return $checkpoint->{$fieldName};
 }
//
// ------------------------------------------------------------------------
// ========================================================================
//
// POSSIBLE ACTION(S)
//
// ------------------------------------------------------------------------
$story->addAction(function () {
    // we're going to store the received message in here
    $checkpoint = getCheckpoint();
    foreach (firstHostWithRole("zmq_target") as $hostId) {
        $context = usingZmqContext()->getZmqContext();
        $inPort = fromHost($hostId)->getStorySetting("zmq.single.inPort");
        $outPort = fromHost($hostId)->getStorySetting("zmq.single.outPort");
        $inSocket = usingZmqContext($context)->connectToHost($hostId, $inPort, 'PUSH');
        $outSocket = usingZmqContext($context)->connectToHost($hostId, $outPort, 'PULL');
        usingZmqSocket($inSocket)->send($checkpoint->expectedMessage);
        $checkpoint->actualMessage = fromZmqSocket($outSocket)->recv();
    }
});
// ========================================================================
//
// POST-TEST INSPECTION
//
// ------------------------------------------------------------------------
$story->addPostTestInspection(function () {
    $checkpoint = getCheckpoint();
    assertsObject($checkpoint)->hasAttribute("expectedMessage");
    assertsObject($checkpoint)->hasAttribute("actualMessage");
    assertsString($checkpoint->actualMessage)->equals($checkpoint->expectedMessage);
});