当前位置: 首页>>代码示例>>Python>>正文


Python oplog_manager.OplogThread类代码示例

本文整理汇总了Python中mongo_connector.oplog_manager.OplogThread的典型用法代码示例。如果您正苦于以下问题:Python OplogThread类的具体用法?Python OplogThread怎么用?Python OplogThread使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了OplogThread类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_find_field

 def test_find_field(self):
     doc = {'a': {'b': {'c': 1}}}
     self.assertEqual(OplogThread._find_field('a', doc),
                      [(['a'], doc['a'])])
     self.assertEqual(OplogThread._find_field('a.b', doc),
                      [(['a', 'b'], doc['a']['b'])])
     self.assertEqual(OplogThread._find_field('a.b.c', doc),
                      [(['a', 'b', 'c'], doc['a']['b']['c'])])
     self.assertEqual(OplogThread._find_field('x', doc),
                      [])
     self.assertEqual(OplogThread._find_field('a.b.x', doc),
                      [])
开发者ID:sliwinski-milosz,项目名称:mongo-connector,代码行数:12,代码来源:test_filter_fields.py

示例2: test_find_field

 def test_find_field(self):
     doc = {"a": {"b": {"c": 1}}}
     self.assertEqual(OplogThread._find_field("a", doc), [(["a"], doc["a"])])
     self.assertEqual(
         OplogThread._find_field("a.b", doc), [(["a", "b"], doc["a"]["b"])]
     )
     self.assertEqual(
         OplogThread._find_field("a.b.c", doc),
         [(["a", "b", "c"], doc["a"]["b"]["c"])],
     )
     self.assertEqual(OplogThread._find_field("x", doc), [])
     self.assertEqual(OplogThread._find_field("a.b.x", doc), [])
开发者ID:mongodb-labs,项目名称:mongo-connector,代码行数:12,代码来源:test_filter_fields.py

