Exemplo n.º 1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $dialog = $this->getHelperSet()->get('dialog');
     $hoard_host = $dialog->ask($output, 'Hoard Host: ', 'hoard.dev');
     $request_count = $dialog->ask($output, 'Number of Events: ', 10000);
     // Assert Fake Bucket
     $id = '51cd6e83c2cea';
     $alias = 'demo-bucket';
     $data = array('_id' => $id, 'alias' => array($alias), 'description' => 'Demo Bucket', 'roles' => array('all' => 'owner'), 'created' => new \MongoDate(), 'updated' => new \MongoDate());
     $bucket = Bucket::create($data);
     // Events
     $events = array('test1', 'test2', 'test3', 'test4', 'test5');
     // Get Faker Factory
     $faker = \Faker\Factory::create();
     // Now pump data in
     $run = true;
     $count = 0;
     while ($run && $count < $request_count) {
         $event = $events[array_rand($events)];
         $post = json_encode(array('v' => 1, 'b' => $alias, 'e' => $event, 'd' => array('name' => $faker->name, 'gender' => rand(0, 1) === 1 ? 'male' : 'female', 'country' => $faker->countryCode, 'response_time' => rand(1, 1200))));
         $ch = curl_init('http://' . $hoard_host . '/api/track?apikey=' . $this->apikey);
         curl_setopt_array($ch, array(CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true, CURLOPT_POSTFIELDS => $post));
         $response = curl_exec($ch);
         $count++;
         echo "\rCount: " . str_pad(number_format($count), 10, ' ', STR_PAD_RIGHT) . '  ' . $response . '  ';
         usleep(rand(100, 10000));
     }
 }
Exemplo n.º 2
0
 public function req_post()
 {
     if ($this->app->request->get('action') === 'create_bucket') {
         $name = $this->app->request->get('bucket_name');
         $alias = strtolower($name);
         $alias = str_replace(array(' ', '_'), '-', $alias);
         $pattern = Bucket::$regex_id;
         // No name is specified
         if (!$alias) {
             $this->alert('You need to specify a name');
         } elseif (!preg_match($pattern, $alias)) {
             $this->alert('Invalid Alias. Please match <strong>' . $pattern . '</strong>');
         } elseif (Bucket::exists($alias)) {
             $this->alert('Bucket name must be unique across cluster');
         } else {
             $data = array('alias' => array($alias), 'description' => $name, 'roles' => array((string) $this->app->auth->id => 'owner'), 'created' => new \MongoDate(), 'updated' => new \MongoDate());
             $bucket = Bucket::create($data);
             if ($bucket) {
                 $this->alert('Your app was created. <a href="/bucket/' . $alias . '">' . $name . '</a>');
             } else {
                 $this->alert('There was a problem creating your bucket', 'error');
             }
         }
     }
     // Do normal GET request
     return $this->req_get();
 }
Exemplo n.º 3
0
 /**
  * Since buckets can be aliased, we must test this
  */
 public function testBucketAliasPayload()
 {
     // Create Bucket
     $bucket = Bucket::create(array('_id' => '51d077a88dff0', 'alias' => array('test-bucket-2')));
     // Create payload
     $payload = array('v' => 1, 'b' => $bucket->alias[0], 'e' => 'test-event', 'd' => array('test1' => 1, 'test2' => 2));
     // Make request
     $response = $this->makeApiRequest('GET', '/api/track?payload=' . urlencode(json_encode($payload)));
     $data = json_decode($response->getContent(), true);
     $this->assertArrayHasKey('id', $data['data']);
     // Update alias and do it again
     $bucket->alias = array('test-bucket-3');
     $bucket->save();
     $response = $this->makeApiRequest('GET', '/api/track?payload=' . urlencode(json_encode($payload)));
     $data = json_decode($response->getContent(), true);
     $this->assertEquals(404, $data['error']['code']);
     $this->assertEquals('Invalid Bucket', $data['error']['message']);
     // Musical bucket alias's!
     $bucket->alias = array('test-bucket-2');
     $bucket->save();
     $response = $this->makeApiRequest('GET', '/api/track?payload=' . urlencode(json_encode($payload)));
     $data = json_decode($response->getContent(), true);
     $this->assertArrayHasKey('id', $data['data']);
 }
Exemplo n.º 4
0
 /**
  * Create test bucket
  */
 public function createTestBucket()
 {
     $bucket = Bucket::create(array('_id' => '51d077a88dff0', 'alias' => array('test-bucket')));
     return $bucket;
 }