private function restoreData(RestoreJob $job, JobStats $jobStats, OutputInterface $output)
 {
     $memoryAtSection = memory_get_usage();
     $timeStartSection = microtime(true);
     $output->writeln('<info>*** Starting with data restoring ***</info>' . PHP_EOL);
     $storedStats = array();
     /** @var Index $index */
     foreach ($job->getMappings()->getIndices() as $index) {
         $toIndex = null;
         /** @var Type $type */
         foreach ($index->getTypes() as $type) {
             /** @var Finder $finder */
             $finder = $this->filesystem->loadDataFiles($job->getPath(), $index->getName(), $type->getName());
             if (null === $finder) {
                 continue;
             }
             if (!isset($storedStats[$index->getName()])) {
                 $storedStats[$index->getName()] = array();
             }
             if (!isset($storedStats[$index->getName()][$type->getName()])) {
                 $storedStats[$index->getName()][$type->getName()] = array('filesRead' => 0, 'dataInType' => 0);
             }
             $mappingAction = $job->getStrategy()->getMapping($index->getName(), $type->getName());
             if (null === $mappingAction) {
                 throw new \Exception('Mapping action missing for "' . $index->getName() . '/' . $type->getName() . '"');
             }
             $docCount = $finder->count();
             $output->writeln('<comment>Store Data for:</comment>');
             $output->writeln('<comment> [from]' . $index->getName() . '/' . $type->getName() . '</comment>');
             $output->writeln('<comment> [to]' . $mappingAction->getTargetIndex() . '/' . $mappingAction->getTargetType() . '</comment>' . PHP_EOL);
             $progress = new ProgressBar($output, $docCount);
             $progress->setFormat('debug');
             $progress->display();
             $progress->start();
             /** @var SplFileInfo $file */
             foreach ($finder as $file) {
                 $data = json_decode($file->getContents(), true);
                 $id = $data['_id'];
                 $this->elastic->createDocument($mappingAction->getTargetIndex(), $mappingAction->getTargetType(), $id, $data['_source'], $job->getHost(), $job->getPort());
                 $progress->advance();
                 $storedStats[$index->getName()][$type->getName()]['filesRead']++;
             }
             $progress->finish();
             $output->writeln(PHP_EOL);
             $toIndex = $mappingAction->getTargetIndex();
         }
         $this->elastic->refreshIndex($toIndex, $job->getHost(), $job->getPort());
     }
     //add aggregated to storedStats for comparing later
     $docStats = $this->elastic->getDocCountByIndexType($job->getHost(), $job->getPort());
     foreach ($storedStats as $indexName => $types) {
         foreach ($types as $typeName => $typeStats) {
             $storedStats[$indexName][$typeName]['dataInType'] = $docStats->getDocCount($indexName, $typeName);
         }
     }
     $jobStats->setRestoreData(microtime(true) - $timeStartSection, memory_get_usage(), memory_get_usage() - $memoryAtSection, array('storedStats' => $storedStats));
     return $storedStats;
 }
 public function testCreateDocument()
 {
     $version = '1.6.0';
     $serverInfoData = $this->getServerInfoData($version);
     $index = 'my-index';
     $type = 'my-type';
     $id = 'my-id';
     $doc = ['my' => 'doc'];
     $this->request = $this->getMockBuilder('Elastification\\Client\\Request\\V1x\\UpdateDocumentRequest')->disableOriginalConstructor()->getMock();
     $this->serverInfoResponse->expects($this->exactly(3))->method('getData')->willReturn($serverInfoData);
     $this->request->expects($this->once())->method('setId')->with($id);
     $this->request->expects($this->once())->method('setBody')->with($doc);
     $this->requestFactory->expects($this->once())->method('create')->with('UpdateDocumentRequest', $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\\UpdateDocumentRequest'))->willReturnOnConsecutiveCalls($this->serverInfoResponse, $this->response);
     $result = $this->repository->createDocument($index, $type, $id, $doc, self::HOST, self::PORT);
     $this->assertSame($this->response, $result);
 }