public function testCreateScrollSearchException()
 {
     $version = '1.6.0';
     $serverInfoData = $this->getServerInfoData($version);
     $query = array('query' => array('match_all' => array()));
     $scrollUnitTimeout = '1m';
     $sizePerChart = 2;
     $index = 'my-index';
     $type = 'my-type';
     $data = ['no_scroll_id' => 'abc'];
     $nativeArrayGatewaay = $this->getMockBuilder('Elastification\\Client\\Serializer\\Gateway\\NativeArrayGateway')->disableOriginalConstructor()->getMock();
     $nativeArrayGatewaay->expects($this->once())->method('getGatewayValue')->willReturn($data);
     $this->response->expects($this->once())->method('getData')->willReturn($nativeArrayGatewaay);
     $this->serverInfoResponse->expects($this->exactly(3))->method('getData')->willReturn($serverInfoData);
     $this->request->expects($this->once())->method('setBody')->with($this->equalTo($query));
     $this->request->expects($this->exactly(3))->method('setParameter')->withConsecutive(array('scroll', $scrollUnitTimeout), array('size', $sizePerChart), array('search_type', 'scan'));
     $this->requestFactory->expects($this->once())->method('create')->with('SearchRequest', $version, $index, $type, $this->serializer)->willReturn($this->request);
     $this->client->expects($this->exactly(2))->method('send')->withConsecutive($this->isInstanceOf('Elastification\\Client\\Request\\V1x\\NodeInfoRequest'), $this->isInstanceOf('Elastification\\Client\\Request\\V1x\\SearchRequest'))->willReturnOnConsecutiveCalls($this->serverInfoResponse, $this->response);
     try {
         $this->repository->createScrollSearch($index, $type, self::HOST, self::PORT, $scrollUnitTimeout, $sizePerChart);
     } catch (\Exception $exception) {
         $this->assertSame('Scroll id is not set in in response', $exception->getMessage());
         return;
     }
     $this->fail();
 }
 /**
  * Stores data into the filesystem and returns stored stats
  *
  * @param BackupJob $job
  * @param JobStats $jobStats
  * @param OutputInterface $output
  * @return array
  * @author Daniel Wendlandt
  */
 private function storeData(BackupJob $job, JobStats $jobStats, OutputInterface $output)
 {
     $memoryAtSection = memory_get_usage();
     $timeStartSection = microtime(true);
     $output->writeln('<info>*** Starting with data storing ***</info>' . PHP_EOL);
     $docCount = $this->elastic->getDocCountByIndexType($job->getHost(), $job->getPort());
     $storedStats = array();
     /** @var Index $index */
     foreach ($job->getMappings()->getIndices() as $index) {
         if (0 === $docCount->getDocCount($index->getName())) {
             continue;
         }
         /** @var Type $type */
         foreach ($index->getTypes() as $type) {
             $docsInType = $docCount->getDocCount($index->getName(), $type->getName());
             if (0 === $docsInType) {
                 continue;
             }
             $scrollId = $this->elastic->createScrollSearch($index->getName(), $type->getName(), $job->getHost(), $job->getPort());
             $storedStats[$index->getName()][$type->getName()]['aggregatedNumberOfDocs'] = $docsInType;
             $storedStats[$index->getName()][$type->getName()]['storedNumberOfDocs'] = 0;
             $output->writeln('<comment>Store Data for: ' . $index->getName() . '/' . $type->getName() . '</comment>');
             $progress = new ProgressBar($output, $docsInType);
             $progress->setFormat('debug');
             $progress->display();
             $progress->start();
             while (true) {
                 $data = $this->elastic->getScrollSearchData($scrollId, $job->getHost(), $job->getPort());
                 if (0 === count($data['hits'])) {
                     break;
                 }
                 $scrollId = $data['scrollId'];
                 $storedDocs = $this->filesystem->storeData($job->getPath(), $index->getName(), $type->getName(), $data['hits']);
                 $storedStats[$index->getName()][$type->getName()]['storedNumberOfDocs'] += $storedDocs;
                 $progress->advance($storedDocs);
             }
             $progress->finish();
             $output->writeln(PHP_EOL);
         }
     }
     $jobStats->setStoreData(microtime(true) - $timeStartSection, memory_get_usage(), memory_get_usage() - $memoryAtSection, array('stats' => $storedStats));
     return $storedStats;
 }