當前位置: 首頁>>代碼示例>>Python>>正文


Python CQLClient.execute方法代碼示例

本文整理匯總了Python中silverberg.client.CQLClient.execute方法的典型用法代碼示例。如果您正苦於以下問題:Python CQLClient.execute方法的具體用法?Python CQLClient.execute怎麽用?Python CQLClient.execute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在silverberg.client.CQLClient的用法示例。


在下文中一共展示了CQLClient.execute方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_cql_sequence

# 需要導入模塊: from silverberg.client import CQLClient [as 別名]
# 或者: from silverberg.client.CQLClient import execute [as 別名]
    def test_cql_sequence(self):
        """
        Test a sequence of operations results in only one handshake
        but two requests.

        """
        expected = [{"foo": "{P}"}]

        mockrow = [ttypes.CqlRow(key='blah', columns=[ttypes.Column(name='foo', value='{P}')])]
        self.mock_results = ttypes.CqlResult(
            type=ttypes.CqlResultType.ROWS, rows=mockrow,
            schema=ttypes.CqlMetadata(
                value_types={'foo': 'org.apache.cassandra.db.marshal.UTF8Type'}))
        client = CQLClient(self.endpoint, 'blah')

        def _cqlProc(r):
            return client.execute("SELECT :sel FROM test_blah", {"sel": "blah"},
                                  ConsistencyLevel.ONE)

        d = client.execute("SELECT :sel FROM test_blah", {"sel": "ffh"},
                           ConsistencyLevel.ONE)
        d.addCallback(_cqlProc)
        self.assertEqual(self.assertFired(d), expected)
        self.client_proto.execute_cql3_query.assert_any_call("SELECT 'blah' FROM test_blah", 2,
                                                             ConsistencyLevel.ONE)
        self.client_proto.execute_cql3_query.assert_any_call("SELECT 'ffh' FROM test_blah", 2,
                                                             ConsistencyLevel.ONE)
        self.client_proto.set_keyspace.assert_called_once_with('blah')
開發者ID:bmuller,項目名稱:silverberg,代碼行數:30,代碼來源:test_client.py

示例2: test_cql_insert

# 需要導入模塊: from silverberg.client import CQLClient [as 別名]
# 或者: from silverberg.client.CQLClient import execute [as 別名]
    def test_cql_insert(self):
        """Test a mock CQL insert with a VOID response works."""
        expected = None

        self.mock_results = ttypes.CqlResult(type=ttypes.CqlResultType.VOID)
        client = CQLClient(self.endpoint, "blah")

        d = client.execute("UPDATE blah SET 'key'='frr', 'fff'=1222 WHERE KEY='frr'", {}, ConsistencyLevel.ONE)
        self.assertEqual(self.assertFired(d), expected)
        self.client_proto.execute_cql3_query.assert_called_once_with(
            "UPDATE blah SET 'key'='frr', 'fff'=1222 WHERE KEY='frr'", 2, ConsistencyLevel.ONE
        )
        self.client_proto.set_keyspace.assert_called_once_with("blah")
開發者ID:harii,項目名稱:silverberg,代碼行數:15,代碼來源:test_client.py

示例3: test_cql_insert_vars

# 需要導入模塊: from silverberg.client import CQLClient [as 別名]
# 或者: from silverberg.client.CQLClient import execute [as 別名]
    def test_cql_insert_vars(self):
        """Test that a CQL insert that has variables works."""
        expected = None

        self.mock_results = ttypes.CqlResult(type=ttypes.CqlResultType.VOID)
        client = CQLClient(self.endpoint, 'blah')

        d = client.execute("UPDATE blah SET 'key'='frr', 'fff'=:val WHERE KEY='frr'", {"val": 1234},
                           ConsistencyLevel.ONE)
        self.assertEqual(self.assertFired(d), expected)
        self.client_proto.execute_cql3_query.assert_called_once_with(
            "UPDATE blah SET 'key'='frr', 'fff'=1234 WHERE KEY='frr'",
            2, ConsistencyLevel.ONE)
        self.client_proto.set_keyspace.assert_called_once_with('blah')
開發者ID:bmuller,項目名稱:silverberg,代碼行數:16,代碼來源:test_client.py

示例4: test_cql_value

# 需要導入模塊: from silverberg.client import CQLClient [as 別名]
# 或者: from silverberg.client.CQLClient import execute [as 別名]
    def test_cql_value(self):
        """
        Test that a CQL response that is an integer value is
        processed correctly (e.g. SELECT COUNT).

        """
        self.mock_results = ttypes.CqlResult(type=ttypes.CqlResultType.INT, num=1)
        client = CQLClient(self.endpoint, 'blah')

        d = client.execute("SELECT :sel FROM test_blah", {"sel": "blah"}, ConsistencyLevel.ONE)
        self.assertEqual(self.assertFired(d), 1)
        self.client_proto.execute_cql3_query.assert_called_once_with("SELECT 'blah' FROM test_blah", 2,
                                                                     ConsistencyLevel.ONE)
        self.client_proto.set_keyspace.assert_called_once_with('blah')
