Ejemplo n.º 1
0
 def test_set_log_handler_with_non_callables(self, callback):
     '''
     Test whether a non callable may be set as the log function
     '''
     aerospike.set_log_level(aerospike.LOG_LEVEL_DEBUG)
     with pytest.raises(e.ParamError):
         aerospike.set_log_handler(callback)
Ejemplo n.º 2
0
 def test_set_log_handler_with_non_callables(self, callback):
     '''
     Test whether a non callable may be set as the log function
     '''
     aerospike.set_log_level(aerospike.LOG_LEVEL_DEBUG)
     with pytest.raises(e.ParamError):
         aerospike.set_log_handler(callback)
Ejemplo n.º 3
0
    def test_set_log_handler_extra_parameter(self):
        """
        Test log handler with extra parameter
        """
        aerospike.set_log_level(aerospike.LOG_LEVEL_DEBUG)

        with pytest.raises(TypeError) as typeError:
            aerospike.set_log_handler(handler, extrahandler)

        assert "setLogHandler() takes at most 1 argument (2 given)" in str(
            typeError.value)
Ejemplo n.º 4
0
    def test_set_log_handler_extra_parameter(self):
        """
        Test log handler with extra parameter
        """
        aerospike.set_log_level(aerospike.LOG_LEVEL_DEBUG)

        with pytest.raises(TypeError) as typeError:
            aerospike.set_log_handler(handler, extrahandler)

        assert "setLogHandler() takes at most 1 argument (2 given)" in str(
            typeError.value)
    def test_set_log_handler_correct(self):
        """
        Test log handler with correct parameters
        """

        response = aerospike.set_log_level(aerospike.LOG_LEVEL_DEBUG)
        aerospike.set_log_handler(handler)

        # Forces an event to be logged
        client = TestBaseClass.get_new_connection()

        assert response == 0
        client.close()
Ejemplo n.º 6
0
    def test_set_log_handler_correct(self):
        """
        Test log handler with correct parameters
        """

        response = aerospike.set_log_level(aerospike.LOG_LEVEL_DEBUG)
        aerospike.set_log_handler(handler)

        # Forces an event to be logged
        client = TestBaseClass.get_new_connection()

        assert response == 0
        client.close()
    def test_set_log_handler_correct(self):
        """
        Test log handler with correct parameters
        """

        response = aerospike.set_log_level(aerospike.LOG_LEVEL_DEBUG)

        aerospike.set_log_handler(handler)

        config = {
                "hosts": [("127.0.0.1", 3000)]
                }
        client = aerospike.client(config).connect()

        assert response == 0
        client.close()
    def test_set_log_handler_extra_parameter(self):
        """
        Test log handler with extra parameter
        """

        aerospike.set_log_level(aerospike.LOG_LEVEL_DEBUG)

        def handler(level, func, myfile, line):
            print "Level is: %d" % level

        def extrahandler(level, func, myfile, line):
            print "Level is: %d" % level

        with pytest.raises(TypeError) as typeError:
            aerospike.set_log_handler(handler, extrahandler)

        assert "setLogHandler() takes at most 1 argument (2 given)" in typeError.value
Ejemplo n.º 9
0
    def test_set_log_handler_correct(self):
        """
        Test log handler with correct parameters
        """

        response = aerospike.set_log_level(aerospike.LOG_LEVEL_DEBUG)
        aerospike.set_log_handler(handler)

        hostlist, user, password = TestBaseClass.get_hosts()
        config = {"hosts": hostlist}
        if user is None and password is None:
            client = aerospike.client(config).connect()
        else:
            client = aerospike.client(config).connect(user, password)

        assert response == 0
        client.close()
Ejemplo n.º 10
0
    def test_log_handler_raising_error(self):
        '''
        Test for handling of a log handler which raises an error
        '''
        aerospike.set_log_level(aerospike.LOG_LEVEL_DEBUG)
        aerospike.set_log_handler(error_raising_handler)
        with pytest.raises(SystemError):
            hostlist, user, password = TestBaseClass.get_hosts()
            config = {"hosts": hostlist}
            if user is None and password is None:
                client = aerospike.client(config).connect()
            else:
                client = aerospike.client(config).connect(user, password)

        try:
            client.close()  # Close the client if it got opened
        except:
            pass