示例3: test_dump_collection

    def test_dump_collection(self):
        """Test the dump_collection method

        Cases:

        1. empty oplog
        2. non-empty oplog, with gridfs collections
        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 with gridfs collections
        self.opman.oplog = self.primary_conn["local"]["oplog.rs"]
        # Insert 10 gridfs files
        for i in range(10):
            fs = gridfs.GridFS(self.primary_conn["gridfs"],
                               collection="test" + str(i))
            fs.put(b"hello world")
        # Insert 1000 documents
        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()), 1010)

        # Case 3
        # 1MB oplog so that we can rollover quickly
        repl_set = ReplicaSetSingle(oplogSize=1).start()
        conn = repl_set.client()
        opman = OplogThread(
            primary_client=conn,
            doc_managers=(DocManager(),),
            oplog_progress_dict=LockingDict(),
            namespace_config=NamespaceConfig(namespace_set=["test.test"]),
        )
        # Insert a document into an included collection
        conn["test"]["test"].insert_one({"test": 1})
        # Cause the oplog to rollover on a non-included collection
        while conn["local"]["oplog.rs"].find_one({"ns": "test.test"}):
            conn["test"]["ignored"].insert_many(
                [{"test": "1" * 1024} for _ in range(1024)])
        last_ts = opman.get_last_oplog_timestamp()
        self.assertEqual(last_ts, opman.dump_collection())
        self.assertEqual(len(opman.doc_managers[0]._search()), 1)
        conn.close()
        repl_set.stop()
开发者ID:cn3c3p,项目名称:mongo-connector,代码行数:53,代码来源:test_oplog_manager.py

示例4: test_dump_collection

    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 = ReplicaSetSingle(oplogSize=1).start()
        conn = repl_set.client()
        dest_mapping_stru = DestMapping(["test.test"], [], {})
        opman = OplogThread(
            primary_client=conn,
            doc_managers=(DocManager(),),
            oplog_progress_dict=LockingDict(),
            dest_mapping_stru=dest_mapping_stru,
            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
        while conn["local"]["oplog.rs"].find_one({"ns": "test.test"}):
            conn["test"]["ignored"].insert_many(
                [{"test": "1" * 1024} for _ in range(1024)])
        last_ts = opman.get_last_oplog_timestamp()
        self.assertEqual(last_ts, opman.dump_collection())
        self.assertEqual(len(opman.doc_managers[0]._search()), 1)
        conn.close()
        repl_set.stop()
开发者ID:sliwinski-milosz,项目名称:mongo-connector,代码行数:49,代码来源:test_oplog_manager.py

示例5: setUp

 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()
     )
开发者ID:ineo4j,项目名称:mongo-connector,代码行数:7,代码来源:test_oplog_manager.py

示例6: setUp

    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["test"]["mc"].drop()

        # Oplog thread
        doc_manager = DocManager()
        oplog_progress = LockingDict()
        self.opman = OplogThread(
            primary_client=self.main_conn,
            doc_managers=(doc_manager,),
            oplog_progress_dict=oplog_progress,
            ns_set=["test.mc"]
        )
开发者ID:XDestination,项目名称:mongo-connector,代码行数:30,代码来源:test_rollbacks.py

示例7: setUp

 def setUp(self):
     self.namespace_config = NamespaceConfig()
     self.opman = OplogThread(
         primary_client=self.primary_conn,
         doc_managers=(DocManager(),),
         oplog_progress_dict=LockingDict(),
         namespace_config=self.namespace_config,
     )
开发者ID:mongodb-labs,项目名称:mongo-connector,代码行数:8,代码来源:test_filter_fields.py

示例8: setUp

 def setUp(self):
     self.dest_mapping_stru = DestMapping([], [], {})
     self.opman = OplogThread(
         primary_client=self.primary_conn,
         doc_managers=(DocManager(),),
         oplog_progress_dict=LockingDict(),
         dest_mapping_stru=self.dest_mapping_stru
     )
开发者ID:sliwinski-milosz,项目名称:mongo-connector,代码行数:8,代码来源:test_filter_fields.py

示例9: test_skipped_oplog_entry_updates_checkpoint

    def test_skipped_oplog_entry_updates_checkpoint(self):
        repl_set = ReplicaSetSingle().start()
        conn = repl_set.client()
        opman = OplogThread(
            primary_client=conn,
            doc_managers=(DocManager(),),
            oplog_progress_dict=LockingDict(),
            namespace_config=NamespaceConfig(namespace_set=["test.test"]),
        )
        opman.start()

        # Insert a document into an included collection
        conn["test"]["test"].insert_one({"test": 1})
        last_ts = opman.get_last_oplog_timestamp()
        assert_soon(
            lambda: last_ts == opman.checkpoint,
            "OplogThread never updated checkpoint to non-skipped " "entry.",
        )
        self.assertEqual(len(opman.doc_managers[0]._search()), 1)

        # Make sure that the oplog thread updates its checkpoint on every
        # oplog entry.
        conn["test"]["ignored"].insert_one({"test": 1})
        last_ts = opman.get_last_oplog_timestamp()
        assert_soon(
            lambda: last_ts == opman.checkpoint,
            "OplogThread never updated checkpoint to skipped entry.",
        )
        opman.join()
        conn.close()
        repl_set.stop()
开发者ID:mongodb-labs,项目名称:mongo-connector,代码行数:31,代码来源:test_oplog_manager.py

示例10: reset_opman

 def reset_opman(self, include_ns=None, exclude_ns=None, dest_mapping=None):
     self.namespace_config = NamespaceConfig(namespace_set=include_ns,
                                             ex_namespace_set=exclude_ns,
                                             namespace_options=dest_mapping)
     self.opman = OplogThread(
         primary_client=self.primary_conn,
         doc_managers=(DocManager(),),
         oplog_progress_dict=LockingDict(),
         namespace_config=self.namespace_config
     )
开发者ID:cn3c3p,项目名称:mongo-connector,代码行数:10,代码来源:test_oplog_manager_wildcard.py

示例11: setUp

 def setUp(self):
     self.repl_set = ReplicaSetSingle().start()
     self.primary_conn = self.repl_set.client()
     self.oplog_coll = self.primary_conn.local['oplog.rs']
     self.dest_mapping_stru = DestMapping([], [], {})
     self.opman = OplogThread(
         primary_client=self.primary_conn,
         doc_managers=(DocManager(),),
         oplog_progress_dict=LockingDict(),
         dest_mapping_stru=self.dest_mapping_stru,
     )
开发者ID:sliwinski-milosz,项目名称:mongo-connector,代码行数:11,代码来源:test_oplog_manager.py

示例12: initOplogThread

 def initOplogThread(self, namespace_set=[], dest_mapping={}):
     self.docman = CommandLoggerDocManager()
     self.docman.command_helper = CommandHelper(namespace_set, dest_mapping)
     self.opman = OplogThread(
         primary_client=self.primary_conn,
         doc_managers=(self.docman,),
         oplog_progress_dict=self.oplog_progress,
         ns_set=namespace_set,
         dest_mapping=dest_mapping,
         collection_dump=False
     )
     self.opman.start()
开发者ID:XDestination,项目名称:mongo-connector,代码行数:12,代码来源:test_command_replication.py

示例13: setUp

 def setUp(self):
     self.repl_set = ReplicaSetSingle().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(),
         namespace_config=NamespaceConfig(
             namespace_options={"test.*": True, "gridfs.*": {"gridfs": True}}
         ),
     )
开发者ID:mongodb-labs,项目名称:mongo-connector,代码行数:12,代码来源:test_oplog_manager.py

示例14: initOplogThread

    def initOplogThread(self, namespace_set=None):
        self.docman = CommandLoggerDocManager()
        namespace_config = NamespaceConfig(namespace_set=namespace_set)

        self.docman.command_helper = CommandHelper(namespace_config)
        self.opman = OplogThread(
            primary_client=self.primary_conn,
            doc_managers=(self.docman,),
            oplog_progress_dict=self.oplog_progress,
            namespace_config=namespace_config,
            collection_dump=False
        )
        self.opman.start()
开发者ID:cn3c3p,项目名称:mongo-connector,代码行数:13,代码来源:test_command_replication.py

示例15: setUp

 def setUp(self):
     _, _, self.primary_p = start_replica_set("test-oplog-manager")
     self.primary_conn = pymongo.MongoClient(mongo_host, self.primary_p)
     self.oplog_coll = self.primary_conn.local["oplog.rs"]
     self.opman = OplogThread(
         primary_conn=self.primary_conn,
         main_address="%s:%d" % (mongo_host, self.primary_p),
         oplog_coll=self.oplog_coll,
         is_sharded=False,
         doc_manager=DocManager(),
         oplog_progress_dict=LockingDict(),
         namespace_set=None,
         auth_key=None,
         auth_username=None,
         repl_set="test-oplog-manager",
     )
开发者ID:huangchaosuper,项目名称:mongo-connector,代码行数:16,代码来源:test_oplog_manager.py


注:本文中的mongo_connector.oplog_manager.OplogThread类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。