public function testSetRestoreData()
 {
     $timeTaken = 11;
     $memoryUsage = 22;
     $memoryUsed = 33;
     $options = array('my' => 'option');
     $this->entity->setRestoreData($timeTaken, $memoryUsage, $memoryUsed, $options);
     $result = $this->entity->toArray();
     $this->assertArrayHasKey(JobStats::NAME_RESTORE_DATA, $result['data']);
     $data = $result['data'][JobStats::NAME_RESTORE_DATA];
     $this->assertSame($timeTaken, $data['timeTaken']);
     $this->assertSame($memoryUsage, $data['memoryUsage']);
     $this->assertSame($memoryUsed, $data['memoryUsed']);
     $this->assertEquals($options, $data['options']);
     $this->assertContains(date('Y-m-d H:i:'), $data['createdAt']);
 }
 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;
 }