コード例 #1
0
    def test_configure_mongo_client_for_standalone(self):
        self.cleanup()
        Script.config = {
            'clusterHostInfo': {
                'mongos_hosts': [],
                'mongodb_hosts': ['node1.test.com'],
                'mongodc_hosts': []
            }
        }

        client = MongoClient()
        client.configureMongoClient()
        self.assertEqual(params.mongos_hosts, 'node1.test.com:27025',
                         'The mongos_hosts configuration is not right.')
コード例 #2
0
    def test_configure_mongo_client_for_sharding_cluster(self):
        self.cleanup()
        Script.config['clusterHostInfo'] = {
            'mongos_hosts': ['node1.test.com', 'node2.test.com'],
            'mongodb_hosts': ['node1.test.com'],
            'mongodc_hosts': []
        }

        # Test without_mongos cluster definition
        client = MongoClient()
        client.configureMongoClient()
        self.assertEqual(params.mongos_hosts,
                         'node1.test.com:27017,node2.test.com:27017',
                         'The mongos_hosts configuration is not right.')

        # Test with mongos cluster definition
        params.mongos_cluster_definition = 'node2.test.com,node1.test.com,node2.test.com'
        client.configureMongoClient()
        self.assertEqual(
            params.mongos_hosts,
            'node2.test.com:27017,node1.test.com:27017,node2.test.com:27018',
            'The mongos_hosts configuration is not right.')