public function isConnectedToHost($hostId, $portNumber) { // what are we doing? $log = usingLog()->startAction("make sure ZMQ socket is connected to host '{$hostId}':{$portNumber}"); // build the address that we should be connected to $ipAddress = fromHost($hostId)->getIpAddress(); $zmqAddress = "tcp://{$ipAddress}:{$portNumber}"; // where are we connected to? $connections = fromZmqSocket($this->args[0])->getEndpoints(); // make sure we're connected assertsArray($connections['connect'])->containsValue($zmqAddress); // all done $log->endAction(); }
// // ------------------------------------------------------------------------ // ======================================================================== // // 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); });
public function disconnectFromAllHosts() { // what are we doing? $log = usingLog()->startAction("disconnect() ZMQ socket from all endpoints"); // where are we disconnecting from? $endpoints = fromZmqSocket($this->args[0])->getEndpoints(); foreach ($endpoints['connect'] as $address) { usingLog()->writeToLog("disconnecting from {$address}"); $this->args[0]->disconnect($address); } // all done $log->endAction(); }