diff options
author | Joshua Harlow <harlowja@yahoo-inc.com> | 2014-09-18 17:13:43 -0700 |
---|---|---|
committer | Joshua Harlow <harlowja@yahoo-inc.com> | 2014-09-19 11:57:56 -0700 |
commit | fd730c42a32c5c597dd08e496c6a33c7faa579f4 (patch) | |
tree | a32aa06ec4039bb98c0183a51886de70afbaf51d | |
parent | 0df6d848ea733fbe0f732e1132687c9e14b668b2 (diff) | |
download | tooz-fd730c42a32c5c597dd08e496c6a33c7faa579f4.tar.gz |
Have examples run in the py27 environment and make them work
It is great to ensure that the examples that tooz has actually run
during testing time, so enable this as well as adjust the examples
to create unique group ids and run for a limited amount of time instead
of running forever (and fix a few other brokeness)...
Change-Id: I573cf5946a1d3f13862c0c28cf3a5d7fc6178873
-rw-r--r-- | examples/coordinator.py | 2 | ||||
-rw-r--r-- | examples/coordinator_heartbeat.py | 5 | ||||
-rw-r--r-- | examples/group_membership.py | 11 | ||||
-rw-r--r-- | examples/group_membership_watch.py | 12 | ||||
-rw-r--r-- | examples/leader_election.py | 20 | ||||
-rwxr-xr-x | run-examples.sh | 10 | ||||
-rw-r--r-- | tox.ini | 1 |
7 files changed, 46 insertions, 15 deletions
diff --git a/examples/coordinator.py b/examples/coordinator.py index 8850115..6d5cf03 100644 --- a/examples/coordinator.py +++ b/examples/coordinator.py @@ -1,5 +1,5 @@ from tooz import coordination -coordinator = coordination.get_coordinator('zookeeper://localhost', b'host-1') +coordinator = coordination.get_coordinator('kazoo://localhost', b'host-1') coordinator.start() coordinator.stop() diff --git a/examples/coordinator_heartbeat.py b/examples/coordinator_heartbeat.py index 7f8c81b..8b0659f 100644 --- a/examples/coordinator_heartbeat.py +++ b/examples/coordinator_heartbeat.py @@ -2,10 +2,13 @@ import time from tooz import coordination +ALIVE_TIME = 5 + coordinator = coordination.get_coordinator('memcached://localhost', b'host-1') coordinator.start() -while True: +start = time.time() +while time.time() - start < ALIVE_TIME: coordinator.heartbeat() time.sleep(0.1) diff --git a/examples/group_membership.py b/examples/group_membership.py index 963bbb3..58adb2d 100644 --- a/examples/group_membership.py +++ b/examples/group_membership.py @@ -1,14 +1,19 @@ +import uuid + +import six + from tooz import coordination -coordinator = coordination.get_coordinator('zookeeper://localhost', b'host-1') +coordinator = coordination.get_coordinator('kazoo://localhost', b'host-1') coordinator.start() # Create a group -request = coordinator.create_group(b"my group") +group = six.binary_type(six.text_type(uuid.uuid4()).encode('ascii')) +request = coordinator.create_group(group) request.get() # Join a group -request = coordinator.join_group(b"my group") +request = coordinator.join_group(group) request.get() coordinator.stop() diff --git a/examples/group_membership_watch.py b/examples/group_membership_watch.py index 5204df2..28b786f 100644 --- a/examples/group_membership_watch.py +++ b/examples/group_membership_watch.py @@ -1,10 +1,15 @@ +import uuid + +import six + from tooz import coordination -coordinator = coordination.get_coordinator('zookeeper://localhost', b'host-1') +coordinator = coordination.get_coordinator('kazoo://localhost', b'host-1') coordinator.start() # Create a group -request = coordinator.create_group(b"my group") +group = six.binary_type(six.text_type(uuid.uuid4()).encode('ascii')) +request = coordinator.create_group(group) request.get() @@ -13,6 +18,5 @@ def group_joined(event): print(event.group_id, event.member_id) -coordinator.watch_join_group(b"my group", group_joined) - +coordinator.watch_join_group(group, group_joined) coordinator.stop() diff --git a/examples/leader_election.py b/examples/leader_election.py index ff1d75f..b27129e 100644 --- a/examples/leader_election.py +++ b/examples/leader_election.py @@ -1,14 +1,21 @@ +import time +import uuid + +import six + from tooz import coordination -coordinator = coordination.get_coordinator('zookeeper://localhost', b'host-1') +ALIVE_TIME = 1 +coordinator = coordination.get_coordinator('kazoo://localhost', b'host-1') coordinator.start() # Create a group -request = coordinator.create_group(b"my group") +group = six.binary_type(six.text_type(uuid.uuid4()).encode('ascii')) +request = coordinator.create_group(group) request.get() # Join a group -request = coordinator.join_group(b"my group") +request = coordinator.join_group(group) request.get() @@ -18,11 +25,12 @@ def when_i_am_elected_leader(event): # Propose to be a leader for the group -coordinator.watch_elected_as_leader(b"my_group", - when_i_am_elected_leader) +coordinator.watch_elected_as_leader(group, when_i_am_elected_leader) -while True: +start = time.time() +while time.time() - start < ALIVE_TIME: coordinator.heartbeat() coordinator.run_watchers() + time.sleep(0.1) coordinator.stop() diff --git a/run-examples.sh b/run-examples.sh new file mode 100755 index 0000000..0f13fd7 --- /dev/null +++ b/run-examples.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +set -e + +python_version=$(python --version 2>&1) +echo "Running using '$python_version'" +for filename in examples/*.py; do + echo "Activating '$filename'" + python $filename +done @@ -20,6 +20,7 @@ commands = {posargs} deps = {[testenv]deps} doc8 commands = bash -x {toxinidir}/setup-test-env.sh python setup.py testr --slowest --testr-args="{posargs}" + bash -x {toxinidir}/setup-test-env.sh {toxinidir}/run-examples.sh doc8 doc/source [testenv:cover] |