protected function setUp()
 {
     parent::setup();
     // Stub ouf 'addToElastic' search to prevent writes into Elastic Search happening by default.
     /** @var \Tripod\Mongo\Driver|PHPUnit_Framework_MockObject_MockObject $tripod */
     $this->tripod = $this->getMock('\\Tripod\\Mongo\\Driver', array('addToSearchIndexQueue'), array('CBD_testing', 'tripod_php_testing'));
     $this->tripod->expects($this->any())->method('addToSearchIndexQueue');
     $this->getTripodCollection($this->tripod)->drop();
     // Lock collection no longer available from Driver, so drop it manually
     \Tripod\Mongo\Config::getInstance()->getCollectionForLocks($this->tripod->getStoreName())->drop();
     $this->loadResourceDataViaTripod();
     $this->tripodTransactionLog = new \Tripod\Mongo\TransactionLog();
     $this->tripodTransactionLog->purgeAllTransactions();
     $this->tripod->setTransactionLog($this->tripodTransactionLog);
 }
 /**
  * @param Driver $tripod
  */
 public function __construct(Driver $tripod)
 {
     $this->tripod = $tripod;
     $this->storeName = $tripod->getStoreName();
     $this->labeller = new Labeller();
     $this->config = Config::getInstance();
 }
Esempio n. 3
0
 public function testRemoveTableSpecDoesNotAffectInvalidation()
 {
     foreach (\Tripod\Mongo\Config::getInstance()->getTableSpecifications($this->tripod->getStoreName()) as $specId => $spec) {
         $this->generateTableRows($specId);
     }
     $context = 'http://talisaspire.com/';
     $uri = "http://talisaspire.com/works/4d101f63c10a6";
     $collection = \Tripod\Mongo\Config::getInstance()->getCollectionForTable('tripod_php_testing', 't_resource');
     $this->assertGreaterThan(0, $collection->count(array('_id.type' => 't_resource', 'value._impactIndex' => array(_ID_RESOURCE => $uri, _ID_CONTEXT => $context))));
     $config = \Tripod\Mongo\Config::getConfig();
     unset($config['stores']['tripod_php_testing']['table_specifications'][0]);
     \Tripod\Mongo\Config::setConfig($config);
     /** @var PHPUnit_Framework_MockObject_MockObject|\Tripod\Mongo\Driver $mockTripod */
     $mockTripod = $this->getMockBuilder('\\Tripod\\Mongo\\Driver')->setMethods(array('getComposite'))->setConstructorArgs(array('CBD_testing', 'tripod_php_testing', array('defaultContext' => $context, OP_ASYNC => array(OP_VIEWS => true, OP_TABLES => false, OP_SEARCH => true))))->getMock();
     $mockTables = $this->getMockBuilder('\\Tripod\\Mongo\\Composites\\Tables')->setMethods(array('update'))->setConstructorArgs(array('tripod_php_testing', \Tripod\Mongo\Config::getInstance()->getCollectionForCBD('tripod_php_testing', 'CBD_testing'), $context))->getMock();
     $labeller = new \Tripod\Mongo\Labeller();
     $mockTripod->expects($this->once())->method('getComposite')->with(OP_TABLES)->will($this->returnValue($mockTables));
     $mockTables->expects($this->never())->method('update');
     $originalGraph = $mockTripod->describeResource($uri);
     $updatedGraph = $originalGraph->get_subject_subgraph($uri);
     $updatedGraph->add_literal_triple($uri, $labeller->qname_to_uri('dct:description'), 'Physics textbook');
     $mockTripod->saveChanges($originalGraph, $updatedGraph);
     // The table row should still be there, even if the tablespec no longer exists
     $this->assertGreaterThan(0, $collection->count(array('_id.type' => 't_resource', 'value._impactIndex' => array(_ID_RESOURCE => $uri, _ID_CONTEXT => $context))));
 }
Esempio n. 4
0
 /**
  * @param \Tripod\Mongo\Driver $tripod
  * @param string $readPreference
  * @throws \Tripod\Exceptions\SearchException
  */
 public function __construct(\Tripod\Mongo\Driver $tripod, $readPreference = ReadPreference::RP_PRIMARY)
 {
     $this->tripod = $tripod;
     $this->storeName = $tripod->getStoreName();
     $this->podName = $tripod->podName;
     $this->labeller = new Labeller();
     $this->stat = $tripod->getStat();
     $this->config = Config::getInstance();
     $provider = $this->config->getSearchProviderClassName($this->tripod->getStoreName());
     if (class_exists($provider)) {
         $this->configuredProvider = new $provider($this->tripod);
     } else {
         throw new \Tripod\Exceptions\SearchException("Did not recognise Search Provider, or could not find class: {$provider}");
     }
     $this->readPreference = $readPreference;
 }
