/**
  * performs sending the request
  *
  * @param RequestInterface $request
  *
  * @throws ClientException
  * @throws RequestException
  * @return ResponseInterface
  * @author Daniel Wendlandt
  */
 public function send(RequestInterface $request)
 {
     $timeTaken = microtime(true);
     try {
         $response = $this->client->send($request);
         if (null !== $this->dataCollector) {
             $this->dataCollector->add(ElasticsearchDataCollector::TYPE_SUCCESS, (microtime(true) - $timeTaken) * 1000, $request, $response);
         }
         return $response;
     } catch (ClientException $exception) {
         if (null !== $this->dataCollector) {
             $this->dataCollector->add(ElasticsearchDataCollector::TYPE_ERROR, (microtime(true) - $timeTaken) * 1000, $request);
         }
         throw $exception;
     }
 }
 public function testGetCount()
 {
     $timeTaken = 20;
     $this->request->expects($this->exactly(2))->method('getMethod')->willReturn('GET');
     $this->request->expects($this->exactly(2))->method('getIndex')->willReturn('index');
     $this->request->expects($this->exactly(2))->method('getType')->willReturn('type');
     $this->request->expects($this->exactly(2))->method('getAction')->willReturn('action');
     $this->request->expects($this->exactly(2))->method('getSupportedClass')->willReturn('supportedClass');
     $this->request->expects($this->exactly(4))->method('getBody')->willReturn('{"id": 1}');
     $this->dataCollector->add(ElasticsearchDataCollector::TYPE_SUCCESS, $timeTaken, $this->request);
     $this->dataCollector->add(ElasticsearchDataCollector::TYPE_SUCCESS, $timeTaken, $this->request);
     $this->assertEquals(2, $this->dataCollector->getCount());
 }