Ejemplo n.º 1
0
    def test_write_timeout_error_message(self):
        session = self.make_session()
        query = SimpleStatement("INSERT INFO foo (a, b) VALUES (1, 2)")
        query.retry_policy = Mock()
        query.retry_policy.on_write_timeout.return_value = (
            RetryPolicy.RETHROW, None)
        message = QueryMessage(query=query,
                               consistency_level=ConsistencyLevel.ONE)

        rf = ResponseFuture(session, message, query, 1)
        rf.send_request()

        result = Mock(spec=WriteTimeoutErrorMessage, info={})
        rf._set_result(None, None, None, result)
        self.assertRaises(Exception, rf.result)
Ejemplo n.º 2
0
    def test_add_callbacks(self):
        session = self.make_session()
        query = SimpleStatement("INSERT INFO foo (a, b) VALUES (1, 2)")
        query.retry_policy = Mock()
        query.retry_policy.on_unavailable.return_value = (RetryPolicy.RETHROW,
                                                          None)
        message = QueryMessage(query=query,
                               consistency_level=ConsistencyLevel.ONE)

        # test errback
        rf = ResponseFuture(session, message, query, 1)
        rf.send_request()

        rf.add_callbacks(callback=self.assertEqual,
                         callback_args=([{
                             'col': 'val'
                         }], ),
                         errback=self.assertIsInstance,
                         errback_args=(Exception, ))

        result = Mock(spec=UnavailableErrorMessage, info={})
        rf._set_result(None, None, None, result)
        self.assertRaises(Exception, rf.result)

        # test callback
        rf = ResponseFuture(session, message, query, 1)
        rf.send_request()

        callback = Mock()
        expected_result = (object(), object())
        arg = "positional"
        kwargs = {'one': 1, 'two': 2}
        rf.add_callbacks(callback=callback,
                         callback_args=(arg, ),
                         callback_kwargs=kwargs,
                         errback=self.assertIsInstance,
                         errback_args=(Exception, ))

        rf._set_result(
            None, None, None,
            self.make_mock_response(expected_result[0], expected_result[1]))
        self.assertEqual(rf.result()[0], expected_result)

        callback.assert_called_once_with([expected_result], arg, **kwargs)
Ejemplo n.º 3
0
 def make_response_future(self, session):
     query = SimpleStatement("SELECT * FROM foo")
     message = QueryMessage(query=query,
                            consistency_level=ConsistencyLevel.ONE)
     return ResponseFuture(session, message, query, 1)
 def _send_query_message(self, session, timeout, **kwargs):
     query = "SELECT * FROM test3rf.test"
     message = QueryMessage(query=query, **kwargs)
     future = ResponseFuture(session, message, query=None, timeout=timeout)
     future.send_request()
     return future