• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python operations.multishard_find函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: test_multishard_skip

    def test_multishard_skip(self):
        doc1 = {'x': 1, 'y': 1}
        doc2 = {'x': 1, 'y': 2}
        doc3 = {'x': 2, 'y': 1}
        doc4 = {'x': 2, 'y': 2}
        self.db1.dummy.insert(doc1)
        self.db1.dummy.insert(doc2)
        self.db2.dummy.insert(doc3)
        self.db2.dummy.insert(doc4)

        results = operations.multishard_find(
            'dummy', {}, sort=[('x', 1), ('y', 1)]).skip(1)
        self.assertEquals([doc2, doc3, doc4], list(results))

        results = operations.multishard_find(
            'dummy', {}, sort=[('x', 1), ('y', 1)]).skip(2)
        self.assertEquals([doc3, doc4], list(results))

        results = operations.multishard_find(
            'dummy', {}, sort=[('x', 1), ('y', 1)]).skip(3)
        self.assertEquals([doc4], list(results))

        results = operations.multishard_find(
            'dummy', {}, sort=[('x', 1), ('y', 1)]).skip(4)
        self.assertEquals([], list(results))
开发者ID:alsuren,项目名称:shardmonster,代码行数:25,代码来源:test_operations.py


示例2: test_multishard_skip

    def test_multishard_skip(self):
        doc1 = {'x': 1, 'y': 1}
        doc2 = {'x': 1, 'y': 2}
        doc3 = {'x': 2, 'y': 1}
        doc4 = {'x': 2, 'y': 2}
        self.db1.dummy.insert(doc1)
        self.db1.dummy.insert(doc2)
        self.db2.dummy.insert(doc3)
        self.db2.dummy.insert(doc4)

        # TODO There is a bug here. The skip is done BEFORE the sory. Poo :(
        results = operations.multishard_find(
            'dummy', {}, sort=[('x', 1), ('y', 1)]).skip(1)
        results = list(results)
        self.assertEquals([doc2, doc3, doc4], results)

        results = operations.multishard_find(
            'dummy', {}, sort=[('x', 1), ('y', 1)]).skip(2)
        self.assertEquals([doc3, doc4], list(results))

        results = operations.multishard_find(
            'dummy', {}, sort=[('x', 1), ('y', 1)]).skip(3)
        self.assertEquals([doc4], list(results))

        results = operations.multishard_find(
            'dummy', {}, sort=[('x', 1), ('y', 1)]).skip(4)
        self.assertEquals([], list(results))
开发者ID:colinhowe,项目名称:shardmonster,代码行数:27,代码来源:test_operations.py


示例3: test_multishard_count_with_motion

    def test_multishard_count_with_motion(self):
        api.set_shard_at_rest('dummy', 1, "dest1/test_sharding")
        api.set_shard_at_rest('dummy', 2, "dest1/test_sharding")

        doc1 = {'x': 1, 'y': 1}
        doc2 = {'x': 1, 'y': 2}
        doc3 = {'x': 2, 'y': 1}
        doc4 = {'x': 2, 'y': 2}
        self.db1.dummy.insert(doc1)
        self.db1.dummy.insert(doc2)
        self.db1.dummy.insert(doc3)
        self.db1.dummy.insert(doc4)

        results = operations.multishard_find('dummy', {}).count()
        self.assertEquals(4, results)

        # Mimic the shard now being in the second location and there being
        # documents left here
        api.start_migration('dummy', 2, "dest2/test_sharding")
        api.set_shard_to_migration_status(
            'dummy', 2, api.ShardStatus.POST_MIGRATION_PAUSED_AT_DESTINATION)

        self.db2.dummy.insert(doc3)
        self.db2.dummy.insert(doc4)

        results = operations.multishard_find('dummy', {}).count()
        self.assertEquals(4, results)
开发者ID:alsuren,项目名称:shardmonster,代码行数:27,代码来源:test_operations.py


