ARGS = PARSER.parse_args()

    # we are making some assumptions in here:
    # every location is named 'location<id>' and its TCP port (8080)
    # is mapped to the host port '10000+<id>'
    NODES = dict(("location%d" % idx, 10000 + idx) for idx in xrange(1, ARGS.locations + 1))
    OPS = [CounterOperation() for _ in xrange(ARGS.runners)]

    interact.wait_to_be_running(HOST, NODES)

    INITIAL_COUNTER = check_counters(NODES)
    if INITIAL_COUNTER is None:
        sys.exit(1)

    if not interact.requests_with_chaos(
        OPS, HOST, NODES, ARGS.iterations, ARGS.interval, ARGS.settle, ARGS.delay, ARGS.restarts
    ):
        sys.exit(1)

    DIFF = sum(op.get_counter() for op in OPS)
    COUNTER_VALUE = check_counters(NODES)

    if COUNTER_VALUE is None:
        sys.exit(1)
    else:
        print("All %d nodes converged to the counter value: %d" % (len(NODES), COUNTER_VALUE))

    EXPECTED_VALUE = INITIAL_COUNTER + DIFF
    if COUNTER_VALUE != EXPECTED_VALUE:
        print("Expected counter value: %d; actual %d" % (EXPECTED_VALUE, COUNTER_VALUE))
        sys.exit(0)
                print("Difference: %s; %s" % (node_set.difference(other_set), other_set.difference(node_set)))
                return False
        SETS[node] = node_set
    return True


class SetOperation(interact.Operation):

    def operation(self, idx, state):
        op = random.choice(['add', 'remove'])
        value = random.randint(1, MAX_VALUE)
        return '%s %d' % (op, value)


if __name__ == '__main__':
    PARSER = argparse.ArgumentParser(description='start CRDT ORSet chaos test')
    PARSER.add_argument('-i', '--iterations', type=int, default=5)
    PARSER.add_argument('--interval', type=float, default=0.1)
    PARSER.add_argument('--settle', type=int, default=60)

    ARGS = PARSER.parse_args()
    NODES = {'location1': 10001, 'location2': 10002, 'location3': 10003}
    OP = SetOperation()

    if not interact.requests_with_chaos(OP, HOST, NODES, ARGS.iterations, ARGS.interval, ARGS.settle):
        sys.exit(1)

    # validate current set values
    if not compare_sets(NODES):
        sys.exit(1)
    SETTLE_TIMEOUT = 30
    PARSER = argparse.ArgumentParser(description='start CRDT-counter chaos test')
    PARSER.add_argument('-i', '--iterations', type=int, default=30)
    PARSER.add_argument('--interval', type=float, default=0.1)
    PARSER.add_argument('-l', '--locations', type=int, default=3)
    PARSER.add_argument('-d', '--delay', type=int, default=10)

    ARGS = PARSER.parse_args()

    # we are making some assumptions in here:
    # every location is named 'location<id>' and its TCP port (8080)
    # is mapped to the host port '10000+<id>'
    NODES = dict(('location%d' % idx, 10000+idx) for idx in xrange(1, ARGS.locations+1))
    OP = CounterOperation()

    if not interact.requests_with_chaos(OP, HOST, NODES, ARGS.iterations, ARGS.interval, SETTLE_TIMEOUT, ARGS.delay):
        sys.exit(1)

    EXPECTED_VALUE = OP.get_counter()
    COUNTER_VALUE = check_counters(NODES)

    if COUNTER_VALUE is None:
        sys.exit(1)
    else:
        print('All %d nodes converged to the counter value: %d' % (len(NODES), COUNTER_VALUE))

    if COUNTER_VALUE != EXPECTED_VALUE:
        print('Expected counter value: %d; actual %d' % (EXPECTED_VALUE, COUNTER_VALUE))
        sys.exit(1)

    print('Counter value (%d) matches up correctly' % EXPECTED_VALUE)
    PARSER.add_argument('-i', '--iterations', type=int, default=30)
    PARSER.add_argument('--interval', type=float, default=0.1)
    PARSER.add_argument('-l', '--locations', type=int, default=3)
    PARSER.add_argument('-d', '--delay', type=int, default=10)

    ARGS = PARSER.parse_args()

    # we are making some assumptions in here:
    # every location is named 'location<id>' and its TCP port (8080)
    # is mapped to the host port '10000+<id>'
    NODES = dict(('location%d' % idx, 10000 + idx)
                 for idx in xrange(1, ARGS.locations + 1))
    OP = CounterOperation()

    if not interact.requests_with_chaos(OP, HOST, NODES, ARGS.iterations,
                                        ARGS.interval, SETTLE_TIMEOUT,
                                        ARGS.delay):
        sys.exit(1)

    EXPECTED_VALUE = OP.get_counter()
    COUNTER_VALUE = check_counters(NODES)

    if COUNTER_VALUE is None:
        sys.exit(1)
    else:
        print('All %d nodes converged to the counter value: %d' %
              (len(NODES), COUNTER_VALUE))

    if COUNTER_VALUE != EXPECTED_VALUE:
        print('Expected counter value: %d; actual %d' %
              (EXPECTED_VALUE, COUNTER_VALUE))
Beispiel #5
0
    # we are making some assumptions in here:
    # every location is named 'location<id>' and its TCP port (8080)
    # is mapped to the host port '10000+<id>'
    NODES = dict(('location%d' % idx, 10000 + idx)
                 for idx in xrange(1, ARGS.locations + 1))
    OPS = [CounterOperation() for _ in xrange(ARGS.runners)]

    interact.wait_to_be_running(HOST, NODES)

    INITIAL_COUNTER = check_counters(NODES)
    if INITIAL_COUNTER is None:
        sys.exit(1)

    if not interact.requests_with_chaos(OPS, HOST, NODES, ARGS.iterations,
                                        ARGS.interval, ARGS.settle, ARGS.delay,
                                        ARGS.restarts):
        sys.exit(1)

    DIFF = sum(op.get_counter() for op in OPS)
    COUNTER_VALUE = check_counters(NODES)

    if COUNTER_VALUE is None:
        sys.exit(1)
    else:
        print('All %d nodes converged to the counter value: %d' %
              (len(NODES), COUNTER_VALUE))

    EXPECTED_VALUE = INITIAL_COUNTER + DIFF
    if COUNTER_VALUE != EXPECTED_VALUE:
        print('Expected counter value: %d; actual %d' %