/** * Constructor */ public function __construct() { $config = Config::getInstance(); $this->config = $config->getTransactionLogConfig(); $this->transaction_db = $config->getTransactionLogDatabase(); $this->transaction_collection = $this->transaction_db->selectCollection($this->config['collection']); }
public function testToNQuads() { $g = new \Tripod\Mongo\MongoGraph(); $g->add_literal_triple("http://example.com/1", $g->qname_to_uri("dct:title"), "some literal title"); $g->add_resource_triple("http://example.com/1", $g->qname_to_uri("dct:source"), "http://www.google.com"); $expected = "<http://example.com/1> <http://purl.org/dc/terms/title> \"some literal title\" <http://talisaspire.com/> .\n<http://example.com/1> <http://purl.org/dc/terms/source> <http://www.google.com> <http://talisaspire.com/> .\n"; $this->assertEquals($expected, $g->to_nquads(\Tripod\Mongo\Config::getInstance()->getDefaultContextAlias())); }
protected function setUp() { parent::setUp(); $this->tripod = new \Tripod\Mongo\Driver("CBD_testing", "tripod_php_testing", array("async" => array(OP_VIEWS => true, OP_TABLES => true, OP_SEARCH => false))); foreach (\Tripod\Mongo\Config::getInstance()->getCollectionsForSearch($this->tripod->getStoreName()) as $collection) { $collection->drop(); } $this->loadResourceDataViaTripod(); $this->loadBaseSearchDataViaTripod(); }
/** * Note: Current version of this test tried to create 1000 objects within 6000ms which is reasonable at this time. * Any change to this class if make it a more a big number it should be validated and tested to ensure performance impact. * * Create some instances of Config to see what amount of time is taken in creating instance and processing in constructor. */ public function testCreateMongoTripodConfigObject() { $testStartTime = microtime(); //Let's try to create 1000 objects to see how much time they take. for ($i = 0; $i < self::BENCHMARK_OBJECT_CREATE_ITERATIONS; $i++) { \Tripod\Mongo\Config::setConfig($this->config); $instance = \Tripod\Mongo\Config::getInstance(); } $testEndTime = microtime(); $this->assertLessThan(self::BENCHMARK_OBJECT_CREATE_TIME, $this->getTimeDifference($testStartTime, $testEndTime), "It should always take less than " . self::BENCHMARK_OBJECT_CREATE_TIME . "ms to create " . self::BENCHMARK_OBJECT_CREATE_ITERATIONS . " objects of Config class"); }
public function testGetMongoDateWithParam() { $config = \Tripod\Mongo\Config::getInstance(); $updatedAt = (new \Tripod\Mongo\DateUtil())->getMongoDate(); $_id = array('r' => 'http://talisaspire.com/resources/testEtag' . microtime(false), 'c' => 'http://talisaspire.com/'); $doc = array('_id' => $_id, 'dct:title' => array('l' => 'etag'), '_version' => 0, '_cts' => $updatedAt, '_uts' => $updatedAt); $config->getCollectionForCBD('tripod_php_testing', 'CBD_testing')->insertOne($doc, array("w" => 1)); $time = floor(microtime(true) * 1000); $date = \Tripod\Mongo\DateUtil::getMongoDate($time); $this->assertInstanceOf('\\MongoDB\\BSON\\UTCDateTime', $date); $this->assertEquals(13, strlen($date->__toString())); $this->assertEquals($time, $date->__toString()); }
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 string|null $id * @param string|null $specId * @param string|null $storeName * @param \Tripod\iTripodStat|null $stat * @param string|null $queue */ function generateSearchDocuments($id, $specId, $storeName, $stat = null, $queue = null) { $spec = \Tripod\Mongo\Config::getInstance()->getSearchDocumentSpecification($storeName, $specId); if (array_key_exists("from", $spec)) { \Tripod\Mongo\Config::getInstance()->setMongoCursorTimeout(-1); print "Generating {$specId}"; $tripod = new \Tripod\Mongo\Driver($spec['from'], $storeName, array('stat' => $stat)); $search = $tripod->getSearchIndexer(); if ($id) { print " for {$id}....\n"; $search->generateSearchDocuments($specId, $id, null, $queue); } else { print " for all tables....\n"; $search->generateSearchDocuments($specId, null, null, $queue); } } }
/** * @param string|null $id * @param string|null $tableId * @param string|null $storeName * @param \Tripod\ITripodStat|null $stat * @param string|null $queue */ function generateTables($id, $tableId, $storeName, $stat = null, $queue = null) { $tableSpec = \Tripod\Mongo\Config::getInstance()->getTableSpecification($storeName, $tableId); if (array_key_exists("from", $tableSpec)) { \Tripod\Mongo\Config::getInstance()->setMongoCursorTimeout(-1); print "Generating {$tableId}"; $tripod = new \Tripod\Mongo\Driver($tableSpec['from'], $storeName, array('stat' => $stat)); $tTables = $tripod->getTripodTables(); if ($id) { print " for {$id}....\n"; $tTables->generateTableRows($tableId, $id); } else { print " for all tables....\n"; $tTables->generateTableRows($tableId, null, null, $queue); } } }
/** * @param string|null $id * @param string|null $viewId * @param string $storeName * @param \Tripod\ITripodStat|null $stat * @param string $queue */ function generateViews($id, $viewId, $storeName, $stat, $queue) { $viewSpec = \Tripod\Mongo\Config::getInstance()->getViewSpecification($storeName, $viewId); if (array_key_exists("from", $viewSpec)) { \Tripod\Mongo\Config::getInstance()->setMongoCursorTimeout(-1); print "Generating {$viewId}"; $tripod = new \Tripod\Mongo\Driver($viewSpec['from'], $storeName, array('stat' => $stat)); $views = $tripod->getTripodViews(); if ($id) { print " for {$id}....\n"; $views->generateView($viewId, $id, null, $queue); } else { print " for all views....\n"; $views->generateView($viewId, null, null, $queue); } } }
public function testSerializerWithMultipleSubjects() { $g = new MongoGraph(); $docs = json_decode(file_get_contents(dirname(__FILE__) . '/data/resources.json'), true); foreach ($docs as $d) { $g->add_tripod_array($d); } $expected = "<http://life.ac.uk/resources/BFBC6A06-A8B0-DED8-53AA-8E80DB44CC53> <http://purl.org/dc/terms/title> \"Title of resource 2\" <http://talisaspire.com/> .\n<http://life.ac.uk/resources/836E7CAD-63D2-63A0-B1CB-AA6A7E54A5C9> <http://purl.org/dc/terms/title> \"Title of resource 1\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA> <http://purl.org/dc/terms/isVersionOf> <http://talisaspire.com/works/4d101f63c10a6> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA> <http://purl.org/dc/terms/source> <http://life.ac.uk/resources/BFBC6A06-A8B0-DED8-53AA-8E80DB44CC53> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA> <http://purl.org/dc/terms/source> <http://life.ac.uk/resources/836E7CAD-63D2-63A0-B1CB-AA6A7E54A5C9> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA> <http://purl.org/dc/terms/subject> <http://talisaspire.com/disciplines/physics> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA> <http://purl.org/ontology/bibo/isbn13> \"9780393929690\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA> <http://talisaspire.com/schema#bookmarkReferences> <http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA/bookmarks> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA> <http://talisaspire.com/schema#foo> \"wibble\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA> <http://talisaspire.com/schema#jacsUri> <http://jacs3.dataincubator.org/f300> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA> <http://talisaspire.com/schema#jacsUri> <http://jacs3.dataincubator.org/f340> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA> <http://talisaspire.com/schema#listReferences> <http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA/lists> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA> <http://talisaspire.com/schema#openLibraryUri> <http://openlibrary.org/books/OL10157958M> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA> <http://talisaspire.com/schema#preferredMetadata> <http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA/metadata> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA> <http://talisaspire.com/searchTerms/schema#author> \"Ohanian\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA> <http://talisaspire.com/searchTerms/schema#discipline> \"physics\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA> <http://talisaspire.com/searchTerms/schema#isbn> \"9780393929690\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA> <http://talisaspire.com/searchTerms/schema#openLibrarySubject> \"Engineering: general\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA> <http://talisaspire.com/searchTerms/schema#openLibrarySubject> \"PHYSICS\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA> <http://talisaspire.com/searchTerms/schema#openLibrarySubject> \"Science\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA> <http://talisaspire.com/searchTerms/schema#title> \"Physics 3rd Edition\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA> <http://talisaspire.com/searchTerms/schema#title> \"Physics for Engineers and Scientists\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA> <http://talisaspire.com/searchTerms/schema#topic> \"engineering: general\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA> <http://talisaspire.com/searchTerms/schema#topic> \"physics\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA> <http://talisaspire.com/searchTerms/schema#topic> \"science\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA> <http://talisaspire.com/searchTerms/schema#usedAt> \"0071\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://purl.org/ontology/bibo/Book> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://talisaspire.com/schema#Resource> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA> <http://www.w3.org/2002/07/owl#sameAs> <http://talisaspire.com/isbn/9780393929690> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA-2> <http://purl.org/dc/terms/isVersionOf> <http://talisaspire.com/works/4d101f63c10a6> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA-2> <http://purl.org/dc/terms/source> <http://life.ac.uk/resources/836E7CAD-63D2-63A0-B1CB-AA6A7E54A5C9> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA-2> <http://purl.org/dc/terms/source> <http://life.ac.uk/resources/BFBC6A06-A8B0-DED8-53AA-8E80DB44CC53> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA-2> <http://purl.org/dc/terms/subject> <http://talisaspire.com/disciplines/physics> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA-2> <http://purl.org/ontology/bibo/isbn13> \"9780393929691\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA-2> <http://talisaspire.com/schema#bookmarkReferences> <http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA/bookmarks> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA-2> <http://talisaspire.com/schema#foo> \"wibble\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA-2> <http://talisaspire.com/schema#jacsUri> <http://jacs3.dataincubator.org/f300> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA-2> <http://talisaspire.com/schema#jacsUri> <http://jacs3.dataincubator.org/f340> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA-2> <http://talisaspire.com/schema#listReferences> <http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA/lists> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA-2> <http://talisaspire.com/schema#openLibraryUri> <http://openlibrary.org/books/OL10157958M> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA-2> <http://talisaspire.com/schema#preferredMetadata> <http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA/metadata> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA-2> <http://talisaspire.com/searchTerms/schema#author> \"Ohanian\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA-2> <http://talisaspire.com/searchTerms/schema#discipline> \"physics\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA-2> <http://talisaspire.com/searchTerms/schema#isbn> \"9780393929690\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA-2> <http://talisaspire.com/searchTerms/schema#openLibrarySubject> \"Engineering: general\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA-2> <http://talisaspire.com/searchTerms/schema#openLibrarySubject> \"PHYSICS\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA-2> <http://talisaspire.com/searchTerms/schema#openLibrarySubject> \"Science\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA-2> <http://talisaspire.com/searchTerms/schema#title> \"Physics 3rd Edition\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA-2> <http://talisaspire.com/searchTerms/schema#title> \"Physics for Engineers and Scientists\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA-2> <http://talisaspire.com/searchTerms/schema#topic> \"engineering: general\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA-2> <http://talisaspire.com/searchTerms/schema#topic> \"physics\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA-2> <http://talisaspire.com/searchTerms/schema#topic> \"science\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA-2> <http://talisaspire.com/searchTerms/schema#usedAt> \"0071\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA-2> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://purl.org/ontology/bibo/Book> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA-2> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://talisaspire.com/schema#Resource> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA-2> <http://www.w3.org/2002/07/owl#sameAs> <http://talisaspire.com/isbn/9780393929690> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/indexKeyTooLarge> <http://purl.org/dc/terms/isVersionOf> <http://talisaspire.com/works/4d101f63c10a6> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/indexKeyTooLarge> <http://purl.org/dc/terms/source> <http://life.ac.uk/resources/836E7CAD-63D2-63A0-B1CB-AA6A7E54A5C9> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/indexKeyTooLarge> <http://purl.org/dc/terms/source> <http://life.ac.uk/resources/BFBC6A06-A8B0-DED8-53AA-8E80DB44CC53> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/indexKeyTooLarge> <http://purl.org/dc/terms/subject> <http://talisaspire.com/disciplines/physics> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/indexKeyTooLarge> <http://purl.org/ontology/bibo/isbn13> \"1234567890123\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/indexKeyTooLarge> <http://talisaspire.com/schema#bookmarkReferences> <http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA/bookmarks> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/indexKeyTooLarge> <http://talisaspire.com/schema#foo> \"wibble\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/indexKeyTooLarge> <http://talisaspire.com/schema#jacsUri> <http://jacs3.dataincubator.org/f300> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/indexKeyTooLarge> <http://talisaspire.com/schema#jacsUri> <http://jacs3.dataincubator.org/f340> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/indexKeyTooLarge> <http://talisaspire.com/schema#listReferences> <http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA/lists> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/indexKeyTooLarge> <http://talisaspire.com/schema#openLibraryUri> <http://openlibrary.org/books/OL10157958M> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/indexKeyTooLarge> <http://talisaspire.com/schema#preferredMetadata> <http://talisaspire.com/resources/3SplCtWGPqEyXcDiyhHQpA/metadata> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/indexKeyTooLarge> <http://talisaspire.com/searchTerms/schema#author> \"Ohanian\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/indexKeyTooLarge> <http://talisaspire.com/searchTerms/schema#discipline> \"physics\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/indexKeyTooLarge> <http://talisaspire.com/searchTerms/schema#isbn> \"1234567890\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/indexKeyTooLarge> <http://talisaspire.com/searchTerms/schema#openLibrarySubject> \"Engineering: general\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/indexKeyTooLarge> <http://talisaspire.com/searchTerms/schema#openLibrarySubject> \"PHYSICS\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/indexKeyTooLarge> <http://talisaspire.com/searchTerms/schema#openLibrarySubject> \"Science\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/indexKeyTooLarge> <http://talisaspire.com/searchTerms/schema#title> \"Mahommah Gardo Baquaqua. Biography of Mahommah G. Baquaqua, a Native of Zoogoo, in the Interior of Africa. (A Convert to Christianity,) With a Description of That Part of the World; Including the Manners and Customs of the Inhabitants, Their Religious Notions, Form of Government, Laws, Appearance of the Country, Buildings, Agriculture, Manufactures, Shepherds and Herdsmen, Domestic Animals, Marriage Ceremonials, Funeral Services, Styles of Dress, Trade and Commerce, Modes of Warfare, System of Slavery, &c., &c. Mahommah's Early Life, His Education, His Capture and Slavery in Western Africa and Brazil, His Escape to the United States, from Thence to Hayti, (the City of Port Au Prince,) His Reception by the Baptist Missionary There, The Rev. W. L. Judd; His Conversion to Christianity, Baptism, and Return to This Country, His Views, Objects and Aim. Written and Revised from His Own Words, by Samuel Moore, Esq., Late Publisher of the "North of England Shipping Gazette," Author of Several Popular Works, and Editor of Sundry Reform Papers.\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/indexKeyTooLarge> <http://talisaspire.com/searchTerms/schema#topic> \"engineering: general\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/indexKeyTooLarge> <http://talisaspire.com/searchTerms/schema#topic> \"physics\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/indexKeyTooLarge> <http://talisaspire.com/searchTerms/schema#topic> \"science\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/indexKeyTooLarge> <http://talisaspire.com/searchTerms/schema#usedAt> \"0071\" <http://talisaspire.com/> .\n<http://talisaspire.com/resources/indexKeyTooLarge> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://purl.org/ontology/bibo/Book> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/indexKeyTooLarge> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://talisaspire.com/schema#ResourceForTruncating> <http://talisaspire.com/> .\n<http://talisaspire.com/resources/indexKeyTooLarge> <http://www.w3.org/2002/07/owl#sameAs> <http://talisaspire.com/isbn/9780393929690> <http://talisaspire.com/> .\n<http://jacs3.dataincubator.org/f300> <http://purl.org/dc/terms/title> \"First title\" <http://talisaspire.com/> .\n<http://jacs3.dataincubator.org/f300> <http://purl.org/dc/terms/title> \"Second title\" <http://talisaspire.com/> .\n<http://jacs3.dataincubator.org/f340> <http://purl.org/dc/terms/title> \"First title\" <http://talisaspire.com/> .\n<http://talisaspire.com/works/4d101f63c10a6> <http://purl.org/dc/terms/subject> <http://talisaspire.com/disciplines/physics> <http://talisaspire.com/> .\n<http://talisaspire.com/works/4d101f63c10a6> <http://purl.org/ontology/bibo/isbn13> \"9780393929691\" <http://talisaspire.com/> .\n<http://talisaspire.com/works/4d101f63c10a6> <http://purl.org/ontology/bibo/isbn13> \"9780393929691-2\" <http://talisaspire.com/> .\n<http://talisaspire.com/works/4d101f63c10a6> <http://talisaspire.com/searchTerms/schema#discipline> \"physics\" <http://talisaspire.com/> .\n<http://talisaspire.com/works/4d101f63c10a6> <http://talisaspire.com/schema#seeAlso> <http://talisaspire.com/works/4d101f63c10a6-2> <http://talisaspire.com/> .\n<http://talisaspire.com/works/4d101f63c10a6> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://purl.org/ontology/bibo/Book> <http://talisaspire.com/> .\n<http://talisaspire.com/works/4d101f63c10a6> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://talisaspire.com/schema#Work> <http://talisaspire.com/> .\n<http://talisaspire.com/works/4d101f63c10a6-2> <http://purl.org/dc/terms/subject> <http://talisaspire.com/disciplines/physics> <http://talisaspire.com/> .\n<http://talisaspire.com/works/4d101f63c10a6-2> <http://purl.org/ontology/bibo/isbn13> \"9780393929691\" <http://talisaspire.com/> .\n<http://talisaspire.com/works/4d101f63c10a6-2> <http://talisaspire.com/searchTerms/schema#discipline> \"physics\" <http://talisaspire.com/> .\n<http://talisaspire.com/works/4d101f63c10a6-2> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://purl.org/ontology/bibo/Book> <http://talisaspire.com/> .\n<http://talisaspire.com/works/4d101f63c10a6-2> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://talisaspire.com/schema#Work> <http://talisaspire.com/> .\n<http://talisaspire.com/works/lockedDoc> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://purl.org/ontology/bibo/Book> <http://talisaspire.com/> .\n<http://talisaspire.com/works/lockedDoc> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://talisaspire.com/schema#Work> <http://talisaspire.com/> .\n<http://basedata.com/b/1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://talisaspire.com/schema#Work> <http://talisaspire.com/> .\n<http://basedata.com/b/1> <http://talisaspire.com/schema#seeAlso> <http://talisaspire.com/works/4d101f63c10a6-2> <http://talisaspire.com/> .\n<http://basedata.com/b/2> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://talisaspire.com/schema#Work> <http://talisaspire.com/> .\n<http://basedata.com/b/2> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://talisaspire.com/schema#Work2> <http://talisaspire.com/> .\n<http://basedata.com/b/2> <http://talisaspire.com/schema#seeAlso> <http://basedata.com/b/1> <http://talisaspire.com/> .\n<tenantUsers:s2123> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://rdfs.org/sioc/spec/User> <http://talisaspire.com/> .\n<tenantUsers:s2123> <http://xmlns.com/foaf/0.1/firstName> \"Harry\" <http://talisaspire.com/> .\n<tenantUsers:s2123> <http://xmlns.com/foaf/0.1/surname> \"Potter\" <http://talisaspire.com/> .\n<tenantUsers:s2123> <http://lists.talis.com/schema/temp#last_login> \"2014-03-25T15:07:12+00:00\" <http://talisaspire.com/> .\n<tenantUsers:s2123> <http://lists.talis.com/schema/temp#last_login_invalid> \"invalid\" <http://talisaspire.com/> .\n<http://basedata.com/b/foo1234> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://purl.org/ontology/bibo/Document> <http://talisaspire.com/> .\n<http://basedata.com/b/foo1234> <http://purl.org/dc/terms/creator> <http://schemas.talis.com/2005/user/schema#10101> <http://talisaspire.com/> .\n<http://basedata.com/b/foo1234> <http://purl.org/dc/terms/title> \"A document title\" <http://talisaspire.com/> .\n<http://basedata.com/b/foo1234> <http://purl.org/dc/terms/isVersionOf> <http://talisaspire.com/works/4d101f63c10a6> <http://talisaspire.com/> .\n<http://schemas.talis.com/2005/user/schema#10101> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> <http://talisaspire.com/> .\n<http://schemas.talis.com/2005/user/schema#10101> <http://xmlns.com/foaf/0.1/name> \"A. Person\" <http://talisaspire.com/> .\n<http://schemas.talis.com/2005/user/schema#10101> <http://xmlns.com/foaf/0.1/knows> <http://schemas.talis.com/2005/user/schema#10102> <http://talisaspire.com/> .\n<http://schemas.talis.com/2005/user/schema#10102> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> <http://talisaspire.com/> .\n<http://schemas.talis.com/2005/user/schema#10102> <http://xmlns.com/foaf/0.1/name> \"Anne O'ther\" <http://talisaspire.com/> .\n<http://basedata.com/b/bar1234> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://purl.org/ontology/bibo/Document> <http://talisaspire.com/> .\n<http://basedata.com/b/bar1234> <http://purl.org/dc/terms/creator> <http://schemas.talis.com/2005/user/schema#10103> <http://talisaspire.com/> .\n<http://basedata.com/b/bar1234> <http://purl.org/dc/terms/contributor> <http://schemas.talis.com/2005/user/schema#10101> <http://talisaspire.com/> .\n<http://basedata.com/b/bar1234> <http://purl.org/dc/terms/contributor> <http://schemas.talis.com/2005/user/schema#10102> <http://talisaspire.com/> .\n<http://basedata.com/b/bar1234> <http://purl.org/dc/terms/title> \"Another document title\" <http://talisaspire.com/> .\n<http://basedata.com/b/docWithEmptySeq123> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://basedata.com/b/DocWithSequence> <http://talisaspire.com/> .\n<http://basedata.com/b/docWithEmptySeq123> <http://basedata.com/b/hasSequence> <http://basedata.com/b/sequence123> <http://talisaspire.com/> .\n<http://basedata.com/b/docWithEmptySeq123> <http://purl.org/dc/terms/creator> <http://schemas.talis.com/2005/user/schema#xyz> <http://talisaspire.com/> .\n<http://basedata.com/b/docWithEmptySeq123> <http://purl.org/dc/terms/title> \"Doc with sequence\" <http://talisaspire.com/> ."; $serializer = new NQuadSerializer(); $actual = $serializer->getSerializedIndex($g->_index, \Tripod\Mongo\Config::getInstance()->getDefaultContextAlias()); // This test initially asserted that $expected was equal to $actual // $this->assertEquals($expected, $actual); // However, each time test data was added - it would also need to be added to expected above. // Rather than increasing the size of $expected further when adding new test data // this test now asserts that each line in $expected has been serialised correctly, without failing // due to new test data. foreach (preg_split("/((\r?\n)|(\r\n?))/", $expected) as $expectedLine) { $this->assertTrue(strpos($actual, rtrim($expectedLine)) !== false, "Failed checking for line: " . rtrim($expectedLine)); } }
public function testApplyTableOperation() { $this->setArgs(); $applyOperation = $this->getMockBuilder('\\Tripod\\Mongo\\Jobs\\ApplyOperation')->setMethods(array('createImpactedSubject', 'getStat'))->getMock(); $statMock = $this->getMockStat($this->args['statsConfig']['config']['host'], $this->args['statsConfig']['config']['port'], $this->args['statsConfig']['config']['prefix'], array('timer', 'increment')); $impactedSubject = new \Tripod\Mongo\ImpactedSubject(array(_ID_RESOURCE => 'http://example.com/resources/foo', _ID_CONTEXT => 'http://talisaspire.com/'), OP_TABLES, 'tripod_php_testing', 'CBD_testing', array('t_resource')); $this->args['subjects'] = array($impactedSubject->toArray()); $applyOperation->args = $this->args; $applyOperation->job->payload['id'] = uniqid(); $subject = $this->getMockBuilder('\\Tripod\\Mongo\\ImpactedSubject')->setMethods(array('getTripod'))->setConstructorArgs(array(array(_ID_RESOURCE => 'http://example.com/resources/foo', _ID_CONTEXT => 'http://talisaspire.com'), OP_TABLES, 'tripod_php_testing', 'CBD_testing'))->getMock(); $tripod = $this->getMockBuilder('\\Tripod\\Mongo\\Driver')->setMethods(array('getComposite'))->setConstructorArgs(array('CBD_testing', 'tripod_php_testing'))->getMock(); $tables = $this->getMockBuilder('\\Tripod\\Mongo\\Composites\\Tables')->setMethods(array('update'))->setConstructorArgs(array('tripod_php_testing', \Tripod\Mongo\Config::getInstance()->getCollectionForCBD('tripod_php_testing', 'CBD_testing'), 'http://talisapire.com/'))->getMock(); $applyOperation->expects($this->once())->method('createImpactedSubject')->will($this->returnValue($subject)); $applyOperation->expects($this->exactly(3))->method('getStat')->will($this->returnValue($statMock)); $statMock->expects($this->once())->method('increment')->with(MONGO_QUEUE_APPLY_OPERATION_JOB . '.' . SUBJECT_COUNT, 1); $statMock->expects($this->exactly(2))->method('timer')->withConsecutive(array(MONGO_QUEUE_APPLY_OPERATION . '.' . OP_TABLES, $this->anything()), array(MONGO_QUEUE_APPLY_OPERATION_SUCCESS, $this->anything())); $subject->expects($this->once())->method('getTripod')->will($this->returnValue($tripod)); $tripod->expects($this->once())->method('getComposite')->with(OP_TABLES)->will($this->returnValue($tables)); $tables->expects($this->once())->method('update')->with($subject); $applyOperation->perform(); }
} array_shift($argv); $config = json_decode(file_get_contents($argv[0]), true); \Tripod\Mongo\Config::setConfig($config); $currentSubject = ""; $triples = array(); $docs = array(); $errors = array(); // array of subjects that failed to insert, even after retry... $tu = new \Tripod\Mongo\TriplesUtil(); while (($line = fgets(STDIN)) !== false) { $line = rtrim($line); $parts = preg_split("/\\s/", $line); $subject = trim($parts[0], '><'); if (empty($currentSubject)) { $currentSubject = $subject; } if ($currentSubject != $subject) { print json_encode($tu->getTArrayAbout($currentSubject, $triples, \Tripod\Mongo\Config::getInstance()->getDefaultContextAlias())) . "\n"; $currentSubject = $subject; // reset current subject to next subject $triples = array(); // reset triples } $triples[] = $line; } // last doc print json_encode($tu->getTArrayAbout($currentSubject, $triples, \Tripod\Mongo\Config::getInstance()->getDefaultContextAlias())) . "\n"; ?>
public function testArithmeticSpecValidationInvalidNestedOperator() { $newConfig = \Tripod\Mongo\Config::getConfig(); \Tripod\Mongo\Config::setValidationLevel(\Tripod\Mongo\Config::VALIDATE_MAX); $arithmeticFunction = array('fieldName' => 'fooBar', 'value' => array('arithmetic' => array(array(101, '#', 100), '*', 3))); $newConfig['stores']['tripod_php_testing']['table_specifications'][0]['computed_fields'] = array($arithmeticFunction); \Tripod\Mongo\Config::setConfig($newConfig); $this->setExpectedException('\\Tripod\\Exceptions\\ConfigException', "Invalid arithmetic operator '#' in computed arithmetic spec"); \Tripod\Mongo\Config::getInstance(); }
/** START: getETag tests */ public function testEtagIsMicrotimeFormat() { $config = \Tripod\Mongo\Config::getInstance(); $updatedAt = \Tripod\Mongo\DateUtil::getMongoDate(); $_id = array('r' => 'http://talisaspire.com/resources/testEtag', 'c' => 'http://talisaspire.com/'); $doc = array('_id' => $_id, 'dct:title' => array('l' => 'etag'), '_version' => 0, '_cts' => $updatedAt, '_uts' => $updatedAt); $config->getCollectionForCBD('tripod_php_testing', 'CBD_testing')->insertOne($doc, array("w" => 1)); $tripod = new \Tripod\Mongo\Driver('CBD_testing', 'tripod_php_testing', array('defaultContext' => 'http://talisaspire.com/')); $this->assertRegExp('/^0.[0-9]{8} [0-9]{10}/', $tripod->getETag($_id['r'])); }
/** * 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; } }
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)))); }
require_once dirname(__FILE__) . '/common.inc.php'; $options = getopt("c:h", array("config:", "help")); function showUsage() { $help = <<<END validateConfig.php Usage: php validateConfig.php -c/--config path/to/tripod-config.json [options] Options: -h --help This help -c --config path to Config configuration (required) END; echo $help; } if (empty($options) || isset($options['h']) || isset($options['help']) || !isset($options['c']) && !isset($options['config'])) { showUsage(); exit; } $configLocation = isset($options['c']) ? $options['c'] : $options['config']; require_once dirname(dirname(dirname(__FILE__))) . '/src/tripod.inc.php'; \Tripod\Mongo\Config::setValidationLevel(\Tripod\Mongo\Config::VALIDATE_MAX); \Tripod\Mongo\Config::setConfig(json_decode(file_get_contents($configLocation), true)); try { \Tripod\Mongo\Config::getInstance(); echo "\nConfig OK\n"; } catch (\Tripod\Exceptions\ConfigException $e) { echo "\nError: " . $e->getMessage() . "\n"; }
/** * Run the DiscoverImpactedSubjects job * @throws \Exception */ public function perform() { try { $this->debugLog("[JOBID " . $this->job->payload['id'] . "] DiscoverImpactedSubjects::perform() start"); $timer = new \Tripod\Timer(); $timer->start(); $this->validateArgs(); // set the config to what is received \Tripod\Mongo\Config::setConfig($this->args[self::TRIPOD_CONFIG_KEY]); $statsConfig = array(); if (isset($this->args['statsConfig'])) { $statsConfig['statsConfig'] = $this->args['statsConfig']; } $tripod = $this->getTripod($this->args[self::STORE_NAME_KEY], $this->args[self::POD_NAME_KEY], $statsConfig); $operations = $this->args[self::OPERATIONS_KEY]; $subjectsAndPredicatesOfChange = $this->args[self::CHANGES_KEY]; $subjectCount = 0; foreach ($operations as $op) { /** @var \Tripod\Mongo\Composites\IComposite $composite */ $composite = $tripod->getComposite($op); $modifiedSubjects = $composite->getImpactedSubjects($subjectsAndPredicatesOfChange, $this->args[self::CONTEXT_ALIAS_KEY]); if (!empty($modifiedSubjects)) { /* @var $subject \Tripod\Mongo\ImpactedSubject */ foreach ($modifiedSubjects as $subject) { $subjectCount++; $subjectTimer = new \Tripod\Timer(); $subjectTimer->start(); if (isset($this->args[self::QUEUE_KEY]) || count($subject->getSpecTypes()) == 0) { $queueName = isset($this->args[self::QUEUE_KEY]) ? $this->args[self::QUEUE_KEY] : Config::getApplyQueueName(); $this->addSubjectToQueue($subject, $queueName); } else { $specsGroupedByQueue = array(); foreach ($subject->getSpecTypes() as $specType) { $spec = null; switch ($subject->getOperation()) { case OP_VIEWS: $spec = Config::getInstance()->getViewSpecification($this->args[self::STORE_NAME_KEY], $specType); break; case OP_TABLES: $spec = Config::getInstance()->getTableSpecification($this->args[self::STORE_NAME_KEY], $specType); break; case OP_SEARCH: $spec = Config::getInstance()->getSearchDocumentSpecification($this->args[self::STORE_NAME_KEY], $specType); break; } if (!$spec || !isset($spec['queue'])) { if (!$spec) { $spec = array(); } $spec['queue'] = Config::getApplyQueueName(); } if (!isset($specsGroupedByQueue[$spec['queue']])) { $specsGroupedByQueue[$spec['queue']] = array(); } $specsGroupedByQueue[$spec['queue']][] = $specType; } foreach ($specsGroupedByQueue as $queueName => $specs) { $queuedSubject = new \Tripod\Mongo\ImpactedSubject($subject->getResourceId(), $subject->getOperation(), $subject->getStoreName(), $subject->getPodName(), $specs); $this->addSubjectToQueue($queuedSubject, $queueName); } } $subjectTimer->stop(); // stat time taken to discover impacted subjects for the given subject of change $this->getStat()->timer(MONGO_QUEUE_DISCOVER_SUBJECT, $subjectTimer->result()); } if (!empty($this->subjectsGroupedByQueue)) { foreach ($this->subjectsGroupedByQueue as $queueName => $subjects) { $this->getApplyOperation()->createJob($subjects, $queueName, $statsConfig); } $this->subjectsGroupedByQueue = array(); } } } // stat time taken to process item, from time it was created (queued) $timer->stop(); $this->getStat()->timer(MONGO_QUEUE_DISCOVER_SUCCESS, $timer->result()); $this->debugLog("[JOBID " . $this->job->payload['id'] . "] DiscoverImpactedSubjects::perform() done in {$timer->result()}ms"); $this->getStat()->increment(MONGO_QUEUE_DISCOVER_JOB . '.' . SUBJECT_COUNT, $subjectCount); } catch (\Exception $e) { $this->getStat()->increment(MONGO_QUEUE_DISCOVER_FAIL); $this->errorLog("Caught exception in " . get_class($this) . ": " . $e->getMessage()); throw $e; } }
$tripodOptions = array(); if (isset($appConfig['tripod'])) { $tripodOptions = $appConfig['tripod']; } if (isset($appConfig['statsConfig'])) { $tripodOptions['statsConfig'] = $appConfig['statsConfig']; } $readRepeat = isset($appConfig['read-repeat']) ? (int) $appConfig['read-repeat'] : 0; define('READ_REPEAT_NUM', $readRepeat); $app->group('/1', function () use($app, $tripodOptions) { $app->group('/:storeName', function () use($app, $tripodOptions) { $app->get('/views/:viewId/:encodedFqUri', function ($storeName, $viewSpecId, $encodedFqUri) use($app, $tripodOptions) { \Tripod\Mongo\Config::setConfig(json_decode(file_get_contents('./config/tripod-config-' . $storeName . '.json'), true)); $i = 0; do { $viewSpec = \Tripod\Mongo\Config::getInstance()->getViewSpecification($storeName, $viewSpecId); $podName = isset($viewSpec['from']) ? $viewSpec['from'] : null; $tripodOptions['statsConfig'] = getStat($app, $tripodOptions); $tripod = new \Tripod\Mongo\Driver($podName, $storeName, $tripodOptions); $contentType = $app->request()->getMediaType(); switch ($contentType) { case 'application/rdf+xml': $format = FORMAT_RDF_XML; break; case 'text/plain': $format = FORMAT_NTRIPLES; break; case 'text/turtle': $format = FORMAT_TURTLE; break; default:
/** * @param $specId * @return array|null */ protected function getSearchDocumentSpecification($specId) { return Config::getInstance()->getSearchDocumentSpecification($this->storeName, $specId); }
public function testNestConditionalInArithmeticFunction() { $tableSpec = array("_id" => "t_arithmetic_with_nested_conditional", "type" => array("bibo:Book", "bibo:Document"), "from" => "CBD_testing", "fields" => array(array("fieldName" => "x", "predicates" => array("foo:wibble"))), "computed_fields" => array(array("fieldName" => "foobar", "value" => array("arithmetic" => array(array("conditional" => array("if" => array('$x'), "then" => '$x', "else" => 100)), "*", 3))))); $oldConfig = \Tripod\Mongo\Config::getConfig(); $newConfig = \Tripod\Mongo\Config::getConfig(); $newConfig['stores']['tripod_php_testing']['table_specifications'][] = $tableSpec; \Tripod\Mongo\Config::setConfig($newConfig); \Tripod\Mongo\Config::getInstance(); $this->tripod = new \Tripod\Mongo\Driver('CBD_testing', 'tripod_php_testing'); $this->loadResourceDataViaTripod(); $this->tripod->generateTableRows('t_arithmetic_with_nested_conditional'); $collection = \Tripod\Mongo\Config::getInstance()->getCollectionForTable('tripod_php_testing', 't_arithmetic_with_nested_conditional'); $tableDoc = $collection->findOne(array('_id.type' => 't_arithmetic_with_nested_conditional')); $this->assertEquals(300, $tableDoc['value']['foobar']); \Tripod\Mongo\Config::setConfig($oldConfig); \Tripod\Mongo\Config::getInstance(); $collection->drop(); }
/** * @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; }
/** * Add $triples about a given $subject to Mongo. Only $triples with subject matching $subject will be added, others will be ignored. * Make them quads with a $context * @param string $subject * @param array $triples * @param string|null $context * @return array */ public function bsonizeTriplesAbout($subject, array $triples, $context = null) { $context = $context == null ? Config::getInstance()->getDefaultContextAlias() : $this->labeller->uri_to_alias($context); $graph = new MongoGraph(); foreach ($triples as $triple) { $triple = rtrim($triple); $parts = preg_split("/\\s/", $triple); $subject = trim($parts[0], '><'); $predicate = trim($parts[1], '><'); $object = $this->extract_object($parts); if ($this->isUri($object)) { $graph->add_resource_triple($subject, $predicate, $object); } else { $graph->add_literal_triple($subject, $predicate, $object); } } return $graph->to_tripod_array($subject, $context); }
/** * For mocking * @return Config */ protected function getConfigInstance() { return Config::getInstance(); }
public function testManuallySpecifiedQueueWillOverrideQueuesDefinedInConfig() { $config = \Tripod\Mongo\Config::getConfig(); // Create a bunch of specs on various queues $tableSpecs = array(array("_id" => "t_resource", "type" => "acorn:Resource", "from" => "CBD_testing", "ensureIndexes" => array("value.isbn" => 1), "fields" => array(array("fieldName" => "type", "predicates" => array("rdf:type")), array("fieldName" => "isbn", "predicates" => array("bibo:isbn13"))), "joins" => array("dct:isVersionOf" => array("fields" => array(array("fieldName" => "isbn13", "predicates" => array("bibo:isbn13")))))), array("_id" => "t_source_count", "type" => "acorn:Resource", "from" => "CBD_testing", "to_data_source" => "rs2", "queue" => "counts_and_other_non_essentials", "fields" => array(array("fieldName" => "type", "predicates" => array("rdf:type"))), "joins" => array("dct:isVersionOf" => array("fields" => array(array("fieldName" => "isbn13", "predicates" => array("bibo:isbn13"))))), "counts" => array(array("fieldName" => "source_count", "property" => "dct:isVersionOf"), array("fieldName" => "random_predicate_count", "property" => "dct:randomPredicate"))), array("_id" => "t_source_count_regex", "type" => "acorn:Resource", "from" => "CBD_testing", "queue" => "counts_and_other_non_essentials", "fields" => array(array("fieldName" => "type", "predicates" => array("rdf:type"))), "joins" => array("dct:isVersionOf" => array("fields" => array(array("fieldName" => "isbn13", "predicates" => array("bibo:isbn13"))))), "counts" => array(array("fieldName" => "source_count", "property" => "dct:isVersionOf"), array("fieldName" => "regex_source_count", "property" => "dct:isVersionOf", "regex" => "/foobar/"))), array("_id" => "t_join_source_count_regex", "type" => "acorn:Resource", "from" => "CBD_testing", "queue" => "MOST_IMPORTANT_QUEUE_EVER", "joins" => array("acorn:jacsUri" => array("counts" => array(array("fieldName" => "titles_count", "property" => "dct:title")))))); $config['stores']['tripod_php_testing']['table_specifications'] = $tableSpecs; \Tripod\Mongo\Config::setConfig($config); /** @var \Tripod\Mongo\Jobs\DiscoverImpactedSubjects|PHPUnit_Framework_MockObject_MockObject $discoverImpactedSubjects */ $discoverImpactedSubjects = $this->getMockBuilder('\\Tripod\\Mongo\\Jobs\\DiscoverImpactedSubjects')->setMethods(array('getTripod', 'getApplyOperation'))->getMock(); $this->setArgs(); $args = $this->args; $args['operations'] = array(OP_TABLES); $args['queue'] = 'TRIPOD_TESTING_QUEUE_' . uniqid(); $discoverImpactedSubjects->args = $args; $discoverImpactedSubjects->job->payload['id'] = uniqid(); $tripod = $this->getMockBuilder('\\Tripod\\Mongo\\Driver')->setMethods(array('getComposite'))->setConstructorArgs(array('CBD_testing', 'tripod_php_testing'))->getMock(); $tables = $this->getMockBuilder('\\Tripod\\Mongo\\Composites\\Tables')->setMethods(array('getImpactedSubjects'))->setConstructorArgs(array('tripod_php_testing', \Tripod\Mongo\Config::getInstance()->getCollectionForCBD('tripod_php_testing', 'CBD_testing'), 'http://talisaspire.com/'))->getMock(); $applyOperation = $this->getMockBuilder('\\Tripod\\Mongo\\Jobs\\ApplyOperation')->setMethods(array('createJob'))->getMock(); $tableSubjects = array(new \Tripod\Mongo\ImpactedSubject(array(_ID_RESOURCE => 'http://example.com/resources/foo2', _ID_CONTEXT => $this->args['contextAlias']), OP_TABLES, $this->args['storeName'], $this->args['podName'], array('t_resource', 't_source_count', 't_source_count_regex', 't_join_source_count_regex')), new \Tripod\Mongo\ImpactedSubject(array(_ID_RESOURCE => 'http://example.com/resources/foo3', _ID_CONTEXT => $this->args['contextAlias']), OP_TABLES, $this->args['storeName'], $this->args['podName'], array('t_distinct'))); $tables->expects($this->once())->method('getImpactedSubjects')->with($this->args['changes'], $this->args['contextAlias'])->will($this->returnValue($tableSubjects)); $tripod->expects($this->once())->method('getComposite')->with(OP_TABLES)->will($this->returnValue($tables)); $discoverImpactedSubjects->expects($this->once())->method('getTripod')->will($this->returnValue($tripod)); $discoverImpactedSubjects->expects($this->once())->method('getApplyOperation')->will($this->returnValue($applyOperation)); $applyOperation->expects($this->once())->method('createJob')->withConsecutive(array($tableSubjects, $args['queue'])); $discoverImpactedSubjects->perform(); }
<?php require_once dirname(__FILE__) . '/common.inc.php'; require_once dirname(dirname(dirname(__FILE__))) . '/src/tripod.inc.php'; if ($argc != 2 && $argc != 3 && $argc != 4) { echo "usage: php ensureIndexes.php tripodConfig.json [storeName] [forceReindex (default is false)]\n"; die; } array_shift($argv); \Tripod\Mongo\Config::setConfig(json_decode(file_get_contents($argv[0]), true)); $storeName = isset($argv[1]) ? $argv[1] : null; $forceReindex = isset($argv[2]) && $argv[2] == "true" ? true : false; \Tripod\Mongo\Config::getInstance()->setMongoCursorTimeout(-1); $ei = new \Tripod\Mongo\IndexUtils(); $t = new \Tripod\Timer(); $t->start(); print "About to start indexing on {$storeName}...\n"; $ei->ensureIndexes($forceReindex, $storeName); $t->stop(); print "Indexing complete, took {$t->result()} seconds\n";
/** * @param string $tableType * @param string|null $resource * @param string|null $context * @param string|null $queueName Queue for background bulk generation * @return null //@todo: this should be a bool */ public function generateTableRows($tableType, $resource = null, $context = null, $queueName = null) { $t = new \Tripod\Timer(); $t->start(); $this->temporaryFields = array(); $tableSpec = Config::getInstance()->getTableSpecification($this->storeName, $tableType); $collection = $this->config->getCollectionForTable($this->storeName, $tableType); if ($tableSpec == null) { $this->debugLog("Could not find a table specification for {$tableType}"); return null; } // ensure that the ID field, view type, and the impactIndex indexes are correctly set up $collection->createIndex(array('_id.r' => 1, '_id.c' => 1, '_id.type' => 1), array('background' => 1)); $collection->createIndex(array('_id.type' => 1), array('background' => 1)); $collection->createIndex(array('value.' . _IMPACT_INDEX => 1), array('background' => 1)); // ensure any custom view indexes foreach (Config::getInstance()->getTableSpecifications($this->storeName) as $tSpec) { if (isset($tSpec['ensureIndexes']) && $tSpec['to_data_source'] == $tableSpec['to_data_source']) { foreach ($tSpec['ensureIndexes'] as $ensureIndex) { $this->ensureIndex($collection, $ensureIndex); } } } // default the context $contextAlias = $this->getContextAlias($context); // default collection $from = isset($tableSpec["from"]) ? $tableSpec["from"] : $this->podName; $types = array(); if (is_array($tableSpec["type"])) { foreach ($tableSpec["type"] as $type) { $types[] = array("rdf:type.u" => $this->labeller->qname_to_alias($type)); $types[] = array("rdf:type.u" => $this->labeller->uri_to_alias($type)); } } else { $types[] = array("rdf:type.u" => $this->labeller->qname_to_alias($tableSpec["type"])); $types[] = array("rdf:type.u" => $this->labeller->uri_to_alias($tableSpec["type"])); } $filter = array('$or' => $types); if (isset($resource)) { $filter["_id"] = array(_ID_RESOURCE => $this->labeller->uri_to_alias($resource), _ID_CONTEXT => $contextAlias); } $docs = $this->config->getCollectionForCBD($this->storeName, $from)->find($filter, array('maxTimeMS' => 1000000)); foreach ($docs as $doc) { if ($queueName && !$resource) { $subject = new ImpactedSubject($doc['_id'], OP_TABLES, $this->storeName, $from, array($tableType)); $jobOptions = array(); if ($this->stat || !empty($this->statsConfig)) { $jobOptions['statsConfig'] = $this->getStatsConfig(); } $this->getApplyOperation()->createJob(array($subject), $queueName, $jobOptions); } else { // set up ID $generatedRow = array("_id" => array(_ID_RESOURCE => $doc["_id"][_ID_RESOURCE], _ID_CONTEXT => $doc["_id"][_ID_CONTEXT], _ID_TYPE => $tableSpec['_id'])); $value = array('_id' => $doc['_id']); // everything must go in the value object todo: this is a hang over from map reduce days, engineer out once we have stability on new PHP method for M/R $this->addIdToImpactIndex($doc['_id'], $value); // need to add the doc to the impact index to be consistent with views/search etc. this is needed for discovering impacted operations $this->addFields($doc, $tableSpec, $value); if (isset($tableSpec['joins'])) { $this->doJoins($doc, $tableSpec['joins'], $value, $from, $contextAlias); } if (isset($tableSpec['counts'])) { $this->doCounts($doc, $tableSpec['counts'], $value); } if (isset($tableSpec['computed_fields'])) { $this->doComputedFields($tableSpec, $value); } // Remove temp fields from document $generatedRow['value'] = array_diff_key($value, array_flip($this->temporaryFields)); $this->truncatingSave($collection, $generatedRow); } } $t->stop(); $this->timingLog(MONGO_CREATE_TABLE, array('type' => $tableSpec['type'], 'duration' => $t->result(), 'filter' => $filter, 'from' => $from)); $this->getStat()->timer(MONGO_CREATE_TABLE . ".{$tableType}", $t->result()); }
/** * Joins data to $dest from $source according to specification in $joins, or queries DB if data is not available in $source. * @param $source * @param $joins * @param $dest * @param $from * @param $contextAlias * @param bool $buildImpactIndex */ protected function doJoins($source, $joins, &$dest, $from, $contextAlias, $buildImpactIndex = true) { // expand sequences before doing any joins... $this->expandSequence($joins, $source); foreach ($joins as $predicate => $ruleset) { if ($predicate == 'followSequence') { continue; } if (isset($source[$predicate])) { // todo: perhaps we can get better performance by detecting whether or not // the uri to join on is already in the impact index, and if so not attempting // to join on it. However, we need to think about different combinations of // nested joins in different points of the view spec and see if this would // complicate things. Needs a unit test or two. $joinUris = array(); if (isset($source[$predicate][VALUE_URI])) { // single value for join $joinUris[] = array(_ID_RESOURCE => $source[$predicate][VALUE_URI], _ID_CONTEXT => $contextAlias); } else { // multiple values for join $joinsPushed = 0; foreach ($source[$predicate] as $v) { if (isset($ruleset['maxJoins']) && !$joinsPushed < $ruleset['maxJoins']) { break; // maxJoins reached } $joinUris[] = array(_ID_RESOURCE => $v[VALUE_URI], _ID_CONTEXT => $contextAlias); $joinsPushed++; } } $recursiveJoins = array(); $collection = isset($ruleset['from']) ? $this->config->getCollectionForCBD($this->storeName, $ruleset['from']) : $this->config->getCollectionForCBD($this->storeName, $from); $cursor = $collection->find(array('_id' => array('$in' => $joinUris)), array('maxTimeMS' => \Tripod\Mongo\Config::getInstance()->getMongoCursorTimeout())); $this->addIdToImpactIndex($joinUris, $dest, $buildImpactIndex); foreach ($cursor as $linkMatch) { // if there is a condition, check it... if (isset($ruleset['condition'])) { $ruleset['condition']['._id'] = $linkMatch['_id']; } if (!(isset($ruleset['condition']) && $collection->count($ruleset['condition']) == 0)) { // make sure any sequences are expanded before extracting properties if (isset($ruleset['joins'])) { $this->expandSequence($ruleset['joins'], $linkMatch); } if (isset($ruleset['filter'])) { foreach ($ruleset['filter'] as $filterPredicate => $filter) { foreach ($filter as $filterType => $filterMatch) { if (isset($linkMatch[$filterPredicate])) { foreach ($linkMatch[$filterPredicate] as $linkMatchType => $linkMatchValues) { if (is_array($linkMatchValues) == false) { $linkMatchValues = array($linkMatchType => $linkMatchValues); } foreach ($linkMatchValues as $linkMatchType => $linkMatchValue) { if ($this->matchesFilter($linkMatchType, $linkMatchValue, $filterType, $filterMatch)) { $dest[_GRAPHS][] = $this->extractProperties($linkMatch, $ruleset, $from); } } } } } } } else { $dest[_GRAPHS][] = $this->extractProperties($linkMatch, $ruleset, $from); } if (isset($ruleset['joins'])) { // recursive joins must be done after this cursor has completed, otherwise things get messy $recursiveJoins[] = array('data' => $linkMatch, 'ruleset' => $ruleset['joins']); } } } if (count($recursiveJoins) > 0) { foreach ($recursiveJoins as $r) { $this->doJoins($r['data'], $r['ruleset'], $dest, $from, $contextAlias, $buildImpactIndex); } } } } return; }
/** * Test that a change to a resource that isn't covered by a viewspec or in an impact index still triggers the discover * impacted subjects operation and returns nothing */ public function testResourceUpdateNotCoveredBySpecStillTriggersOperations() { $context = 'http://talisaspire.com/'; $labeller = new \Tripod\Mongo\Labeller(); // First add a graph $originalGraph = new \Tripod\ExtendedGraph(); $uri1 = 'http://example.com/resources/' . uniqid(); $originalGraph->add_resource_triple($uri1, RDF_TYPE, $labeller->qname_to_uri('bibo:Document')); $originalGraph->add_literal_triple($uri1, $labeller->qname_to_uri('dct:title'), 'How to speak American like a native'); $originalGraph->add_literal_triple($uri1, $labeller->qname_to_uri('dct:subject'), 'Languages -- \'Murrican'); $originalSubjectsAndPredicatesOfChange = array($labeller->uri_to_alias($uri1) => array('rdf:type', 'dct:title', 'dct:subject')); $updatedSubjectsAndPredicatesOfChange = array($labeller->uri_to_alias($uri1) => array('dct:subject')); /** @var \Tripod\Mongo\Driver|PHPUnit_Framework_MockObject_MockObject $mockTripod */ $mockTripod = $this->getMock('\\Tripod\\Mongo\\Driver', array('getDataUpdater', 'getComposite'), array('CBD_testing', 'tripod_php_testing', array('defaultContext' => $context, OP_ASYNC => array(OP_TABLES => true, OP_VIEWS => false, OP_SEARCH => true)))); $mockTripodUpdates = $this->getMock('\\Tripod\\Mongo\\Updates', array('processSyncOperations', 'queueAsyncOperations'), array($mockTripod, array(OP_ASYNC => array(OP_TABLES => true, OP_VIEWS => false, OP_SEARCH => true)))); $mockViews = $this->getMock('\\Tripod\\Mongo\\Composites\\Views', array('generateViewsForResourcesOfType'), array('tripod_php_testing', \Tripod\Mongo\Config::getInstance()->getCollectionForCBD('tripod_php_testing', 'CBD_testing'), $context)); $mockTripod->expects($this->exactly(2))->method('getDataUpdater')->will($this->returnValue($mockTripodUpdates)); $mockTripod->expects($this->exactly(2))->method('getComposite')->with(OP_VIEWS)->will($this->returnValue($mockViews)); $mockTripodUpdates->expects($this->exactly(2))->method('processSyncOperations')->withConsecutive(array($this->equalTo($originalSubjectsAndPredicatesOfChange), $this->equalTo($context)), array($this->equalTo($updatedSubjectsAndPredicatesOfChange), $this->equalTo($context))); $mockTripodUpdates->expects($this->exactly(2))->method('queueAsyncOperations')->withConsecutive(array($this->equalTo($originalSubjectsAndPredicatesOfChange), $this->equalTo($context)), array($this->equalTo($updatedSubjectsAndPredicatesOfChange), $this->equalTo($context))); $mockViews->expects($this->never())->method('generateViewsForResourcesOfType'); $mockTripod->saveChanges(new \Tripod\ExtendedGraph(), $originalGraph); /** @var \Tripod\Mongo\Composites\Views $view */ $view = $mockTripod->getComposite(OP_VIEWS); $this->assertInstanceOf('\\Tripod\\Mongo\\Composites\\Views', $view); $impactedSubjects = $view->getImpactedSubjects($originalSubjectsAndPredicatesOfChange, $context); $this->assertEmpty($impactedSubjects); $newGraph = $originalGraph->get_subject_subgraph($uri1); $newGraph->replace_literal_triple($uri1, $labeller->qname_to_uri('dct:subject'), 'Languages -- \'Murrican', 'Languages -- English, American'); $mockTripod->saveChanges($originalGraph, $newGraph); /** @var \Tripod\Mongo\Composites\Views $view */ $view = $mockTripod->getComposite(OP_VIEWS); $this->assertInstanceOf('\\Tripod\\Mongo\\Composites\\Views', $view); $impactedSubjects = $view->getImpactedSubjects($updatedSubjectsAndPredicatesOfChange, $context); $this->assertEmpty($impactedSubjects); }
/** * @param array $source * @param array $joins * @param array $target * @param string $from */ protected function doJoin($source, $joins, &$target, $from) { // expand sequences before proceeding $this->expandSequence($joins, $source); $config = Config::getInstance(); foreach ($joins as $predicate => $rules) { if (isset($source[$predicate])) { $joinUris = array(); if (isset($source[$predicate]['u'])) { //single value for join $joinUris[] = array('r' => $source[$predicate]['u'], 'c' => $this->defaultContext); // todo: check that default context is the right thing to set here and below } else { //multiple values for join foreach ($source[$predicate] as $v) { $joinUris[] = array('r' => $v['u'], 'c' => $this->defaultContext); } } $recursiveJoins = array(); $collection = isset($rules['from']) ? $config->getCollectionForCBD($this->storeName, $rules['from']) : $config->getCollectionForCBD($this->storeName, $from); $cursor = $collection->find(array('_id' => array('$in' => $joinUris)), array('maxTimeMS' => \Tripod\Mongo\Config::getInstance()->getMongoCursorTimeout())); // add to impact index $this->addIdToImpactIndex($joinUris, $target); foreach ($cursor as $linkMatch) { if (isset($rules['fields'])) { $this->addFields($linkMatch, $rules['fields'], $target); } if (isset($rules['indices'])) { $this->addFields($linkMatch, $rules['indices'], $target, true); } if (isset($rules['join'])) { $recursiveJoins[] = array('data' => $linkMatch, 'ruleset' => $rules['joins']); } } foreach ($recursiveJoins as $rj) { $this->doJoin($rj['data'], $rj['ruleset'], $target, $from); } } } }