Пример #1
0
 public function __construct($label = false)
 {
     // This creates the system db and one node
     parent::__construct('test_model', $label);
     // This creates a copy of the same node on a second test connection
     $this->_testSqlRunner($runTests = false, $conName = Meshing_Utils::CONN_NODE_TEST_2);
     $this->conNode2 = Propel::getConnection(Meshing_Utils::CONN_NODE_TEST_2);
     // Set up a known node for the first node
     Meshing_Utils::initialiseNodeDbs('test_model');
     $this->node1 = $this->createKnownNode(new TestModelKnownNode(), $this->conNode);
 }
Пример #2
0
 public function run()
 {
     // We access the node db twice, so let's init the autoloading for this schema
     Meshing_Utils::initialiseNodeDbs($this->opts->schema);
     $conn = Propel::getConnection($this->opts->connection);
     // Check "identity" table on this connection to see whether a build requires --force
     $this->checkNodeBuildCanProceed($conn);
     // Create SQL and run SQL on this connection
     $projectRoot = Meshing_Utils::getProjectRoot();
     $this->buildSql($projectRoot);
     $this->runSql($projectRoot);
     // Record node details in system and system details in node
     $ownNode = $this->writeOwnNodeRecord();
     $this->writeNodeIdentityRecord($ownNode, $conn);
 }
Пример #3
0
 /**
  * Gets mixed array of MeshingOwnNode and *KnownNode objects to send to
  */
 protected function getLocalAndRemoteReceiverNodes(P2POwnNode $node)
 {
     // Rewrite the above from the perspective of the local 'to' node
     $localNodes = P2POwnNodeQuery::create()->joinMeshingTrustLocalRelatedByToOwnNodeId('TrustLocal')->useQuery('TrustLocal')->joinMeshingTrustType()->endUse()->where('TrustLocal.FromOwnNodeId = ?', $node->getId())->where('MeshingTrustType.Name LIKE ?', 'write%')->find();
     // Get array of node ids in remote database (we can't join between system and node dbs)
     $remoteNodeIds = MeshingTrustRemoteQuery::create()->joinMeshingTrustType()->where('MeshingTrustRemote.FromOwnNodeId = ?', $node->getId())->where('MeshingTrustType.Name LIKE ?', 'write%')->select('MeshingTrustRemote.KnownNodeId')->find()->getArrayCopy();
     // Initialise remote node models
     $schemaName = $node->getMeshingSchema()->getName();
     Meshing_Utils::initialiseNodeDbs($schemaName);
     $con = Meshing_Node_Utils::getConnectionForNode($node);
     // Do select in node database for remote node ids
     $className = Meshing_Node_Utils::getNodeClassName($schemaName, 'KnownNodeQuery');
     /* @var $query JobsKnownNodeQuery */
     // (This is just an example - can be of any *KnownNodeQuery class)
     $query = call_user_func(array($className, 'create'), 'KnownNode');
     $remoteNodes = $query->where('KnownNode.Id IN ?', $remoteNodeIds)->find($con);
     /* @var $localNodes PropelObjectCollection */
     /* @var $remoteNodes PropelObjectCollection */
     return array_merge($localNodes->getArrayCopy(), $remoteNodes->getArrayCopy());
 }
Пример #4
0
 public function preRunCheck()
 {
     if (!$this->opts->name) {
         throw new Zend_Console_Getopt_Exception('Which node would you like to start? (use --name)');
     }
     Meshing_Utils::initialiseDb();
     $node = P2POwnNodeQuery::create()->findOneByName($this->opts->name);
     if (!$node) {
         throw new Zend_Console_Getopt_Exception('A node of that name is not registered');
     }
     // Connect with this node's connection, and ensure there are rows in known_nodes
     $conn = Propel::getConnection($node->getP2PConnection()->getName());
     $schemaName = $node->getMeshingSchema()->getName();
     Meshing_Utils::initialiseNodeDbs($schemaName);
     // Obtain the number of trusted nodes
     $class = Meshing_Node_Utils::getNodeClassName($schemaName, 'KnownNodePeer');
     $knownNodeCount = call_user_func(array($class, 'doCount'), new Criteria(), $distinct = false, $conn);
     // If there are no trust rows, we cannot start
     if (!$knownNodeCount) {
         throw new Zend_Console_Getopt_Exception('A node needs to trust other nodes before it can be started');
     }
 }
Пример #5
0
// Set up project
$projectRoot = realpath(dirname(__FILE__) . '/../../..');
require_once $projectRoot . '/lib/Meshing/Paths.php';
require_once $projectRoot . '/tests/unit/Meshing_Test_Paths.php';
require_once $projectRoot . '/lib/Meshing/Utils.php';
Meshing_Utils::reinitialise(new Meshing_Test_Paths());
define('CHILD_TOKEN', 'meshing_test');
define('LOCKING_TEST_LOG', 'log.log');
// If we're running the child here, we'll pass an token
global $argv;
$token = array_key_exists(1, $argv) ? $argv[1] : null;
if ($token == CHILD_TOKEN) {
    // Initialise database (normally done by DatabaseTestCase)
    Meshing_Utils::initialiseDb($testMode = true);
    Meshing_Utils::initialiseNodeDbs('test_model', $testMode);
    // Run child test
    new LockingTestCaseChild($argv[2]);
    exit;
} else {
    // Init simpletest
    require_once 'simpletest/autorun.php';
}
class LockingTestCase extends Meshing_Test_ModelTestCase
{
    public function __construct($label = false)
    {
        // Same package name as test 2
        parent::__construct('test_model', $label);
        $this->node = $this->createKnownNode(new TestModelKnownNode(), $this->conNode);
        // Create/empty the log
Пример #6
0
 /**
  * Initialise the test system and test node databases
  * 
  * Can't init the test node db in the constructor, since the conf file may not be created
  */
 protected function initConnections()
 {
     Meshing_Utils::initialiseDb($testMode = true);
     Meshing_Utils::initialiseNodeDbs($this->package, $testMode);
     $this->conSystem = Propel::getConnection(Meshing_Utils::CONN_SYSTEM_TEST);
     $this->conNode = Propel::getConnection(Meshing_Utils::CONN_NODE_TEST_1);
 }