예제 #1
0
 public function testAddConnectionsNewGroupWithConnections()
 {
     $connections = array('master' => array('host' => 'localhost'), 'slave' => array('host' => '127.0.0.1'));
     $group = new Shanty_Mongo_Connection_Group($connections);
     $this->assertEquals(1, count($group->getMasters()));
     $this->assertEquals(1, count($group->getSlaves()));
     $masters = $group->getMasters();
     $slaves = $group->getSlaves();
     $masterInfo = $masters[0]->getConnectionInfo();
     $this->assertEquals('mongodb://localhost:27017', $masterInfo['connectionString']);
     $slave1Info = $slaves[0]->getConnectionInfo();
     $this->assertEquals('mongodb://127.0.0.1:27017', $slave1Info['connectionString']);
 }
예제 #2
0
 public function testReplicaSet()
 {
     $connections = array('hosts' => array(array('host' => 'mongodb1.local'), array('host' => 'mongodb2.local'), array('host' => 'mongodb3.local')), 'replicaSet' => true);
     $group = new Shanty_Mongo_Connection_Group($connections);
     $this->assertEquals(1, count($group->getMasters()));
     $this->assertEquals(0, count($group->getSlaves()));
     $masters = $group->getMasters();
     $masterInfo = $masters[0]->getConnectionInfo();
     $this->assertEquals("mongodb://{$connections['hosts'][0]['host']}:27017,{$connections['hosts'][1]['host']}:27017,{$connections['hosts'][2]['host']}:27017", $masterInfo['connectionString']);
     $this->assertTrue($masterInfo['replicaSet']);
 }