/**
  * Test that it throws an exception when an invalid data type is passed
  *
  * @return void
  */
 public function test_it_should_throw_exception_for_invalid_data_types()
 {
     $this->setExpectedException('Warden\\Exceptions\\InvalidNodeDataTypeException');
     $parambag = new CollectorParamBag();
     $parambag->add('request_memory', ['type' => 'string']);
     $parambag->setValue('request_memory', 100);
 }
 /**
  * Set up test env
  *
  * @return void
  */
 public function setUp()
 {
     $this->eventsDispatcher = new EventDispatcher();
     $this->collectorParamBag = new CollectorParamBag();
     $this->collectorParamBag->add('request_time', ['type' => 'integer', 'default' => 100, 'limit' => 100, 'value' => null]);
     $this->collectorParamBag->add('request_memory', ['type' => 'integer', 'default' => 1024, 'limit' => 1024, 'value' => null]);
     $this->startEvent = new StartEvent();
     $this->stopEvent = new StopEvent($this->collectorParamBag);
 }
예제 #3
0
 /**
  * Checks the limits against the actual recorded values and determines whether they have exceeded
  *
  * @return void
  */
 public function checkResults()
 {
     $data = $this->params->all();
     foreach ($data as $key => $value) {
         $failed = $this->expression->evaluate($value['expression'], array('value' => $value['value'], 'limit' => $value['limit']));
         if ($failed) {
             // We throw the exception because the limit has been breached.
             throw new Exceptions\LimitExceededException($value['value'], $value['limit'], $key);
         }
     }
 }
 /**
  * Set up test env
  *
  * @return void
  */
 public function setUp()
 {
     $this->eventDispatcher = new EventDispatcher();
     $this->params = new CollectorParamBag();
     $setup = Setup::createAnnotationMetadataConfiguration([ENTITIES], true);
     $this->em = EntityManager::create(['driver' => 'pdo_mysql', 'user' => 'user', 'password' => '', 'dbname' => 'warden'], $setup);
     // Setup Param Bag
     $this->params->add('query_limit', ['type' => 'integer', 'default' => 5, 'limit' => 5, 'value' => null, 'expression' => 'value >= limit']);
     // Sync the schema
     $this->schema = new SchemaTool($this->em);
     $this->schema->updateSchema($this->em->getMetadataFactory()->getAllMetadata(), true);
     // Events
     $this->start = new StartEvent();
     $this->stop = new StopEvent($this->params);
 }
예제 #5
0
 /**
  * Test that it allows me to add a collector information node
  * And subsequently allows me to set and get
  *
  * @return void
  * @author Dan Cox
  */
 public function test_can_add_and_get_set()
 {
     $parambag = new CollectorParamBag();
     $parambag->add('request_time', ['type' => 'integer', 'default' => 100, 'limit' => 5, 'value' => '']);
     $this->assertEquals('integer', $parambag->getType('request_time'));
     $this->assertEquals(100, $parambag->getDefault('request_time'));
     $this->assertEquals(5, $parambag->getLimit('request_time'));
     $this->assertEquals('', $parambag->request_time);
     $parambag->request_time = 500;
     $parambag->setLimit('request_time', 15);
     $this->assertEquals(500, $parambag->request_time);
     $this->assertEquals(15, $parambag->getLimit('request_time'));
     $parambag->setValue('request_time', 10);
     $this->assertEquals(10, $parambag->getValue('request_time'));
 }
예제 #6
0
 /**
  * Creates an instance of the collectors specified in settings
  * and runs their describe methods
  *
  * @param Array $collectors
  * @return void
  */
 public function createCollectors(array $collectors)
 {
     $descriptions = array();
     // Init each class, and gather their describe info
     foreach ($collectors as $key => $value) {
         $arguments = isset($value['arguments']) ? $value['arguments'] : array();
         $args = $this->resolveDependencies($arguments);
         $rfl = new \ReflectionClass($value['class']);
         $ins = $rfl->newInstanceArgs($args);
         $this->collectors[$key] = $ins;
         $descriptions = array_merge($descriptions, $ins->describe());
     }
     // Add the describe info to the param bag
     foreach ($descriptions as $key => $description) {
         $this->params->add($key, $description);
     }
 }