開發者ID:bmuller,項目名稱:silverberg,代碼行數:16,代碼來源:test_client.py

示例5: test_cql_array

# 需要導入模塊: from silverberg.client import CQLClient [as 別名]
# 或者: from silverberg.client.CQLClient import execute [as 別名]
    def test_cql_array(self):
        """Test that a full CQL response (e.g. SELECT) works."""
        expected = [{"foo": "{P}"}]

        mockrow = [ttypes.CqlRow(key='blah', columns=[ttypes.Column(name='foo', value='{P}')])]
        self.mock_results = ttypes.CqlResult(
            type=ttypes.CqlResultType.ROWS,
            rows=mockrow,
            schema=ttypes.CqlMetadata(value_types={'foo': 'org.apache.cassandra.db.marshal.UTF8Type'}))
        client = CQLClient(self.endpoint, 'blah')

        d = client.execute("SELECT :sel FROM test_blah", {"sel": "blah"}, ConsistencyLevel.ONE)
        self.assertEqual(self.assertFired(d), expected)
        self.client_proto.execute_cql3_query.assert_called_once_with("SELECT 'blah' FROM test_blah", 2,
                                                                     ConsistencyLevel.ONE)
        self.client_proto.set_keyspace.assert_called_once_with('blah')
開發者ID:bmuller,項目名稱:silverberg,代碼行數:18,代碼來源:test_client.py

示例6: test_cql_array_deserial

# 需要導入模塊: from silverberg.client import CQLClient [as 別名]
# 或者: from silverberg.client.CQLClient import execute [as 別名]
    def test_cql_array_deserial(self):
        """Make sure that values that need to be deserialized correctly are."""
        expected = [{"fff": 1222}]

        mockrow = [ttypes.CqlRow(key="blah", columns=[ttypes.Column(name="fff", value="\x04\xc6")])]
        self.mock_results = ttypes.CqlResult(
            type=ttypes.CqlResultType.ROWS,
            rows=mockrow,
            schema=ttypes.CqlMetadata(value_types={"fff": "org.apache.cassandra.db.marshal.IntegerType"}),
        )
        client = CQLClient(self.endpoint, "blah")

        d = client.execute("SELECT * FROM :tablename;", {"tablename": "blah"}, ConsistencyLevel.ONE)
        self.assertEqual(self.assertFired(d), expected)
        self.client_proto.execute_cql3_query.assert_called_once_with("SELECT * FROM 'blah';", 2, ConsistencyLevel.ONE)
        self.client_proto.set_keyspace.assert_called_once_with("blah")
開發者ID:harii,項目名稱:silverberg,代碼行數:18,代碼來源:test_client.py

示例7: test_no_disconnect_on_cancel

# 需要導入模塊: from silverberg.client import CQLClient [as 別名]
# 或者: from silverberg.client.CQLClient import execute [as 別名]
    def test_no_disconnect_on_cancel(self):
        """
        If not given, cancellation of running query should not try to disconnect
        the TCP connection
        """
        self.client_proto.execute_cql3_query.side_effect = lambda *_: defer.Deferred()
        client = CQLClient(self.endpoint, "abc", disconnect_on_cancel=False)
        client.disconnect = mock.Mock()

        d = client.execute("query", {}, ConsistencyLevel.ONE)

        self.assertNoResult(d)
        self.assertFalse(client.disconnect.called)

        d.cancel()
        self.failureResultOf(d, defer.CancelledError)
        self.assertFalse(client.disconnect.called)
開發者ID:harii,項目名稱:silverberg,代碼行數:19,代碼來源:test_client.py

示例8: test_disconnect_on_cancel_returns_correct_value

# 需要導入模塊: from silverberg.client import CQLClient [as 別名]
# 或者: from silverberg.client.CQLClient import execute [as 別名]
    def test_disconnect_on_cancel_returns_correct_value(self):
        """
        with disconnect_on_cancel=True, the value from execute_cql3_query is
        returned before cancellation
        """
        exec_d = defer.Deferred()
        self.client_proto.execute_cql3_query.side_effect = lambda *_: exec_d
        client = CQLClient(self.endpoint, "abc", disconnect_on_cancel=True)
        client.disconnect = mock.Mock()

        d = client.execute("query", {}, ConsistencyLevel.ONE)

        self.assertNoResult(d)
        self.assertFalse(client.disconnect.called)
        exec_d.callback(self.mock_results)
        self.assertEqual(self.successResultOf(d), 1)
        self.assertFalse(client.disconnect.called)
開發者ID:harii,項目名稱:silverberg,代碼行數:19,代碼來源:test_client.py

