public function testGetApiDurations()
 {
     // emit 2 metric events
     $_tuple = new M3_Event_Tuple();
     $_dispatcher = M3_Event_DispatcherFactory::createApiResponseTimeTupleDispatcher("some.api.name", $_tuple);
     $_dispatcher->startTimer();
     sleep(1);
     $_dispatcher->stopTimer();
     $_dispatcher->startTimer();
     sleep(1);
     $_dispatcher->stopTimer();
     // make sure we can aggregate those two metrics
     $_apiCall = $this->initRest(new MetricsGetApiDurations(), null);
     $_results = $_apiCall->execute();
     $_results = M3_Util_Stats::unflattenArray($_results['api_duration']);
     $this->assertTrue(is_array($_results));
     $this->assertArrayHasKey('some.api.name', $_results);
     $this->assertGreaterThanOrEqual(2, $_results['some.api.name']['count']);
     $this->assertGreaterThanOrEqual(0, $_results['some.api.name']['min']);
     $this->assertGreaterThanOrEqual(0, $_results['some.api.name']['max']);
     $this->assertGreaterThanOrEqual(0, $_results['some.api.name']['avg']);
 }
 public function testPurgeApiDurations()
 {
     // emit 2 metric events
     $_tuple = new M3_Event_Tuple();
     $_dispatcher = M3_Event_DispatcherFactory::createApiResponseTimeTupleDispatcher("some.api.name", $_tuple);
     $_dispatcher->startTimer();
     sleep(1);
     $_dispatcher->stopTimer();
     $_dispatcher->startTimer();
     sleep(1);
     $_dispatcher->stopTimer();
     // make sure we can aggregate those two metrics
     $_apiCall = $this->initRest(new MetricsPurgeApiDurations(), null);
     $_results = $_apiCall->execute();
     $this->assertGreaterThanOrEqual(2, $_results);
     // make sure we really deleted the data
     $_apiCall = $this->initRest(new MetricsGetApiDurations(), null);
     $_results = $_apiCall->execute();
     $this->assertTrue(is_array($_results));
     $this->assertTrue(is_array($_results['api_duration']));
     $this->assertEquals(0, count($_results['api_duration']));
 }
Ejemplo n.º 3
0
 /**
  * Execute the request and return the hash results, this
  * was separated soley for the purpose of running test cases.
  *
  * @param unknown_type $requestParams
  */
 function executeRequest(Api_RequestContext &$context)
 {
     $response = array();
     if ($context->getMethod() == null) {
         throw new OpenFBAPIException('Incorrect Signature, Missing METHOD.', FB_ERROR_CODE_INCORRECT_SIGNATURE);
     }
     // Call the object/method.
     $api_name = explode('.', $context->getMethod());
     $api_pkg = $api_name[1];
     $api_class = ucfirst($api_name[1]) . ucfirst($api_name[2]);
     $lasterrorlevel = error_reporting(E_ERROR);
     if (!(include_once $api_name[0] . '/rest/' . $api_class . '.php')) {
         // TODO: Move these to match the packaging standard
         // Default OpenFBServer API implementations are still here
         include_once 'ringside/api/facebook/' . $api_class . '.php';
     }
     error_reporting($lasterrorlevel);
     if (!$api_class) {
         throw new Exception("Class {$api_class} could not be loaded");
     }
     $faf = new $api_class();
     // Set the server object.
     $faf->_setServer($this);
     // set the context
     $faf->_setContext($context);
     // Load the session and setup the session.
     $faf->loadSession();
     // Execute delegation?
     $faf->delegateRequest();
     // Validation steps
     $faf->validateSession();
     $faf->validateApiKey();
     $faf->validateSig();
     $faf->validateVersion();
     $faf->validateCallId();
     $faf->validateRequest();
     // let's invoke the API that is being requested - collect stat around the call
     $tuple = new M3_Event_Tuple($faf->getNetworkId(), $faf->getAppId(), $faf->getUserId());
     $dispatcher = M3_Event_DispatcherFactory::createApiResponseTimeTupleDispatcher($context->getMethod(), $tuple);
     $dispatcher->startTimer();
     $response = $faf->execute();
     $dispatcher->stopTimer();
     // emit event
     return $response;
 }