Exemplo n.º 1
0
def master_slave():
    master = RedisServer(address="127.0.0.1", port=1234)
    slave = RedisServer(unix_socket="/tmp/redis.socket", master=master)

    filter = Logs(redis_server=slave)
    filter.configure(FLOGS_CONF_TEMPLATE)
    filter.start()

    try:
        filter.log(b'It s dangerous out there. Take this sword.')
    except Exception:
        logging.error("master_slave: Could not connect to logs filter")
        return False

    sleep(1)

    numberMaster = master.get_number_of_connections()
    numberSlave = slave.get_number_of_connections()

    # master : python client, filter connection, slave ping
    # slave : python client, filter connection, master ping
    if numberMaster != 3 and numberSlave != 2:
        logging.error("master_slave: expected 2 master and 1 slave connections, but got " + str(numberMaster) + " and " + str(numberSlave))
        return False

    return True
Exemplo n.º 2
0
def multi_thread_master():
    master = RedisServer(unix_socket="/tmp/redis.socket")

    filter = Logs(redis_server=master, nb_threads=5)
    filter.configure(FLOGS_CONF_TEMPLATE)
    filter.start()

    thread_list = []
    def thread_brute(filter, count_log):
        for count in range(0, count_log):
            try:
                filter.log(b'All work and no play makes Jake a dull boy.')
            except:
                return False
        return True


    for num in range(0, 5):
        thread_list.append(threading.Thread(target=thread_brute, args=(filter, 50)))

    for thread in thread_list:
        thread.start()

    for thread in thread_list:
        thread.join()

    sleep(1)

    number = master.get_number_of_connections()

    if number != 6:
        logging.error("master_timeout: wrong number active connections: expected 6 but got " + str(number))
        return False
    return True
Exemplo n.º 3
0
def master_slave_master_off():
    master = RedisServer(address="127.0.0.1", port=1234)
    slave = RedisServer(unix_socket="/tmp/redis.socket", master=master)

    filter = Logs(redis_server=slave)
    filter.configure(FLOGS_CONF_TEMPLATE)
    master.stop()

    filter.start()

    try:
        filter.log(b'It s dangerous out there. Take this sword.')
    except Exception:
        logging.error("master_slave_master_off: Could not connect to logs filter")
        return False

    if not filter.check_run():
        logging.error("master_slave_master_off: filter seems to have crashed when master Redis got offline")
        return False

    sleep(1)

    number = slave.get_number_of_connections()

    if number != 2:
        logging.error("master_slave_master_off: filter is not connected to slave")
        return False

    return True
Exemplo n.º 4
0
def master_timeout_restart():
    master = RedisServer(unix_socket="/tmp/redis.socket")

    filter = Logs(redis_server=master)
    filter.configure(FLOGS_CONF_TEMPLATE)
    filter.start()

    try:
        filter.log(b'The cake is a lie')
    except Exception:
        logging.error("master_timeout: Could not connect to logs filter")
        return False

    # Wait for Janitor to consider connection has timed out and disconnect
    sleep(25)

    number = master.get_number_of_connections()

    if number != 1:
        logging.error("master_timeout: wrong number active connections: expected 1 but got " + str(number))
        return False

    try:
        filter.log(b'The cake is a lie')
    except Exception:
        logging.error("master_timeout: Could not connect to logs filter")
        return False

    sleep(1)

    number = master.get_number_of_connections()

    if number != 2:
        logging.error("master_timeout: wrong number active connections: expected 2 but got " + str(number))
        return False

    return True
Exemplo n.º 5
0
def simple_master_server():
    master = RedisServer(unix_socket="/tmp/redis.socket")

    filter = Logs(redis_server=master)
    filter.configure(FLOGS_CONF_TEMPLATE)
    filter.start()

    try:
        filter.log(b'The cake is a lie')
    except Exception:
        logging.error("simple_master_server: Could not connect to logs filter")
        return False

    sleep(1)

    number = master.get_number_of_connections()

    if number != 2:
        logging.error("simple_master_server: wrong number active connections: expected 2 but got " + str(number))
        return False

    return True
Exemplo n.º 6
0
def multi_thread_master():
    master = RedisServer(unix_socket=REDIS_SOCKET_PATH)

    filter = Filter(filter_name='test', nb_threads=5)
    filter.configure(FTEST_CONF_TEMPLATE)
    filter.valgrind_start()

    thread_list = []

    def thread_brute(filter, count_log):
        for count in range(0, count_log):
            try:
                filter.send_single(REDIS_LIST_TRIGGER)
            except:
                return False
        return True

    for num in range(0, 5):
        thread_list.append(
            threading.Thread(target=thread_brute, args=(filter, 500)))

    for thread in thread_list:
        thread.start()

    for thread in thread_list:
        thread.join()

    sleep(1)

    number = master.get_number_of_connections()

    # 5 threads
    if number != 5:
        logging.error(
            "multi_thread_master: wrong number of active connections: expected 5 but got "
            + str(number))
        return False

    return True