示例9: test_disconnect_on_cancel

# 需要導入模塊: from silverberg.client import CQLClient [as 別名]
# 或者: from silverberg.client.CQLClient import execute [as 別名]
    def test_disconnect_on_cancel(self):
        """
        If allowed, cancellation of running query will also try to disconnect
        the TCP connection
        """
        self.client_proto.execute_cql3_query.side_effect = lambda *_: defer.Deferred()
        client = CQLClient(self.endpoint, 'abc', disconnect_on_cancel=True)
        client.disconnect = mock.Mock()

        d = client.execute('query', {}, ConsistencyLevel.ONE)

        self.assertNoResult(d)
        self.assertFalse(client.disconnect.called)

        d.cancel()
        self.failureResultOf(d, defer.CancelledError)
        client.disconnect.assert_called_one_with()
開發者ID:TimothyZhang,項目名稱:silverberg,代碼行數:19,代碼來源:test_client.py

示例10: test_unsupported_types_are_returned_as_bytes

# 需要導入模塊: from silverberg.client import CQLClient [as 別名]
# 或者: from silverberg.client.CQLClient import execute [as 別名]
    def test_unsupported_types_are_returned_as_bytes(self):
        """
        When a table includes a column of a type that is not explicitly
        supported we should return the raw bytes instead of attempting to
        unmarshal the data.
        """
        mock_rows = [ttypes.CqlRow(key="", columns=[ttypes.Column(name="an_unknown_type", value="\x00\x01")])]

        self.mock_results = ttypes.CqlResult(
            type=ttypes.CqlResultType.ROWS,
            rows=mock_rows,
            schema=ttypes.CqlMetadata(value_types={"an_unknown_type": "an.unknown.type"}),
        )

        client = CQLClient(self.endpoint, "blah")
        d = client.execute("SELECT * FROM blah", {}, ConsistencyLevel.ONE)
        results = self.assertFired(d)

        self.assertEqual(results, [{"an_unknown_type": "\x00\x01"}])
開發者ID:harii,項目名稱:silverberg,代碼行數:21,代碼來源:test_client.py

示例11: test_cql_list_deserial

# 需要導入模塊: from silverberg.client import CQLClient [as 別名]
# 或者: from silverberg.client.CQLClient import execute [as 別名]
    def test_cql_list_deserial(self):
        expected = [{"fff": ["ggg", "hhh"]}]

        mockrow = [
            ttypes.CqlRow(key="blah", columns=[ttypes.Column(name="fff", value="\x00\x02\x00\x03ggg\x00\x03hhh")])
        ]

        list_type = "org.apache.cassandra.db.marshal.ListType"
        text_type = "org.apache.cassandra.db.marshal.UTF8Type"
        text_list_type = list_type + "(" + text_type + ")"

        self.mock_results = ttypes.CqlResult(
            type=ttypes.CqlResultType.ROWS, rows=mockrow, schema=ttypes.CqlMetadata(value_types={"fff": text_list_type})
        )
        client = CQLClient(self.endpoint, "blah")

        d = client.execute("SELECT * FROM :tablename;", {"tablename": "blah"}, ConsistencyLevel.ONE)
        self.assertEqual(self.assertFired(d), expected)
        self.client_proto.execute_cql3_query.assert_called_once_with("SELECT * FROM 'blah';", 2, ConsistencyLevel.ONE)
        self.client_proto.set_keyspace.assert_called_once_with("blah")
開發者ID:harii,項目名稱:silverberg,代碼行數:22,代碼來源:test_client.py

示例12: test_cql_result_metadata

# 需要導入模塊: from silverberg.client import CQLClient [as 別名]
# 或者: from silverberg.client.CQLClient import execute [as 別名]
    def test_cql_result_metadata(self):
        """
        execute should use the metadata included with the CqlResult for
        deserializing values.
        """
        expected = [{"foo": UUID("114b8328-d1f1-11e2-8683-000c29bc9473")}]

        mockrow = [
            ttypes.CqlRow(
                key="blah",
                columns=[ttypes.Column(name="foo", value="\x11K\x83(\xd1\xf1\x11\xe2\x86\x83\x00\x0c)\xbc\x94s")],
            )
        ]

        self.mock_results = ttypes.CqlResult(
            type=ttypes.CqlResultType.ROWS,
            rows=mockrow,
            schema=ttypes.CqlMetadata(value_types={"foo": "org.apache.cassandra.db.marshal.TimeUUIDType"}),
        )

        client = CQLClient(self.endpoint, "blah")
        d = client.execute("SELECT * FROM blah;", {}, ConsistencyLevel.ONE)
        self.assertEqual(self.assertFired(d), expected)
開發者ID:harii,項目名稱:silverberg,代碼行數:25,代碼來源:test_client.py


注:本文中的silverberg.client.CQLClient.execute方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。