Skip to content

Commit

Permalink
Merge branch 'master' into decouple-invalidation-from-save
Browse files Browse the repository at this point in the history
Conflicts:
	src/mongo/Config.class.php
	src/mongo/base/DriverBase.class.php
	src/mongo/delegates/MongoTripodSearchIndexer.class.php
	src/mongo/delegates/Tables.class.php
	src/mongo/delegates/Updates.class.php
	src/mongo/delegates/Views.class.php
	src/mongo/queue/MongoTripodQueue.class.php
	src/mongo/util/IndexUtils.class.php
	test/unit/mongo/MongoTripodTablesTest.php
	test/unit/mongo/MongoTripodTestBase.php
  • Loading branch information
rsinger committed Jun 23, 2015
2 parents c36b11e + 9ddf67d commit 4ccfb1c
Show file tree
Hide file tree
Showing 3 changed files with 150 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/mongo/base/DriverBase.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
65 changes: 65 additions & 0 deletions test/unit/mongo/MongoTripodConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'), '[email protected]');
$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();
Expand Down
71 changes: 71 additions & 0 deletions test/unit/mongo/MongoTripodTablesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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))));

}
}

0 comments on commit 4ccfb1c

Please sign in to comment.