public function testTransactionRollbackDuringApplyChanges()
 {
     // Save some basic data into the db before we create a transaction to modify it
     $subjectOne = 'http://example.com/resources/1';
     $subjectTwo = 'http://example.com/resources/2';
     $doc1 = array('_id' => array('r' => $subjectOne, 'c' => 'http://talisaspire.com/'), 'rdf:type' => array('u' => 'acorn:Resource'), 'dct:title' => array(array('l' => 'Title one'), array('l' => 'Title two')), '_version' => 0, '_cts' => \Tripod\Mongo\DateUtil::getMongoDate(), '_uts' => \Tripod\Mongo\DateUtil::getMongoDate());
     $doc2 = array('_id' => array('r' => $subjectTwo, 'c' => 'http://talisaspire.com/'), 'rdf:type' => array('u' => 'acorn:Book'), 'dct:title' => array(array('l' => 'Title three'), array('l' => 'Title four')), '_version' => 0, '_cts' => \Tripod\Mongo\DateUtil::getMongoDate(), '_uts' => \Tripod\Mongo\DateUtil::getMongoDate());
     $this->addDocument($doc1);
     $this->addDocument($doc2);
     // now lets modify the data using tripod
     $g1 = $this->tripod->describeResources(array($subjectOne), 'http://talisaspire.com/');
     $g2 = $this->tripod->describeResources(array($subjectTwo), 'http://talisaspire.com/');
     $oG = new \Tripod\Mongo\MongoGraph();
     $oG->add_graph($g1);
     $oG->add_graph($g2);
     $nG = new \Tripod\Mongo\MongoGraph();
     $nG->add_graph($oG);
     $nG->remove_literal_triple($subjectOne, $nG->qname_to_uri("dct:title"), "Title one");
     $nG->add_literal_triple($subjectOne, $nG->qname_to_uri("dct:title"), "Updated Title one");
     $nG->remove_literal_triple($subjectTwo, $nG->qname_to_uri("dct:title"), "Title three");
     $nG->add_literal_triple($subjectTwo, $nG->qname_to_uri("dct:title"), "Updated Title three");
     $mockTransactionId = 'transaction_1';
     $mockTripod = $this->getMock('\\Tripod\\Mongo\\Driver', array('getDataUpdater'), array('CBD_testing', 'tripod_php_testing', array('defaultContext' => 'http://talisaspire.com/')));
     $mockTripodUpdate = $this->getMock('\\Tripod\\Mongo\\Updates', array('generateTransactionId', 'lockSingleDocument', 'applyChangeSet'), array($mockTripod));
     $mockTripodUpdate->expects($this->exactly(1))->method('generateTransactionId')->will($this->returnValue($mockTransactionId));
     $mockTripodUpdate->expects($this->exactly(2))->method('lockSingleDocument')->will($this->returnCallback(array($this, 'lockSingleDocumentCallback')));
     $mockTripodUpdate->expects($this->once())->method('applyChangeSet')->will($this->throwException(new Exception("Exception throw by mock test during applychangeset")));
     $mockTripod->expects($this->atLeastOnce())->method('getDataUpdater')->will($this->returnValue($mockTripodUpdate));
     /** @var $mockTripod \Tripod\Mongo\Driver */
     $mockTripod->setTransactionLog($this->tripodTransactionLog);
     try {
         $mockTripod->saveChanges($oG, $nG, "http://talisaspire.com/");
         $this->fail('Exception should have been thrown');
     } catch (\Tripod\Exceptions\Exception $e) {
         // Squash the exception here as we need to continue running the assertions.
     }
     // make sure the subjects werent changed
     $uG = $this->tripod->describeResources(array($subjectOne, $subjectTwo));
     $this->assertTrue($uG->has_resource_triple($subjectOne, $uG->qname_to_uri("rdf:type"), $uG->qname_to_uri("acorn:Resource")));
     $this->assertTrue($uG->has_literal_triple($subjectOne, $uG->qname_to_uri("dct:title"), 'Title one'));
     $this->assertTrue($uG->has_literal_triple($subjectOne, $uG->qname_to_uri("dct:title"), 'Title two'));
     $this->assertFalse($uG->has_literal_triple($subjectOne, $uG->qname_to_uri("dct:title"), 'Updated Title two'));
     $this->assertTrue($uG->has_resource_triple($subjectTwo, $uG->qname_to_uri("rdf:type"), $uG->qname_to_uri("acorn:Book")));
     $this->assertTrue($uG->has_literal_triple($subjectTwo, $uG->qname_to_uri("dct:title"), 'Title three'));
     $this->assertTrue($uG->has_literal_triple($subjectTwo, $uG->qname_to_uri("dct:title"), 'Title four'));
     $this->assertFalse($uG->has_literal_triple($subjectTwo, $uG->qname_to_uri("dct:title"), 'Updated Title three'));
     $this->assertDocumentDoesNotHaveProperty(array('r' => $subjectOne, 'c' => 'http://talisaspire.com/'), _LOCKED_FOR_TRANS, $this->tripod);
     $this->assertDocumentDoesNotHaveProperty(array('r' => $subjectOne, 'c' => 'http://talisaspire.com/'), _LOCKED_FOR_TRANS_TS, $this->tripod);
     $this->assertDocumentDoesNotHaveProperty(array('r' => $subjectTwo, 'c' => 'http://talisaspire.com/'), _LOCKED_FOR_TRANS, $this->tripod);
     $this->assertDocumentDoesNotHaveProperty(array('r' => $subjectTwo, 'c' => 'http://talisaspire.com/'), _LOCKED_FOR_TRANS_TS, $this->tripod);
     $transaction = $mockTripodUpdate->getTransactionLog()->getTransaction($mockTransactionId);
     $this->assertNotNull($transaction);
     $this->assertEquals("Exception throw by mock test during applychangeset", $transaction['error']['reason']);
     $this->assertEquals("failed", $transaction['status']);
 }
