def setUp(self):
        # Create a new oplog progress file
        try:
            os.unlink("oplog.timestamp")
        except OSError:
            pass
        open("oplog.timestamp", "w").close()

        # Start a replica set
        self.repl_set = ReplicaSet().start()
        # Connection to the replica set as a whole
        self.main_conn = self.repl_set.client()
        # Connection to the primary specifically
        self.primary_conn = self.repl_set.primary.client()
        # Connection to the secondary specifically
        self.secondary_conn = self.repl_set.secondary.client(
            read_preference=ReadPreference.SECONDARY_PREFERRED)

        # Wipe any test data
        self.main_conn.drop_database("test")

        # Oplog thread
        doc_manager = DocManager()
        oplog_progress = LockingDict()
        dest_mapping_stru = DestMapping(["test.mc"], [], {})
        self.opman = OplogThread(primary_client=self.main_conn,
                                 doc_managers=(doc_manager, ),
                                 oplog_progress_dict=oplog_progress,
                                 dest_mapping_stru=dest_mapping_stru,
                                 ns_set=["test.mc"])
 def setUp(self):
     self.repl_set = ReplicaSet().start()
     self.primary_conn = self.repl_set.client()
     self.oplog_coll = self.primary_conn.local['oplog.rs']
     self.opman = OplogThread(primary_client=self.primary_conn,
                              doc_managers=(DocManager(), ),
                              oplog_progress_dict=LockingDict())
 def test_client_options(self):
     repl_set = ReplicaSet().start()
     try:
         config_def = {
             'mainAddress': repl_set.uri,
             'oplogFile': from_here('lib', 'dummy.timestamp'),
             'docManagers': [
                 {
                     'docManager': 'solr_doc_manager',
                     'targetURL': solr_url,
                     'args': {
                         'clientOptions': {
                             'timeout': 100
                         }
                     }
                 }
             ]
         }
         config_obj = config.Config(get_config_options())
         config_obj.load_json(json.dumps(config_def))
         config_obj.parse_args(argv=[])
         conn = connector.Connector.from_config(config_obj)
         self.assertEqual(100, conn.doc_managers[0].solr.timeout)
     finally:
         repl_set.stop()
 def setUpClass(cls):
     """ Initializes the cluster
     """
     try:
         os.unlink("oplog.timestamp")
     except OSError:
         pass
     open("oplog.timestamp", "w").close()
     cls.repl_set = ReplicaSet().start()
    def setUpClass(cls):
        """ Initializes the cluster
        """
        try:
            os.unlink("oplog.timestamp")
        except OSError:
            pass
        open("oplog.timestamp", "w").close()

        cls.repl_set = ReplicaSet().start()
        cls.conn = cls.repl_set.client()
        cls.connector = Connector(mongo_address=cls.repl_set.uri,
                                  ns_set=['test.test'],
                                  **connector_opts)
        cls.synchronizer = cls.connector.doc_managers[0]
        cls.connector.start()
        assert_soon(lambda: len(cls.connector.shard_set) != 0)
Example #6
0
    def test_dump_collection(self):
        """Test the dump_collection method

        Cases:

        1. empty oplog
        2. non-empty oplog
        3. non-empty oplog, specified a namespace-set, none of the oplog
           entries are for collections in the namespace-set
        """

        # Test with empty oplog
        self.opman.oplog = self.primary_conn["test"]["emptycollection"]
        last_ts = self.opman.dump_collection()
        self.assertEqual(last_ts, None)

        # Test with non-empty oplog
        self.opman.oplog = self.primary_conn["local"]["oplog.rs"]
        for i in range(1000):
            self.primary_conn["test"]["test"].insert_one({"i": i + 500})
        last_ts = self.opman.get_last_oplog_timestamp()
        self.assertEqual(last_ts, self.opman.dump_collection())
        self.assertEqual(len(self.opman.doc_managers[0]._search()), 1000)

        # Case 3
        # 1MB oplog so that we can rollover quickly
        repl_set = ReplicaSet(oplogSize=1).start()
        conn = repl_set.client()
        opman = OplogThread(primary_client=conn,
                            doc_managers=(DocManager(), ),
                            oplog_progress_dict=LockingDict(),
                            ns_set=set(["test.test"]))
        # Insert a document into a ns_set collection
        conn["test"]["test"].insert_one({"test": 1})
        # Cause the oplog to rollover on a non-ns_set collection
        conn["test"]["ignored"].insert_many([{
            "test": "1" * 1024
        } for _ in range(1024)])
        self.assertIsNone(conn["local"]["oplog.rs"].find_one(
            {"ns": "test.test"}))
        last_ts = opman.get_last_oplog_timestamp()
        self.assertEqual(last_ts, opman.dump_collection())
        self.assertEqual(len(opman.doc_managers[0]._search()), 1)
 def setUpClass(cls):
     """Start the cluster."""
     super(TestElastic, cls).setUpClass()
     cls.repl_set = ReplicaSet().start()
     cls.conn = cls.repl_set.client()
Example #8
0
 def setUpClass(cls):
     SolrTestCase.setUpClass()
     cls.repl_set = ReplicaSet().start()
     cls.conn = cls.repl_set.client()
 def setUp(self):
     self.repl_set = ReplicaSet().start()
     self.primary_conn = self.repl_set.client()
     self.oplog_progress = LockingDict()
     self.opman = None
Example #10
0
 def setUp(self):
     self.repl_set = ReplicaSet().start()
     self.primary_conn = self.repl_set.client()
     self.oplog_coll = self.primary_conn.local['oplog.rs']
 def setUpClass(cls):
     # Start up a replica set and connect to it
     cls.repl_set = ReplicaSet().start()
     cls.main_connection = cls.repl_set.client()