Exemple #1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $output->writeln("Fill...");
     $minCard = $input->getArgument('min');
     $maxCard = $input->getArgument('max');
     $seed = sha1(microtime() . rand() . $minCard . $maxCard);
     /* @var $progressBar \Symfony\Component\Console\Helper\ProgressHelper */
     $progressBar = $this->getHelper('progress');
     /* @var $repo \Trismegiste\Yuurei\Persistence\RepositoryInterface */
     $repo = $this->getContainer()->get('dokudoki.repository');
     $netizenList = iterator_to_array($repo->find(['-class' => 'netizen']), false);
     $netizenCount = count($netizenList);
     $query = ['-class' => ['$in' => ['small', 'picture', 'video', 'repeat', 'status']]];
     $pubCount = $repo->getCursor($query)->count();
     $progressBar->start($output, $pubCount);
     $cursor = $repo->find($query);
     /* @var $publish \Trismegiste\Socialist\Publishing */
     foreach ($cursor as $publish) {
         $commentaryCount = rand($minCard, $maxCard);
         for ($k = 0; $k < $commentaryCount; $k++) {
             /* @var $picked \Trismegiste\SocialBundle\Security\Netizen */
             $picked = $netizenList[rand(0, $netizenCount - 1)];
             $comment = new \Trismegiste\Socialist\Commentary($picked->getAuthor());
             $comment->setMessage("This is a commentary ({$seed}) to fill the database for benchmark purpose");
             foreach ($picked->getFanIterator() as $fan => $dummy) {
                 $tmpAuth = new \Trismegiste\Socialist\Author($fan);
                 $comment->addFan($tmpAuth);
             }
             $publish->attachCommentary($comment);
         }
         $repo->persist($publish);
         $progressBar->advance();
     }
     $progressBar->finish();
 }
Exemple #2
0
 protected function fill(OutputInterface $output, $numUser, $msgPerUser)
 {
     /* @var $userRepo \Trismegiste\SocialBundle\Repository\NetizenRepository */
     $userRepo = $this->getContainer()->get('social.netizen.repository');
     /* @var $userFactory \Trismegiste\SocialBundle\Security\NetizenFactory */
     $userFactory = $this->getContainer()->get('security.netizen.factory');
     /* @var $contentRepo \Trismegiste\Yuurei\Persistence\Repository */
     $contentRepo = $this->getContainer()->get('dokudoki.repository');
     /* @var $progressBar \Symfony\Component\Console\Helper\ProgressHelper */
     $progressBar = $this->getHelper('progress');
     $output->writeln("With {$numUser} Users");
     $progressBar->start($output, $numUser * 3);
     for ($k = 0; $k < $numUser; $k++) {
         $user[$k] = $userFactory->create("iinano-netizen-{$k}", 'aaaa');
         $progressBar->advance();
     }
     // follow & like user
     for ($k = 0; $k < $numUser; $k++) {
         for ($j = 0; $j < $numUser; $j++) {
             $user[$k]->follow($user[$j]);
             $user[$k]->addFan($user[$j]->getAuthor());
         }
         $progressBar->advance();
     }
     for ($k = 0; $k < $numUser; $k++) {
         $userRepo->persist($user[$k]);
         $progressBar->advance();
     }
     $progressBar->finish();
     // message
     $output->writeln("Writing message");
     $progressBar->start($output, $numUser * $msgPerUser);
     for ($k = 0; $k < $numUser; $k++) {
         $batch = [];
         $author = $user[$k]->getAuthor();
         // template for one author :
         $docTemplate = new \Trismegiste\Socialist\SmallTalk($author);
         for ($i = 0; $i < $numUser; $i++) {
             $docTemplate->addFan($user[$i]->getAuthor());
         }
         for ($i = 0; $i < 10; $i++) {
             $comm = new \Trismegiste\Socialist\Commentary($user[rand(0, $numUser - 1)]->getAuthor());
             $comm->setMessage('This is not a very long commentary but I think it is a good approx');
             $docTemplate->attachCommentary($comm);
         }
         for ($j = 0; $j < $msgPerUser; $j++) {
             $doc = clone $docTemplate;
             $doc->setMessage("One small talk {$k}-{$j} for iinano benchmark, one giant doc for mongo but it's not a big deal for this database");
             $batch[] = $doc;
             //$contentRepo->persist($doc);
             $progressBar->advance();
         }
         $contentRepo->batchPersist($batch);
     }
     $progressBar->finish();
 }
 public function testCappedCollectionAlreadyExisting()
 {
     $limit = rand(14, 27);
     // defensive testing against immortal mutant
     for ($k = 0; $k < $limit; $k++) {
         $comment = new \Trismegiste\Socialist\Commentary($this->mockAuthorInterface);
         $comment->setMessage("msg{$k}");
         $this->sut->attachCommentary($comment);
     }
     $this->assertEquals($limit, $this->sut->getCommentaryCount());
     $this->sut->setCommentaryLimit(3);
     $this->assertEquals($limit, $this->sut->getCommentaryCount());
     $newComment = new \Trismegiste\Socialist\Commentary($this->mockAuthorInterface);
     $newComment->setMessage("last");
     $this->sut->attachCommentary($newComment);
     $this->assertEquals(3, $this->sut->getCommentaryCount());
     $this->assertEquals('last', $this->sut->getCommentaryIterator()->current()->getMessage());
 }