예제 #2
0
 /**
  * This test addes a set of precanned transactions to the transaction log, and then verifies that
  * only the transactions $gte the given date are replayed
  */
 public function testReplayTransactionsBetweenTwoDates()
 {
     $transaction_1 = $this->buildTransactionDocument(1, 'http://example.com/resources/1', '2013-01-21T13:00:00.000Z', '2013-01-21T13:01:00.000Z', 0);
     $transaction_2 = $this->buildTransactionDocument(2, 'http://example.com/resources/2', '2013-01-21T13:00:00.000Z', '2013-01-21T13:02:00.000Z', 0);
     $transaction_3 = $this->buildTransactionDocument(3, 'http://example.com/resources/3', '2013-01-21T13:00:00.000Z', '2013-01-21T13:03:00.000Z', 0);
     $transaction_4 = $this->buildTransactionDocument(4, 'http://example.com/resources/4', '2013-01-21T13:00:00.000Z', '2013-01-21T13:04:00.000Z', 0);
     $transaction_5 = $this->buildTransactionDocument(5, 'http://example.com/resources/5', '2013-01-21T13:00:00.000Z', '2013-01-21T13:05:00.000Z', 0);
     $this->addDocument($transaction_1, true);
     $this->addDocument($transaction_2, true);
     $this->addDocument($transaction_3, true);
     $this->addDocument($transaction_4, true);
     $this->addDocument($transaction_5, true);
     $this->getTripodCollection($this->tripod)->drop();
     $this->tripod->replayTransactionLog("2013-01-21T13:02:00.000Z", "2013-01-21T13:04:00.000Z");
     $g = $this->tripod->describeResources(array('http://example.com/resources/1', 'http://example.com/resources/2', 'http://example.com/resources/3', 'http://example.com/resources/4', 'http://example.com/resources/5'));
     $this->assertFalse($g->has_triples_about('http://example.com/resources/1'), "Should not contain anything about /resources/1");
     $this->assertTrue($g->has_triples_about('http://example.com/resources/2'), "Should contain triples about /resources/2");
     $this->assertTrue($g->has_triples_about('http://example.com/resources/3'), "Should contain triples about /resources/3");
     $this->assertTrue($g->has_triples_about('http://example.com/resources/4'), "Should contain triples about /resources/4");
     $this->assertFalse($g->has_triples_about('http://example.com/resources/5'), "Should not contain triples about /resources/5");
 }