public function getDataFor($metric, $startTime, $endTime) { // when are we looking for? $humanStartTime = date('Y-m-d H:i:s', $startTime); $humanEndTime = date('Y-m-d H:i:s', $endTime); // what are we doing? $log = usingLog()->startAction("get raw data from graphite for '{$metric}' between '{$humanStartTime}' and '{$humanEndTime}'"); // find out where graphite is $graphiteUrl = fromConfig()->getModuleSetting('graphite.url'); if (substr($graphiteUrl, -1, 1) !== '/') { $graphiteUrl .= '/'; } // get the requested data $response = fromHttp()->get("{$graphiteUrl}render?format=json&target={$metric}&from={$startTime}&until={$endTime}"); // are there any stats in the response? assertsArray($response->chunks)->isExpectedType(); assertsArray($response->chunks)->isNotEmpty(); // assemble the raw chunks into one string to decode $rawStats = implode("", $response->chunks); assertsString($rawStats)->isValidJson(); $stats = json_decode($rawStats); // all done $log->endAction(); return $stats; }
// // ------------------------------------------------------------------------ // ======================================================================== // // POSSIBLE ACTION(S) // // ------------------------------------------------------------------------ $story->addAction(function () { $checkpoint = getCheckpoint(); // this should pass $testData1 = ["alpha" => "a", "bravo" => "b", "charlie" => "c", "delta" => "d", "echo" => [1, 2, 3, 4, 5]]; assertsArray($testData1)->isNotNull(); // and this should fail $testData2 = null; $checkpoint->test2Exception = false; try { assertsArray($testData2)->isNotNull(); } catch (Exception $e) { $checkpoint->test2Exception = true; } }); // ======================================================================== // // POST-TEST INSPECTION // // ------------------------------------------------------------------------ $story->addPostTestInspection(function () { $checkpoint = getCheckpoint(); assertsObject($checkpoint)->hasAttribute("test2Exception"); assertsBoolean($checkpoint->test2Exception)->isTrue(); });
// ------------------------------------------------------------------------ // ======================================================================== // // POSSIBLE ACTION(S) // // ------------------------------------------------------------------------ $story->addAction(function () { $checkpoint = getCheckpoint(); // this should pass $testData1 = ["alpha" => "a", "bravo" => "b", "charlie" => "c", "delta" => "d"]; $testData2 = ["alpha" => "1", "bravo" => "2", "charlie" => "3", "delta" => "4"]; assertsArray($testData1)->doesNotEqual($testData2); // and this should fail $testData3 = ["alpha" => "a", "bravo" => "b", "charlie" => "c", "delta" => "d"]; $checkpoint->test2Exception = false; try { assertsArray($testData3)->doesNotEqual($testData1); } catch (Exception $e) { $checkpoint->test2Exception = true; } }); // ======================================================================== // // POST-TEST INSPECTION // // ------------------------------------------------------------------------ $story->addPostTestInspection(function () { $checkpoint = getCheckpoint(); assertsObject($checkpoint)->hasAttribute("test2Exception"); assertsBoolean($checkpoint->test2Exception)->isTrue(); });
// STORY SETUP / TEAR-DOWN // // ------------------------------------------------------------------------ // ======================================================================== // // POSSIBLE ACTION(S) // // ------------------------------------------------------------------------ $story->addAction(function () { $checkpoint = getCheckpoint(); // this should pass $testData = ["alpha" => "a", "bravo" => "b", "charlie" => "c", "delta" => "d"]; assertsArray($testData)->hasKey("alpha"); // and this should fail $checkpoint->test2Exception = false; try { assertsArray($testData)->hasKey("zulu"); } catch (Exception $e) { $checkpoint->test2Exception = true; } }); // ======================================================================== // // POST-TEST INSPECTION // // ------------------------------------------------------------------------ $story->addPostTestInspection(function () { $checkpoint = getCheckpoint(); assertsObject($checkpoint)->hasAttribute("test2Exception"); assertsBoolean($checkpoint->test2Exception)->isTrue(); });
// ======================================================================== // // POSSIBLE ACTION(S) // // ------------------------------------------------------------------------ $story->addAction(function () { // get the checkpoint, to store data in $checkpoint = getCheckpoint(); // load our test page usingBrowser()->gotoPage("file://" . __DIR__ . '/../../testpages/index.html'); // resize the window usingBrowser()->resizeCurrentWindow($checkpoint->expectedDimensions['width'], $checkpoint->expectedDimensions['height']); // remember the new size for later $checkpoint->actualDimensions = fromBrowser()->getCurrentWindowSize(); // did the browser change size? expectsBrowser()->currentWindowSizeIs($checkpoint->expectedDimensions['width'], $checkpoint->expectedDimensions['height']); }); // ======================================================================== // // POST-TEST INSPECTION // // ------------------------------------------------------------------------ $story->addPostTestInspection(function () { // get the checkpoint $checkpoint = getCheckpoint(); // do we have the dimensions at all? assertsObject($checkpoint)->hasAttribute('expectedDimensions'); assertsObject($checkpoint)->hasAttribute('actualDimensions'); // do they match? assertsArray($checkpoint->actualDimensions)->equals($checkpoint->expectedDimensions); });
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.multi.inPort"); $outPort = fromHost($hostId)->getStorySetting("zmq.multi.outPort"); $inSocket = usingZmqContext($context)->connectToHost($hostId, $inPort, 'PUSH'); $outSocket = usingZmqContext($context)->connectToHost($hostId, $outPort, 'PULL'); expectsZmqSocket($inSocket)->canSendmultiNonBlocking($checkpoint->expectedMessage); $checkpoint->actualMessage = fromZmqSocket($outSocket)->recvMulti(); } }); // ======================================================================== // // POST-TEST INSPECTION // // ------------------------------------------------------------------------ $story->addPostTestInspection(function () { $checkpoint = getCheckpoint(); assertsObject($checkpoint)->hasAttribute("expectedMessage"); assertsObject($checkpoint)->hasAttribute("actualMessage"); assertsArray($checkpoint->actualMessage)->equals($checkpoint->expectedMessage); });
// // ------------------------------------------------------------------------ // ======================================================================== // // POSSIBLE ACTION(S) // // ------------------------------------------------------------------------ $story->addAction(function () { $checkpoint = getCheckpoint(); // this should pass $data1 = ["a", "b", "c", "d"]; assertsArray($data1)->doesNotContainValue("z"); // and this should fail $checkpoint->data2Exception = false; try { $data2 = $data1; assertsArray($data2)->doesNotContainValue("a"); } catch (Exception $e) { $checkpoint->data2Exception = true; } }); // ======================================================================== // // POST-TEST INSPECTION // // ------------------------------------------------------------------------ $story->addPostTestInspection(function () { $checkpoint = getCheckpoint(); assertsObject($checkpoint)->hasAttribute("data2Exception"); assertsBoolean($checkpoint->data2Exception)->isTrue(); });
// // ------------------------------------------------------------------------ // ======================================================================== // // POSSIBLE ACTION(S) // // ------------------------------------------------------------------------ $story->addAction(function () { $checkpoint = getCheckpoint(); // this should pass $data1 = []; assertsArray($data1)->isArray(); // and this should fail $checkpoint->data2Exception = false; try { $data2 = ""; assertsArray($data2)->isArray(); } catch (Exception $e) { $checkpoint->data2Exception = true; } }); // ======================================================================== // // POST-TEST INSPECTION // // ------------------------------------------------------------------------ $story->addPostTestInspection(function () { $checkpoint = getCheckpoint(); assertsObject($checkpoint)->hasAttribute("data2Exception"); assertsBoolean($checkpoint->data2Exception)->isTrue(); });
// ======================================================================== // // STORY DETAILS // // ------------------------------------------------------------------------ $story = newStoryFor('Storyplayer')->inGroup(['Stories', 'Groups'])->called('Can use an array for groups'); $story->requiresStoryplayerVersion(2); // ======================================================================== // // STORY SETUP / TEAR-DOWN // // ------------------------------------------------------------------------ // ======================================================================== // // POSSIBLE ACTION(S) // // ------------------------------------------------------------------------ $story->addAction(function () { // nothing to do }); // ======================================================================== // // POST-TEST INSPECTION // // ------------------------------------------------------------------------ $story->addPostTestInspection(function () use($story) { $groups = $story->getGroup(); assertsArray($groups)->isArray(); assertsArray($groups)->equals(['Stories', 'Groups']); });
// // ------------------------------------------------------------------------ // ======================================================================== // // POSSIBLE ACTION(S) // // ------------------------------------------------------------------------ $story->addAction(function () { $checkpoint = getCheckpoint(); // this should pass $data1 = []; assertsArray($data1)->isEmpty(); // and this should fail $checkpoint->data2Exception = false; try { $data2 = ["hello, Storyplayer "]; assertsArray($data2)->isEmpty(); } catch (Exception $e) { $checkpoint->data2Exception = true; } }); // ======================================================================== // // POST-TEST INSPECTION // // ------------------------------------------------------------------------ $story->addPostTestInspection(function () { $checkpoint = getCheckpoint(); assertsObject($checkpoint)->hasAttribute("data2Exception"); assertsBoolean($checkpoint->data2Exception)->isTrue(); });
// // ------------------------------------------------------------------------ // ======================================================================== // // POSSIBLE ACTION(S) // // ------------------------------------------------------------------------ $story->addAction(function () { $checkpoint = getCheckpoint(); // this should pass $data1 = ["a", "b", "c", "d"]; assertsArray($data1)->containsValue("a"); // and this should fail $checkpoint->data2Exception = false; try { $data2 = $data1; assertsArray($data2)->containsValue("z"); } catch (Exception $e) { $checkpoint->data2Exception = true; } }); // ======================================================================== // // POST-TEST INSPECTION // // ------------------------------------------------------------------------ $story->addPostTestInspection(function () { $checkpoint = getCheckpoint(); assertsObject($checkpoint)->hasAttribute("data2Exception"); assertsBoolean($checkpoint->data2Exception)->isTrue(); });
$checkpoint = getCheckpoint(); // this should pass $testData1 = ["alpha" => "a", "bravo" => "b", "charlie" => "c", "delta" => "d"]; $testData2 = [1, 2, 3, 4]; assertsArray($testData1)->isSameLengthAs($testData2); // and these should fail $testData3 = [1]; $checkpoint->test2Exception = false; try { assertsArray($testData3)->isSameLengthAs($testData1); } catch (Exception $e) { $checkpoint->test2Exception = true; } $checkpoint->test3Exception = false; try { assertsArray($testData1)->isSameLengthAs($testData3); } catch (Exception $e) { $checkpoint->test3Exception = true; } }); // ======================================================================== // // POST-TEST INSPECTION // // ------------------------------------------------------------------------ $story->addPostTestInspection(function () { $checkpoint = getCheckpoint(); assertsObject($checkpoint)->hasAttribute("test2Exception"); assertsBoolean($checkpoint->test2Exception)->isTrue(); assertsObject($checkpoint)->hasAttribute("test3Exception"); assertsBoolean($checkpoint->test3Exception)->isTrue();
// STORY SETUP / TEAR-DOWN // // ------------------------------------------------------------------------ // ======================================================================== // // POSSIBLE ACTION(S) // // ------------------------------------------------------------------------ $story->addAction(function () { $checkpoint = getCheckpoint(); // this should pass $testData = ["alpha" => "a", "bravo" => "b", "charlie" => "c", "delta" => "d"]; assertsArray($testData)->doesNotHaveKey("zulu"); // and this should fail $checkpoint->test2Exception = false; try { assertsArray($testData)->doesNotHaveKey("alpha"); } catch (Exception $e) { $checkpoint->test2Exception = true; } }); // ======================================================================== // // POST-TEST INSPECTION // // ------------------------------------------------------------------------ $story->addPostTestInspection(function () { $checkpoint = getCheckpoint(); assertsObject($checkpoint)->hasAttribute("test2Exception"); assertsBoolean($checkpoint->test2Exception)->isTrue(); });
// ------------------------------------------------------------------------ // ======================================================================== // // POSSIBLE ACTION(S) // // ------------------------------------------------------------------------ $story->addAction(function () { $checkpoint = getCheckpoint(); // this should pass $testData1 = ["alpha" => "a", "bravo" => "b", "charlie" => "c", "delta" => "d", "echo" => [1, 2, 3, 4, 5]]; $testData2 = ["alpha" => "a", "bravo" => "b", "charlie" => "c", "delta" => "d", "echo" => [1, 2, 3, 4, 5]]; assertsArray($testData1)->equals($testData2); // and this should fail $testData3 = [1]; $checkpoint->test2Exception = false; try { assertsArray($testData3)->equals($testData1); } catch (Exception $e) { $checkpoint->test2Exception = true; } }); // ======================================================================== // // POST-TEST INSPECTION // // ------------------------------------------------------------------------ $story->addPostTestInspection(function () { $checkpoint = getCheckpoint(); assertsObject($checkpoint)->hasAttribute("test2Exception"); assertsBoolean($checkpoint->test2Exception)->isTrue(); });
// ======================================================================== // // STORY DETAILS // // ------------------------------------------------------------------------ $story = newStoryFor('Storyplayer')->generateGroup()->called('Can generate group name from file structure'); $story->requiresStoryplayerVersion(2); // ======================================================================== // // STORY SETUP / TEAR-DOWN // // ------------------------------------------------------------------------ // ======================================================================== // // POSSIBLE ACTION(S) // // ------------------------------------------------------------------------ $story->addAction(function () { // nothing to do }); // ======================================================================== // // POST-TEST INSPECTION // // ------------------------------------------------------------------------ $story->addPostTestInspection(function () use($story) { $groups = $story->getStoryFilename(); assertsArray($groups)->isArray(); assertsArray($groups)->equals(['tests', 'stories', 'stories', 'groups']); });
// STORY SETUP / TEAR-DOWN // // ------------------------------------------------------------------------ // ======================================================================== // // POSSIBLE ACTION(S) // // ------------------------------------------------------------------------ $story->addAction(function () { $checkpoint = getCheckpoint(); // this should pass $testData = ["alpha" => "a", "bravo" => "b", "charlie" => "c", "delta" => "d"]; assertsArray($testData)->hasLength(4); // and this should fail $checkpoint->test2Exception = false; try { assertsArray($testData)->hasLength(5); } catch (Exception $e) { $checkpoint->test2Exception = true; } }); // ======================================================================== // // POST-TEST INSPECTION // // ------------------------------------------------------------------------ $story->addPostTestInspection(function () { $checkpoint = getCheckpoint(); assertsObject($checkpoint)->hasAttribute("test2Exception"); assertsBoolean($checkpoint->test2Exception)->isTrue(); });