示例4: test_getitem_on_non_targetted_query

    def test_getitem_on_non_targetted_query(self):
        """This tests a bug that was found in a production environment. If a
        scatter-gather query is performed and data is only on one shard then if
        the queries are performed in a certain order the getitem will fail due
        to no results being found.
        """
        # Test db1 with all the data and db2 without any.
        self.db1.dummy.insert({'x': 1, 'y': 1})
        self.db1.dummy.insert({'x': 1, 'y': 2})
        expected = {'x': 1, 'y': 3}
        self.db1.dummy.insert(expected)

        result = operations.multishard_find('dummy', {})\
            .sort([('y', 1)])[2]
        self.assertEquals(result, expected)

        # Now test the other way around to ensure we capture all orderings.
        # Add a z field for querying to ensure db1 returns 0 results.
        self.db2.dummy.insert({'x': 2, 'y': 1, 'z': 1})
        self.db2.dummy.insert({'x': 2, 'y': 2, 'z': 1})
        expected = {'x': 2, 'y': 3, 'z': 1}
        self.db2.dummy.insert(expected)

        result = operations.multishard_find('dummy', {'z': 1})\
            .sort([('y', 1)])[2]
        self.assertEquals(result, expected)
开发者ID:alsuren,项目名称:shardmonster,代码行数:26,代码来源:test_operations.py


示例5: test_multishard_find_with_sort

    def test_multishard_find_with_sort(self):
        doc1 = {'x': 1, 'y': 1}
        doc2 = {'x': 1, 'y': 2}
        doc3 = {'x': 2, 'y': 1}
        doc4 = {'x': 2, 'y': 2}
        self.db1.dummy.insert(doc1)
        self.db1.dummy.insert(doc2)
        self.db2.dummy.insert(doc3)
        self.db2.dummy.insert(doc4)

        results = operations.multishard_find(
            'dummy', {}, sort=[('x', 1), ('y', 1)])
        self.assertEquals([doc1, doc2, doc3, doc4], list(results))

        results = operations.multishard_find(
            'dummy', {}, sort=[('x', -1), ('y', 1)])
        self.assertEquals([doc3, doc4, doc1, doc2], list(results))

        results = operations.multishard_find(
            'dummy', {}, sort=[('x', 1), ('y', -1)])
        self.assertEquals([doc2, doc1, doc4, doc3], list(results))

        results = operations.multishard_find(
            'dummy', {}, sort=[('x', -1), ('y', -1)])
        self.assertEquals([doc4, doc3, doc2, doc1], list(results))

        # Insert a document the same as doc4 to ensure sorts will cope with
        # things that are basically the same
        doc5 = {'x': 2, 'y': 2, 'z': 1}
        self.db2.dummy.insert(doc5)
        results = operations.multishard_find(
            'dummy', {}, sort=[('x', -1), ('y', -1)])
        results = results[:2]
        self.assertTrue(doc4 in results)
        self.assertTrue(doc5 in results)
开发者ID:alsuren,项目名称:shardmonster,代码行数:35,代码来源:test_operations.py


示例6: test_update

    def test_update(self):
        # Put the same document in multiple locations (a mid-migration status)
        # then do an update and ensure that only the correct place has been
        # updated.
        api.set_shard_at_rest('dummy', 1, "dest1/test_sharding")
        doc1 = {'x': 1, 'y': 1}
        self.db1.dummy.insert(doc1)

        api.start_migration('dummy', 1, 'dest2/test_sharding')
        api.set_shard_to_migration_status(
            'dummy', 1, api.ShardStatus.MIGRATING_COPY)
        self.db2.dummy.insert(doc1)

        result = operations.multishard_update('dummy', {}, {'$inc': {'y': 1}})
        self.assertEquals(1, result['n'])

        # Query the correct shard first and see that the counter has been
        # incremented
        result, = operations.multishard_find('dummy', {'x': 1})
        self.assertEquals(2, result['y'])

        # Now spoof the metadata such that the system thinks the data is on
        # shard2. The counter should still be 1 here.
        api.set_shard_at_rest('dummy', 1, "dest2/test_sharding", force=True)
        result, = operations.multishard_find('dummy', {'x': 1})
        self.assertEquals(1, result['y'])
开发者ID:alsuren,项目名称:shardmonster,代码行数:26,代码来源:test_operations.py


示例7: test_indexed_read

    def test_indexed_read(self):
        doc1 = {'x': 1, 'y': 1}
        doc2 = {'x': 2, 'y': 1}
        self.db1.dummy.insert(doc1)
        self.db2.dummy.insert(doc2)

        cursor = operations.multishard_find(
            'dummy', {'y': 1}, sort=[('x', 1), ('y', 1)])
        self.assertEquals(doc1, cursor[0])
        cursor = operations.multishard_find(
            'dummy', {'y': 1}, sort=[('x', -1), ('y', 1)])
        self.assertEquals(doc2, cursor[0])