Ejemplo n.º 11
0
    def test_set_log_handler_correct(self):
        """
        Test log handler with correct parameters
        """

        response = aerospike.set_log_level(aerospike.LOG_LEVEL_DEBUG)
        aerospike.set_log_handler(handler)

        hostlist, user, password = TestBaseClass.get_hosts()
        config = {
            "hosts": hostlist
        }
        if user is None and password is None:
            client = aerospike.client(config).connect()
        else:
            client = aerospike.client(config).connect(user, password)

        assert response == 0
        client.close()
Ejemplo n.º 12
0
    def test_log_handler_raising_error(self):
        '''
        Test for handling of a log handler which raises an error
        '''
        aerospike.set_log_level(aerospike.LOG_LEVEL_DEBUG)
        aerospike.set_log_handler(error_raising_handler)
        with pytest.raises(SystemError):
            hostlist, user, password = TestBaseClass.get_hosts()
            config = {
                "hosts": hostlist
            }
            if user is None and password is None:
                client = aerospike.client(config).connect()
            else:
                client = aerospike.client(config).connect(user, password)

        try:
            client.close()  # Close the client if it got opened
        except:
            pass
Ejemplo n.º 13
0
    def test_incorrect_prototype_callback(self):
        """
        Test that having a callback which takes the wrong number
        of args, will raise an error on methods which trigger
        logging
        """
        aerospike.set_log_level(aerospike.LOG_LEVEL_DEBUG)
        aerospike.set_log_handler(wrong_args_handler)

        with pytest.raises(SystemError):
            hostlist, user, password = TestBaseClass.get_hosts()
            config = {"hosts": hostlist}
            if user is None and password is None:
                client = aerospike.client(config).connect()
            else:
                client = aerospike.client(config).connect(user, password)

        try:
            client.close()  # Close the client if it got opened
        except:
            pass
Ejemplo n.º 14
0
    def test_incorrect_prototype_callback(self):
        """
        Test that having a callback which takes the wrong number
        of args, will raise an error on methods which trigger
        logging
        """
        aerospike.set_log_level(aerospike.LOG_LEVEL_DEBUG)
        aerospike.set_log_handler(wrong_args_handler)

        with pytest.raises(SystemError):
            hostlist, user, password = TestBaseClass.get_hosts()
            config = {
                "hosts": hostlist
            }
            if user is None and password is None:
                client = aerospike.client(config).connect()
            else:
                client = aerospike.client(config).connect(user, password)

        try:
            client.close()  # Close the client if it got opened
        except:
            pass
Ejemplo n.º 15
0
import os
import aerospike

THIS_DIR = os.path.abspath(os.path.dirname(__file__))


def log_callback(level, func, path, line, msg):
    print("[{}] {}".format(func, msg))


if __name__ == "__main__":

    # Setup debug logging in the Aerospike client to help with troubleshooting
    aerospike.set_log_level(aerospike.LOG_LEVEL_DEBUG)
    aerospike.set_log_handler(log_callback)

    config = {
        # The 'tls-name' (third element in tuple) must be specified when using
        # TLS. The 'tls-name' must match the Common Name (CN) or a Subject
        # Alternative Name (SAN) found in the certificate.
        'hosts': [('127.0.0.1', 4000, 'example.server')],
        'tls': {
            # TLS must be explicitly enabled
            'enable':
            True,

            # The CA certificate can alternatively be installed in the system
            # trusted CA certificate directory if security requirements allow
            # system-wide CA trust.
            'cafile':
            os.path.join(THIS_DIR, '..', 'certs', 'example.ca.crt'),
Ejemplo n.º 16
0
 def teardown_class(cls):
     '''
     Set the class level logger to a no-op to ensure no problems later
     '''
     aerospike.set_log_handler(valid_handler)
Ejemplo n.º 17
0
 def teardown_class(cls):
     '''
     Set the class level logger to a no-op to ensure no problems later
     '''
     aerospike.set_log_handler(valid_handler)