Example #1
0
def test_add_log_with_activity(host, iterations, debug):
    log.info("Run add_log_with_activity test for {0} times".format(iterations))
    result = True
    hdb = historydb(host, debug)

    user = "******" + hex(random.randint(0, MAX_USER_NO))[2:]
    keys = set()

    begin_time = int(datetime.now().strftime('%s'))
    for _ in range(iterations):
        data = ''.join([hex(x)[2:] for x in random.sample(range(100), 100)])
        dt = datetime.now()
        if random.randint(0, 1) == 0:
            key = dt.strftime('%b_%d_%y')
            keys.add(key)
            log.debug("Writing '{0}' log to user '{1}' by key '{2}'".format(
                len(data), user, key))
            if hdb.add_log_with_activity(user=user, data=data, key=key) != 200:
                log.error('Failed add log by key')
                result = False
            else:
                logs[user + key] += data
                activity[key] += [user]
        else:
            time = int(dt.strftime("%s"))
            log.debug("Writing '{0}' log to user '{1}' by time '{2}'".format(
                len(data), user, time))
            if hdb.add_log_with_activity(user=user, data=data,
                                         time=time) != 200:
                log.error('Failed add log by timestamp')
                result = False
            else:
                day = int(time / (24 * 60 * 60))
                logs[user + str(day)] += data
                activity[day] += [user]
    end_time = int(datetime.now().strftime("%s"))

    log.info("Checking results")

    if not check_logs(hdb, user, keys=keys):
        result = False

    if not check_logs(hdb, user, begin_time=begin_time, end_time=end_time):
        result = False

    if not check_activity(hdb, keys=keys):
        result = False

    if not check_activity(hdb, begin_time=begin_time, end_time=end_time):
        result = False

    if result:
        log.info("Add_log_with_activity test successed")
    else:
        log.info("Add_log_with_activity failed")
    return result
Example #2
0
def test_ping(host, iterations, debug):
    log.info("Run test_ping")
    hdb = historydb(host, debug)
    res = hdb.ping()
    if res == 200:
        log.info("Ping test successed")
    else:
        log.error("Ping failed: {0}".format(res))
        log.info("Ping test failed")
    return res == 200
Example #3
0
def test_ping(host, iterations, debug):
    log.info("Run test_ping")
    hdb = historydb(host, debug)
    res = hdb.ping()
    if res == 200:
        log.info("Ping test successed")
    else:
        log.error("Ping failed: {0}".format(res))
        log.info("Ping test failed")
    return res == 200
Example #4
0
def test_add_log_with_activity(host, iterations, debug):
    log.info("Run add_log_with_activity test for {0} times".format(iterations))
    result = True
    hdb = historydb(host, debug)

    user = "******" + hex(random.randint(0, MAX_USER_NO))[2:]
    keys = set()

    begin_time = int(datetime.now().strftime('%s'))
    for _ in range(iterations):
        data = ''.join([hex(x)[2:] for x in random.sample(range(100), 100)])
        dt = datetime.now()
        if random.randint(0, 1) == 0:
            key = dt.strftime('%b_%d_%y')
            keys.add(key)
            log.debug("Writing '{0}' log to user '{1}' by key '{2}'".format(len(data), user, key))
            if hdb.add_log_with_activity(user=user, data=data, key=key) != 200:
                log.error('Failed add log by key')
                result = False
            else:
                logs[user + key] += data
                activity[key] += [user]
        else:
            time = int(dt.strftime("%s"))
            log.debug("Writing '{0}' log to user '{1}' by time '{2}'".format(len(data), user, time))
            if hdb.add_log_with_activity(user=user, data=data, time=time) != 200:
                log.error('Failed add log by timestamp')
                result = False
            else:
                day = int(time / (24 * 60 * 60))
                logs[user + str(day)] += data
                activity[day] += [user]
    end_time = int(datetime.now().strftime("%s"))

    log.info("Checking results")

    if not check_logs(hdb, user, keys=keys):
        result = False

    if not check_logs(hdb, user, begin_time=begin_time, end_time=end_time):
        result = False

    if not check_activity(hdb, keys=keys):
        result = False

    if not check_activity(hdb, begin_time=begin_time, end_time=end_time):
        result = False

    if result:
        log.info("Add_log_with_activity test successed")
    else:
        log.info("Add_log_with_activity failed")
    return result
Example #5
0
def test_add_activity(host, iterations, debug):
    log.info("Run add_activity test for {0} times".format(iterations))
    result = True
    hdb = historydb(host, debug)
    keys = set()

    begin_time = int(datetime.now().strftime('%s'))
    for _ in range(iterations):
        user = "******" + hex(random.randint(0, MAX_USER_NO))[2:]
        dt = datetime.now()
        if random.randint(0, 1) == 0:
            key = dt.strftime('%b_%d_%y')
            keys.add(key)
            if hdb.add_activity(user=user, key=key) != 200:
                log.error("Error while adding activity by keys")
            else:
                activity[key] += [user]
        else:
            time = int(dt.strftime("%s"))
            if hdb.add_activity(user=user, time=time) != 200:
                log.error("Error while adding activity by timestamp")
            else:
                day = int(time / (24 * 60 * 60))
                activity[day] += [user]
    end_time = int(datetime.now().strftime("%s"))

    log.info("Checking results")

    if not check_activity(hdb, keys=list(keys)):
        result = False

    if not check_activity(hdb, begin_time=begin_time, end_time=end_time):
        result = False

    if result:
        log.info("Add_activity test successed")
    else:
        log.info("Add_activity failed")
    return result
Example #6
0
def test_add_activity(host, iterations, debug):
    log.info("Run add_activity test for {0} times".format(iterations))
    result = True
    hdb = historydb(host, debug)
    keys = set()

    begin_time = int(datetime.now().strftime('%s'))
    for _ in range(iterations):
        user = "******" + hex(random.randint(0, MAX_USER_NO))[2:]
        dt = datetime.now()
        if random.randint(0, 1) == 0:
            key = dt.strftime('%b_%d_%y')
            keys.add(key)
            if hdb.add_activity(user=user, key=key) != 200:
                log.error("Error while adding activity by keys")
            else:
                activity[key] += [user]
        else:
            time = int(dt.strftime("%s"))
            if hdb.add_activity(user=user, time=time) != 200:
                log.error("Error while adding activity by timestamp")
            else:
                day = int(time / (24 * 60 * 60))
                activity[day] += [user]
    end_time = int(datetime.now().strftime("%s"))

    log.info("Checking results")

    if not check_activity(hdb, keys=list(keys)):
        result = False

    if not check_activity(hdb, begin_time=begin_time, end_time=end_time):
        result = False

    if result:
        log.info("Add_activity test successed")
    else:
        log.info("Add_activity failed")
    return result