开发者ID:alsuren,项目名称:shardmonster,代码行数:12,代码来源:test_operations.py


示例8: test_multishard_find_with_sort_as_single_arg

    def test_multishard_find_with_sort_as_single_arg(self):
        doc1 = {'x': 1, 'y': 1}
        doc2 = {'x': 2, 'y': 1}
        self.db1.dummy.insert(doc1)
        self.db2.dummy.insert(doc2)

        results = operations.multishard_find(
            'dummy', {}).sort('x', 1)
        self.assertEquals([doc1, doc2], list(results))

        results = operations.multishard_find(
            'dummy', {}).sort('x', -1)
        self.assertEquals([doc2, doc1], list(results))
开发者ID:alsuren,项目名称:shardmonster,代码行数:13,代码来源:test_operations.py


示例9: test_indexed_read

    def test_indexed_read(self):
        api.set_shard_at_rest('dummy', 1, 'dest1/test_sharding')
        api.set_shard_at_rest('dummy', 2, 'dest2/test_sharding')
        doc1 = {'x': 1, 'y': 1}
        doc2 = {'x': 2, 'y': 1}
        self.db1.dummy.insert(doc1)
        self.db2.dummy.insert(doc2)

        cursor = operations.multishard_find(
            'dummy', {'y': 1}, sort=[('x', 1), ('y', 1)])
        self.assertEquals(doc1, cursor[0])
        cursor = operations.multishard_find(
            'dummy', {'y': 1}, sort=[('x', -1), ('y', 1)])
        self.assertEquals(doc2, cursor[0])
开发者ID:c-oreills,项目名称:shardmonster,代码行数:14,代码来源:test_operations.py


示例10: test_multi_update

    def test_multi_update(self):
        # Test that an update will hit multiple clusters at once
        doc1 = {'x': 1, 'y': 1}
        doc2 = {'x': 2, 'y': 1}
        self.db1.dummy.insert(doc1)
        self.db2.dummy.insert(doc2)

        result = operations.multishard_update('dummy', {}, {'$inc': {'y': 1}})
        self.assertEquals(2, result['n'])

        result, = operations.multishard_find('dummy', {'x': 1})
        self.assertEquals(2, result['y'])

        result, = operations.multishard_find('dummy', {'x': 2})
        self.assertEquals(2, result['y'])
开发者ID:alsuren,项目名称:shardmonster,代码行数:15,代码来源:test_operations.py


示例11: test_alive

    def test_alive(self):
        api.set_shard_at_rest('dummy', 1, "dest1/test_sharding")
        doc1 = {'x': 1, 'y': 1}
        self.db1.dummy.insert(doc1)

        c = operations.multishard_find('dummy', {})
        self.assertTrue(c.alive)
开发者ID:alsuren,项目名称:shardmonster,代码行数:7,代码来源:test_operations.py


示例12: test_non_zero_indexing

    def test_non_zero_indexing(self):
        doc1 = {'x': 1, 'y': 1}
        doc2 = {'x': 2, 'y': 1}
        self.db1.dummy.insert(doc1)
        self.db2.dummy.insert(doc2)

        result = operations.multishard_find('dummy', {'y': 1})[1]
        self.assertEquals(doc2, result)
开发者ID:alsuren,项目名称:shardmonster,代码行数:8,代码来源:test_operations.py


示例13: test_multishard_find_with_sort_fn

    def test_multishard_find_with_sort_fn(self):
        doc1 = {'x': 1, 'y': 1}
        doc2 = {'x': 1, 'y': 2}
        doc3 = {'x': 2, 'y': 1}
        doc4 = {'x': 2, 'y': 2}
        self.db1.dummy.insert(doc1)
        self.db1.dummy.insert(doc2)
        self.db2.dummy.insert(doc3)
        self.db2.dummy.insert(doc4)

        results = operations.multishard_find(
            'dummy', {}).sort([('x', 1), ('y', 1)])
        self.assertEquals([doc1, doc2, doc3, doc4], list(results))

        results = operations.multishard_find(
            'dummy', {}).sort([('x', -1), ('y', 1)])
        self.assertEquals([doc3, doc4, doc1, doc2], list(results))
开发者ID:alsuren,项目名称:shardmonster,代码行数:17,代码来源:test_operations.py


