/**
  * @param array $data
  * @param string|null $queueName
  */
 public function createJob(array $data, $queueName = null)
 {
     if (!$queueName) {
         $queueName = Config::getDiscoverQueueName();
     } elseif (strpos($queueName, \Tripod\Mongo\Config::getDiscoverQueueName()) === false) {
         $queueName = \Tripod\Mongo\Config::getDiscoverQueueName() . '::' . $queueName;
     }
     $this->submitJob($queueName, get_class($this), $data);
 }
 /**
  * Saving a change to an entity that appears in the impact index for view/table_rows/search docs of 3 other entities should result in
  * 4 items being placed on the queue, with the operations for each relevant to the configured operations based on the specifications
  * todo: new test in composite for one subject that impacts another
  */
 public function testSingleJobSubmittedToQueueForChangeToSeveralSubjects()
 {
     $tripod = $this->getMockBuilder('\\Tripod\\Mongo\\Driver')->setMethods(array('getDataUpdater', 'getComposite'))->setConstructorArgs(array('CBD_testing', 'tripod_php_testing', array('defaultContext' => 'http://talisaspire.com/', OP_ASYNC => array(OP_VIEWS => true, OP_TABLES => true, OP_SEARCH => true))))->getMock();
     $tripodUpdates = $this->getMockBuilder('\\Tripod\\Mongo\\Updates')->setMethods(array('processSyncOperations', 'getDiscoverImpactedSubjects'))->setConstructorArgs(array($tripod, array('defaultContext' => 'http://talisaspire.com/', OP_ASYNC => array(OP_VIEWS => true, OP_TABLES => true, OP_SEARCH => true))))->getMock();
     $discoverImpactedSubjects = $this->getMockBuilder('\\Tripod\\Mongo\\Jobs\\DiscoverImpactedSubjects')->setMethods(array('createJob'))->getMock();
     $tripod->expects($this->once())->method('getDataUpdater')->will($this->returnValue($tripodUpdates));
     $subjectsAndPredicatesOfChange = array("http://talisaspire.com/resources/doc1" => array('dct:date'), "http://talisaspire.com/resources/doc2" => array('dct:date'), "http://talisaspire.com/resources/doc3" => array('dct:date'));
     $tripod->expects($this->never())->method('getComposite');
     $data = array("changes" => $subjectsAndPredicatesOfChange, "operations" => array(OP_VIEWS, OP_TABLES, OP_SEARCH), "tripodConfig" => \Tripod\Mongo\Config::getConfig(), "storeName" => 'tripod_php_testing', "podName" => 'CBD_testing', "contextAlias" => 'http://talisaspire.com/', "statsConfig" => array());
     $tripodUpdates->expects($this->once())->method('getDiscoverImpactedSubjects')->will($this->returnValue($discoverImpactedSubjects));
     $discoverImpactedSubjects->expects($this->once())->method('createJob')->with($data, \Tripod\Mongo\Config::getDiscoverQueueName());
     $g1 = $tripod->describeResources(array("http://talisaspire.com/resources/doc1", "http://talisaspire.com/resources/doc2", "http://talisaspire.com/resources/doc3"));
     $g2 = $tripod->describeResources(array("http://talisaspire.com/resources/doc1", "http://talisaspire.com/resources/doc2", "http://talisaspire.com/resources/doc3"));
     $g2->add_literal_triple("http://talisaspire.com/resources/doc1", $g2->qname_to_uri("dct:date"), "01-01-1970");
     $g2->add_literal_triple("http://talisaspire.com/resources/doc2", $g2->qname_to_uri("dct:date"), "01-01-1970");
     $g2->add_literal_triple("http://talisaspire.com/resources/doc3", $g2->qname_to_uri("dct:date"), "01-01-1970");
     $tripod->saveChanges($g1, $g2);
 }
 public function testDiscoverImpactedSubjectsForDefaultOperationsSetting()
 {
     $uri_1 = "http://example.com/1";
     $uri_2 = "http://example.com/2";
     $oG = new \Tripod\Mongo\MongoGraph();
     $oG->add_resource_triple($uri_1, $oG->qname_to_uri("rdf:type"), $oG->qname_to_uri("acorn:Resource"));
     $oG->add_resource_triple($uri_2, $oG->qname_to_uri("rdf:type"), $oG->qname_to_uri("acorn:Resource"));
     // a delete and an update
     $nG = new \Tripod\Mongo\MongoGraph();
     $nG->add_graph($oG);
     $nG->add_literal_triple($uri_1, $nG->qname_to_uri("searchterms:title"), "wibble");
     $nG->remove_resource_triple($uri_2, $oG->qname_to_uri("rdf:type"), "http://foo/bar#Class2");
     /** @var \Tripod\Mongo\Driver|PHPUnit_Framework_MockObject_MockObject $mockTripod */
     $mockTripod = $this->getMock('\\Tripod\\Mongo\\Driver', array('getComposite', 'getDataUpdater'), array('CBD_testing', 'tripod_php_testing', array('defaultContext' => 'http://talisaspire.com/')));
     $mockTripodUpdates = $this->getMock('\\Tripod\\Mongo\\Updates', array('storeChanges', 'getDiscoverImpactedSubjects'), array($mockTripod, array(OP_ASYNC => array(OP_TABLES => true, OP_VIEWS => false, OP_SEARCH => true))));
     $mockViews = $this->getMock('\\Tripod\\Mongo\\Composites\\Views', array('getImpactedSubjects', 'update'), array('tripod_php_testing', \Tripod\Mongo\Config::getInstance()->getCollectionForCBD('tripod_php_testing', 'CBD_testing'), 'http://talisaspire.com/'));
     $mockDiscoverImpactedSubjects = $this->getMockBuilder('\\Tripod\\Mongo\\Jobs\\DiscoverImpactedSubjects')->setMethods(array('createJob'))->getMock();
     $impactedViewSubjects = array($this->getMockBuilder('\\Tripod\\Mongo\\ImpactedSubject')->setConstructorArgs(array(array(_ID_RESOURCE => $uri_1, _ID_CONTEXT => 'http://talisaspire.com'), OP_VIEWS, 'tripod_php_testing', 'CBD_testing'))->setMethods(array('update'))->getMock(), $this->getMockBuilder('\\Tripod\\Mongo\\ImpactedSubject')->setConstructorArgs(array(array(_ID_RESOURCE => $uri_2, _ID_CONTEXT => 'http://talisaspire.com'), OP_VIEWS, 'tripod_php_testing', 'CBD_testing'))->setMethods(array('update'))->getMock());
     $labeller = new \Tripod\Mongo\Labeller();
     $subjectsAndPredicatesOfChange = array($labeller->uri_to_alias($uri_1) => array('searchterms:title'), $labeller->uri_to_alias($uri_2) => array('rdf:type'));
     $jobData = array('changes' => $subjectsAndPredicatesOfChange, 'operations' => array(OP_TABLES, OP_SEARCH), 'tripodConfig' => \Tripod\Mongo\Config::getConfig(), 'storeName' => 'tripod_php_testing', 'podName' => 'CBD_testing', 'contextAlias' => 'http://talisaspire.com/', 'statsConfig' => array());
     // getComposite() should only be called if there are synchronous operations
     $mockTripod->expects($this->once())->method('getComposite')->with(OP_VIEWS)->will($this->returnValue($mockViews));
     $mockTripodUpdates->expects($this->once())->method('getDiscoverImpactedSubjects')->will($this->returnValue($mockDiscoverImpactedSubjects));
     $mockTripodUpdates->expects($this->once())->method('storeChanges')->will($this->returnValue(array("subjectsAndPredicatesOfChange" => $subjectsAndPredicatesOfChange, "transaction_id" => "t1234")));
     $mockTripod->expects($this->once())->method('getDataUpdater')->will($this->returnValue($mockTripodUpdates));
     $mockViews->expects($this->once())->method('getImpactedSubjects')->will($this->returnValue($impactedViewSubjects));
     $impactedViewSubjects[0]->expects($this->once())->method('update');
     $impactedViewSubjects[1]->expects($this->once())->method('update');
     // This shouldn't be called because ImpactedSubject->update has been mocked and isn't doing anything
     $mockViews->expects($this->never())->method('update');
     $mockDiscoverImpactedSubjects->expects($this->once())->method('createJob')->with($jobData, \Tripod\Mongo\Config::getDiscoverQueueName());
     $mockTripod->saveChanges($oG, $nG, "http://talisaspire.com/");
 }
 public function testCreateJobSpecifyQueue()
 {
     $labeller = new \Tripod\Mongo\Labeller();
     $subjectsAndPredicatesOfChange = array($labeller->uri_to_alias('http://example.com/1') => array('rdf:type', 'spec:name'), $labeller->uri_to_alias('http://example.com/2') => array('rdf:type', 'dct:title', 'dct:subject'));
     $jobData = array('changes' => $subjectsAndPredicatesOfChange, 'operations' => array(OP_SEARCH), 'tripodConfig' => \Tripod\Mongo\Config::getConfig(), 'storeName' => 'tripod_php_testing', 'podName' => 'CBD_testing', 'contextAlias' => 'http://talisaspire.com/');
     $queueName = \Tripod\Mongo\Config::getDiscoverQueueName() . '::TRIPOD_TESTING_QUEUE_' . uniqid();
     /** @var \Tripod\Mongo\Jobs\DiscoverImpactedSubjects|PHPUnit_Framework_MockObject_MockObject $discoverImpactedSubjects */
     $discoverImpactedSubjects = $this->getMockBuilder('\\Tripod\\Mongo\\Jobs\\DiscoverImpactedSubjects')->setMethods(array('submitJob'))->setMockClassName('MockDiscoverImpactedSubjects')->getMock();
     $discoverImpactedSubjects->expects($this->once())->method('submitJob')->with($queueName, 'MockDiscoverImpactedSubjects', $jobData);
     $discoverImpactedSubjects->createJob($jobData, $queueName);
 }
Example #5
0
 /**
  * Adds the operations to the queue to be performed asynchronously
  * @param array $subjectsAndPredicatesOfChange
  * @param string $contextAlias
  */
 protected function queueASyncOperations(array $subjectsAndPredicatesOfChange, $contextAlias)
 {
     $operations = $this->getAsyncOperations();
     if (!empty($operations)) {
         $data = array("changes" => $subjectsAndPredicatesOfChange, "operations" => $operations, "tripodConfig" => Config::getConfig(), "storeName" => $this->storeName, "podName" => $this->podName, "contextAlias" => $contextAlias, "statsConfig" => $this->getStatsConfig());
         if (isset($this->queueName)) {
             $data[OP_QUEUE] = $this->queueName;
             $queueName = $this->queueName;
         } else {
             $queueName = Config::getDiscoverQueueName();
         }
         $this->getDiscoverImpactedSubjects()->createJob($data, $queueName);
     }
 }