Esempio n. 5
0
 /**
  * @param Driver $tripod
  * @param array $opts
  */
 public function __construct(Driver $tripod, $opts = array())
 {
     $this->tripod = $tripod;
     $this->storeName = $tripod->getStoreName();
     $this->podName = $tripod->getPodName();
     $this->stat = $tripod->getStat();
     $this->labeller = new Labeller();
     $opts = array_merge(array('defaultContext' => null, OP_ASYNC => array(OP_VIEWS => false, OP_TABLES => true, OP_SEARCH => true), 'stat' => null, 'readPreference' => ReadPreference::RP_PRIMARY_PREFERRED, 'retriesToGetLock' => 20), $opts);
     $this->readPreference = $opts['readPreference'];
     $this->config = $this->getConfigInstance();
     // default context
     $this->defaultContext = $opts['defaultContext'];
     //max retries to get lock
     $this->retriesToGetLock = $opts['retriesToGetLock'];
     // fill in and default any missing keys for $async array
     $async = $opts[OP_ASYNC];
     if (!array_key_exists(OP_VIEWS, $async)) {
         $async[OP_VIEWS] = false;
     }
     if (!array_key_exists(OP_TABLES, $async)) {
         $async[OP_TABLES] = true;
     }
     if (!array_key_exists(OP_SEARCH, $async)) {
         $async[OP_SEARCH] = true;
     }
     // if there is no es configured then remove OP_SEARCH from async (no point putting these onto the queue) TRI-19
     if ($this->config->getSearchDocumentSpecifications($this->storeName) == null) {
         unset($async[OP_SEARCH]);
     }
     // If a custom queue name was specified, store it
     if (array_key_exists(OP_QUEUE, $async)) {
         $this->queueName = $async[OP_QUEUE];
         unset($async[OP_QUEUE]);
     }
     $this->async = $async;
     if (isset($opts['statsConfig'])) {
         $this->statsConfig = $opts['statsConfig'];
     }
 }
 /**
  * This is a private method that performs exactly the same operation as Driver::lockSingleDocument, the reason this is duplicated here
  * is so that we can simulate the correct locking of documents as part of mocking a workflow that will lock a document correctly but not another
  * @param $s
  * @param $transaction_id
  * @param $contextAlias
  * @return array
  */
 public function lockSingleDocumentCallback($s, $transaction_id, $contextAlias)
 {
     $lCollection = \Tripod\Mongo\Config::getInstance()->getCollectionForLocks($this->tripod->getStoreName());
     $countEntriesInLocksCollection = $lCollection->count(array('_id' => array(_ID_RESOURCE => $this->labeller->uri_to_alias($s), _ID_CONTEXT => $contextAlias)));
     if ($countEntriesInLocksCollection > 0) {
         //Subject is already locked
         return false;
     } else {
         try {
             //Add a entry to locks collection for this subject, will throws exception if an entry already there
             $result = $lCollection->insertOne(array('_id' => array(_ID_RESOURCE => $this->labeller->uri_to_alias($s), _ID_CONTEXT => $contextAlias), _LOCKED_FOR_TRANS => $transaction_id, _LOCKED_FOR_TRANS_TS => \Tripod\Mongo\DateUtil::getMongoDate()), array("w" => 1));
             if (!$result->isAcknowledged()) {
                 throw new Exception("Failed to lock document with error message- " . $this->getLastDBError());
             }
         } catch (Exception $e) {
             //Subject is already locked or unable to lock
             $this->debugLog(MONGO_LOCK, array('description' => 'Driver::lockSingleDocument - failed with exception', 'transaction_id' => $transaction_id, 'subject' => $s, 'exception-message' => $e->getMessage()));
             return false;
         }
         //Let's get original document for processing.
         $document = $this->getTripodCollection($this->tripod)->findOne(array('_id' => array(_ID_RESOURCE => $this->labeller->uri_to_alias($s), _ID_CONTEXT => $contextAlias)));
         if (empty($document)) {
             //if document is not there, create it
             try {
                 $result = $this->getTripodCollection($this->tripod)->insertOne(array('_id' => array(_ID_RESOURCE => $this->labeller->uri_to_alias($s), _ID_CONTEXT => $contextAlias)), array("w" => 1));
                 if (!$result->isAcknowledged()) {
                     throw new Exception("Failed to create new document with error message- " . $this->getLastDBError());
                 }
                 $document = $this->getTripodCollection($this->tripod)->findOne(array('_id' => array(_ID_RESOURCE => $this->labeller->uri_to_alias($s), _ID_CONTEXT => $contextAlias)));
             } catch (\Exception $e) {
                 $this->errorLog(MONGO_LOCK, array('description' => 'Driver::lockSingleDocument - failed when creating new document', 'transaction_id' => $transaction_id, 'subject' => $s, 'exception-message' => $e->getMessage()));
                 return false;
             }
         }
         return $document;
     }
 }
 /**
  * @param \Tripod\Mongo\Driver $tripod
  * @param array $specs
  * @return int
  */
 protected function getCountForSearchSpecs(\Tripod\Mongo\Driver $tripod, $specs = array())
 {
     $count = 0;
     if (empty($specs)) {
         $specs = \Tripod\Mongo\Config::getInstance()->getSearchDocumentSpecifications($tripod->getStoreName(), null, true);
     }
     foreach ($specs as $spec) {
         $count += \Tripod\Mongo\Config::getInstance()->getCollectionForSearchDocument($tripod->getStoreName(), $spec)->count(array('_id.type' => $spec));
     }
     return $count;
 }
Esempio n. 8
0
 /**
  * @param \Tripod\Mongo\Driver $tripod
  * @return Collection
  */
 protected function getTripodCollection(\Tripod\Mongo\Driver $tripod)
 {
     $config = \Tripod\Mongo\Config::getInstance();
     $podName = $tripod->getPodName();
     $dataSource = $config->getDataSourceForPod($tripod->getStoreName(), $podName);
     return $config->getDatabase($tripod->getStoreName(), $dataSource)->selectCollection($tripod->getPodName());
 }
 /**
  * @param \Tripod\Mongo\Driver $tripod
  * @return SearchDocuments
  */
 protected function getSearchDocuments(\Tripod\Mongo\Driver $tripod)
 {
     return new \Tripod\Mongo\SearchDocuments($tripod->getStoreName(), $this->getTripodCollection($tripod), 'http://talisaspire.com/');
 }