示例14: test_skip_slice

    def test_skip_slice(self):
        doc1 = {'x': 1, 'y': 1}
        doc2 = {'x': 2, 'y': 1}
        self.db1.dummy.insert(doc1)
        self.db2.dummy.insert(doc2)

        c = operations.multishard_find('dummy', {'y': 1})[1:]
        results = sorted(list(c), key=lambda d: d['x'])
        self.assertEquals([doc2], results)
开发者ID:alsuren,项目名称:shardmonster,代码行数:9,代码来源:test_operations.py


示例15: test_multishard_find_args

    def test_multishard_find_args(self):
        doc1 = {'x': 1, 'y': 1}
        doc2 = {'x': 2, 'y': 1}
        self.db1.dummy.insert(doc1)
        self.db2.dummy.insert(doc2)

        c = operations.multishard_find('dummy', {'y': 1}, {'x': 1, '_id': 0})
        results = sorted(list(c), key=lambda d: d['x'])
        self.assertEquals([{'x': 1}, {'x': 2}], results)
开发者ID:alsuren,项目名称:shardmonster,代码行数:9,代码来源:test_operations.py


示例16: test_skip_beyond_limit

    def test_skip_beyond_limit(self):
        self.db1.dummy.insert({'x': 1, 'y': 1})
        self.db1.dummy.insert({'x': 1, 'y': 1})
        self.db1.dummy.insert({'x': 1, 'y': 1})
        self.db1.dummy.insert({'x': 1, 'y': 1})
        expected_doc = {'x': 2, 'y': 1}
        self.db2.dummy.insert(expected_doc)

        result = operations.multishard_find('dummy', {'y': 1}).limit(1).skip(4)
        self.assertEquals([expected_doc], list(result))
开发者ID:alsuren,项目名称:shardmonster,代码行数:10,代码来源:test_operations.py


示例17: test_multishard_find

    def test_multishard_find(self):
        api.set_shard_at_rest('dummy', 1, 'dest1/test_sharding')
        api.set_shard_at_rest('dummy', 2, 'dest2/test_sharding')
        doc1 = {'x': 1, 'y': 1}
        doc2 = {'x': 2, 'y': 1}
        self.db1.dummy.insert(doc1)
        self.db2.dummy.insert(doc2)

        c = operations.multishard_find('dummy', {'y': 1})
        results = sorted(list(c), key=lambda d: d['x'])
        self.assertEquals([doc1, doc2], results)
开发者ID:c-oreills,项目名称:shardmonster,代码行数:11,代码来源:test_operations.py


示例18: test_multishard_rewind

    def test_multishard_rewind(self):
        doc1 = {'x': 1, 'y': 1}
        doc2 = {'x': 2, 'y': 1}
        self.db1.dummy.insert(doc1)
        self.db2.dummy.insert(doc2)

        cursor = operations.multishard_find('dummy', {'y': 1}, sort=[('x', 1)])
        found = cursor.next()
        self.assertEquals((1, 1), (found['x'], found['y']))
        cursor.rewind()
        found = cursor.next()
        self.assertEquals((1, 1), (found['x'], found['y']))
开发者ID:alsuren,项目名称:shardmonster,代码行数:12,代码来源:test_operations.py


示例19: test_alive_with_sort

    def test_alive_with_sort(self):
        doc1 = {'x': 1, 'y': 1}
        doc2 = {'x': 2, 'y': 1}
        self.db1.dummy.insert(doc1)
        self.db2.dummy.insert(doc2)

        c = operations.multishard_find('dummy', {}).sort('x', 1)
        self.assertTrue(c.alive)
        c.next()
        self.assertTrue(c.alive)
        c.next()
        self.assertFalse(c.alive)
开发者ID:alsuren,项目名称:shardmonster,代码行数:12,代码来源:test_operations.py


示例20: test_multishard_find_with_limit_as_method

    def test_multishard_find_with_limit_as_method(self):
        doc1 = {'x': 1, 'y': 1}
        doc2 = {'x': 1, 'y': 2}
        doc3 = {'x': 2, 'y': 1}
        doc4 = {'x': 2, 'y': 2}
        self.db1.dummy.insert(doc1)
        self.db1.dummy.insert(doc2)
        self.db2.dummy.insert(doc3)
        self.db2.dummy.insert(doc4)

        results = operations.multishard_find('dummy', {}).limit(3)
        self.assertEquals(3, len(list(results)))
开发者ID:alsuren,项目名称:shardmonster,代码行数:12,代码来源:test_operations.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python util.IDObfuscator类代码示例发布时间:2022-05-27
下一篇:
Python api.set_shard_at_rest函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap