diff --git a/src/mongo/base/DriverBase.class.php b/src/mongo/base/DriverBase.class.php index 96b11624..1f820ccc 100644 --- a/src/mongo/base/DriverBase.class.php +++ b/src/mongo/base/DriverBase.class.php @@ -204,6 +204,20 @@ public function timingLog($type, $params=null) * @param string $message * @param array|null $params */ + /** + * @param $message + * @param array|null $params + */ + public function infoLog($message, $params=null) + { + $this->log(\Psr\Log\LogLevel::INFO,$message,$params); + + } + + /** + * @param $message + * @param array|null $params + */ public function debugLog($message, $params=null) { $this->log(\Psr\Log\LogLevel::DEBUG,$message,$params); diff --git a/test/unit/mongo/MongoTripodConfigTest.php b/test/unit/mongo/MongoTripodConfigTest.php index f6153f7f..cf125845 100644 --- a/test/unit/mongo/MongoTripodConfigTest.php +++ b/test/unit/mongo/MongoTripodConfigTest.php @@ -1264,6 +1264,71 @@ public function testDataLoadedInConfiguredDataSource() } } + public function testTransactionLogIsWrittenToCorrectDBAndCollection() + { + $storeName = 'tripod_php_testing'; + $newConfig = \Tripod\Mongo\Config::getConfig(); + $newConfig['transaction_log']['database'] = 'tripod_php_testing_transaction_log'; + $newConfig['transaction_log']['collection'] = 'transaction_log'; + + \Tripod\Mongo\Config::setConfig($newConfig); + + $config = \Tripod\Mongo\Config::getInstance(); + + // Clear out any old data + $tlogDB = $config->getTransactionLogDatabase(); + $tlogDB->drop(); + + + // Make sure the dbs do not exist + $transactionConnInfo = $newConfig['data_sources'][$newConfig['transaction_log']['data_source']]; + $options = isset($transactionConnInfo['replicaSet']) && !empty($transactionConnInfo['replicaSet']) ? array('replicaSet' => $transactionConnInfo['replicaSet']): array(); + $transactionMongo = new MongoClient($transactionConnInfo['connection'], $options); + $transactionDbInfo = $transactionMongo->listDBs(); + foreach($transactionDbInfo['databases'] as $db){ + $this->assertNotEquals($db['name'], $newConfig['transaction_log']['database'], $newConfig['queue']['database']); + } + $tqueuesConnInfo = $newConfig['data_sources'][$newConfig['transaction_log']['data_source']]; + $options = isset($tqueuesConnInfo['replicaSet']) && !empty($tqueuesConnInfo['replicaSet']) ? array('replicaSet' => $tqueuesConnInfo['replicaSet']): array(); + $queuesMongo = new MongoClient($tqueuesConnInfo['connection'], $options); + $queuesDbInfo = $queuesMongo->listDBs(); + foreach($queuesDbInfo['databases'] as $db){ + $this->assertNotEquals($db['name'], $newConfig['transaction_log']['database'], $newConfig['queue']['database']); + } + + // Start adding some data + $this->tripod = new \Tripod\Mongo\Driver('CBD_testing', $storeName, array(OP_ASYNC=>array(OP_VIEWS=>true,OP_TABLES=>false,OP_SEARCH=>false))); + $this->loadBaseDataViaTripod(); + + $graph = new \Tripod\Mongo\MongoGraph(); + $subject = 'http://example.com/' . uniqid(); + $labeller = new \Tripod\Mongo\Labeller(); + $graph->add_resource_triple($subject, RDF_TYPE, $labeller->qname_to_uri('foaf:Person')); + $graph->add_literal_triple($subject, FOAF_NAME, "Anne Example"); + $this->tripod->saveChanges(new \Tripod\ExtendedGraph(), $graph); + + $newGraph = $this->tripod->describeResource($subject); + $newGraph->add_literal_triple($subject, $labeller->qname_to_uri('foaf:email'), 'anne@example.com'); + $this->tripod->saveChanges($graph, $newGraph); + + // Make sure the dbs do now exist + $transactionDbInfo = $transactionMongo->listDBs(); + $transactionDbExists = false; + foreach($transactionDbInfo['databases'] as $db){ + if($db['name'] === $newConfig['transaction_log']['database']){ + $transactionDbExists = true; + } + } + $this->assertTrue($transactionDbExists); + + // Make sure the data in the dbs look right + $transactionColletion = $transactionMongo->selectCollection($newConfig['transaction_log']['database'], $newConfig['transaction_log']['collection']); + $transactionCount = $transactionColletion->count(); + $transactionExampleDocument = $transactionColletion->findOne(); + $this->assertEquals(18, $transactionCount); + $this->assertContains('transaction_', $transactionExampleDocument["_id"]); + } + public function testComputedFieldSpecValidationInvalidFunction() { $newConfig = \Tripod\Mongo\Config::getConfig(); diff --git a/test/unit/mongo/MongoTripodTablesTest.php b/test/unit/mongo/MongoTripodTablesTest.php index 7de26f29..f4ccebb6 100644 --- a/test/unit/mongo/MongoTripodTablesTest.php +++ b/test/unit/mongo/MongoTripodTablesTest.php @@ -1551,4 +1551,75 @@ public function testSavingMultipleNewEntitiesResultsInOneImpactedSubject() $impactedSubjects = $tables->getImpactedSubjects($subjectsAndPredicatesOfChange, 'http://talisaspire.com/'); $this->assertEquals($expectedImpactedSubjects, $impactedSubjects); } + + 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)))); + + } } \ No newline at end of file