Package: aiozk
Asyncio zookeeper client (aiozk)Table of ContentsAsyncio zookeeper client (aiozk)StatusInstallationQuick ExampleRecipesCautionTestingRun testsTesting approachRecipes testingRun some tests directlyReferencesStatusHave no major bugs in client/session/connection, but recipes need more test
code to become more robust.Any help and interest are welcome 😀Installation$pipinstallaiozkQuick ExampleimportasynciofromaiozkimportZKClientasyncdefmain():zk=ZKClient('localhost')awaitzk.start()awaitzk.create('/foo',data=b'bazz',ephemeral=True)assertb'bazz'==awaitzk.get_data('/foo')awaitzk.close()asyncio.run(main())RecipesYou may use recipes, similar to zoonado, kazoo, and other libs:# assuming zk is aiozk.ZKClient# Lockasyncwithawaitzk.recipes.Lock('/path/to/lock').acquire():# ... Do some stuff ...pass# Barrierbarrier=zk.recipes.Barrier('/path/to/barrier)awaitbarrier.create()awaitbarrier.lift()awaitbarrier.wait()# DoubleBarrierdouble_barrier=zk.recipes.DoubleBarrier('/path/to/double/barrier',min_participants=4)awaitdouble_barrier.enter(timeout=0.5)# ...  Do some stuff ...awaitdouble_barrier.leave(timeout=0.5)You can find full list of recipes provided by aiozk here:aiozk recipesTo understand ideas behind recipesplease read
thisandeven more
recipes here. Make sure
you're familiar with all recipes before doing something new by yourself,
especially when it involves more than few zookeeper calls.CautionDon't mix different type of recipes at the same znode path. For example,
creating a Lock and a DoubleBarrier object at the same path. It may cause
undefined behavior 😓TestingNB: please ensure that you're using recentdocker-composeversion. You can get it by runningpip install --user -U docker-composeRun tests# you should have access to docker

docker-compose build
./test-runner.shOr you can run tests with toxpip install --user tox tox-docker
toxTesting approachMost of tests are integration tests and running on real zookeeper instances.
We've chosenzookeeper 3.5version since it has an ability to dynamic reconfiguration and we're going to do all connecting/reconnecting/watches tests on zk docker cluster as this gives us the ability to restart any server and see what happens.# first terminal: launch zookeeper clusterdocker-composerm-fv&&docker-composebuildzk&&docker-composeup--scalezk=7zk_seedzk# it will launch cluster in this terminal and remain. last lines should be like this:zk_6|Servers:'server.1=172.23.0.9:2888:3888:participant;0.0.0.0:2181\nserver.2=172.23.0.2:2888:3888:participant;0.0.0.0:2181\nserver.3=172.23.0.3:2888:3888:participant;0.0.0.0:2181\nserver.4=172.23.0.4:2888:3888:participant;0.0.0.0:2181\nserver.5=172.23.0.5:2888:3888:participant;0.0.0.0:2181\nserver.6=172.23.0.7:2888:3888:participant;0.0.0.0:2181'zk_6|CONFIG:server.1=172.23.0.9:2888:3888:participant;0.0.0.0:2181
zk_6|server.2=172.23.0.2:2888:3888:participant;0.0.0.0:2181
zk_6|server.3=172.23.0.3:2888:3888:participant;0.0.0.0:2181
zk_6|server.4=172.23.0.4:2888:3888:participant;0.0.0.0:2181
zk_6|server.5=172.23.0.5:2888:3888:participant;0.0.0.0:2181
zk_6|server.6=172.23.0.7:2888:3888:participant;0.0.0.0:2181
zk_6|server.7=172.23.0.6:2888:3888:observer;0.0.0.0:2181
zk_6|zk_6|zk_6|Reconfiguring...
zk_6|ethernalloop
zk_7|Servers:'server.1=172.23.0.9:2888:3888:participant;0.0.0.0:2181\nserver.2=172.23.0.2:2888:3888:participant;0.0.0.0:2181\nserver.3=172.23.0.3:2888:3888:participant;0.0.0.0:2181\nserver.4=172.23.0.4:2888:3888:participant;0.0.0.0:2181\nserver.5=172.23.0.5:2888:3888:participant;0.0.0.0:2181\nserver.6=172.23.0.7:2888:3888:participant;0.0.0.0:2181\nserver.7=172.23.0.6:2888:3888:participant;0.0.0.0:2181'zk_7|CONFIG:server.1=172.23.0.9:2888:3888:participant;0.0.0.0:2181
zk_7|server.2=172.23.0.2:2888:3888:participant;0.0.0.0:2181
zk_7|server.3=172.23.0.3:2888:3888:participant;0.0.0.0:2181
zk_7|server.4=172.23.0.4:2888:3888:participant;0.0.0.0:2181
zk_7|server.5=172.23.0.5:2888:3888:participant;0.0.0.0:2181
zk_7|server.6=172.23.0.7:2888:3888:participant;0.0.0.0:2181
zk_7|server.7=172.23.0.6:2888:3888:participant;0.0.0.0:2181
zk_7|server.8=172.23.0.8:2888:3888:observer;0.0.0.0:2181
zk_7|zk_7|zk_7|Reconfiguring...
zk_7|ethernalloopRun tests in docker:docker-composerun--no-depsaiozk# last lines will be about testing results............lotoflinesommited........
.
----------------------------------------------------------------------
Ran3testsin1.059s

OKRun tests locally:# ZK_IP can be something from logs above, like: ZK_HOST=172.21.0.6:2181ZK_HOST=<ZK_IP>./venv/bin/pytestRecipes testingIt seems that usually recipes require several things to be tested:That recipe flow is working as expectedTimeouts: reproduce every timeout with meaningful values (timeout 0.5s and block for 0.6s)Run some tests directlyAnother way to run tests only which you are interested in quickly. Or this is
useful when you run tests under the other version of python.# Run zookeeper containerdockerrun-p2181:2181zookeeper# Run pytest directly at the development source treeexportZK_HOST=localhost
pytest-s--log-cli-level=DEBUGaiozk/test/test_barrier.pyReferencesIt is based onwglass/zoonadoimplementation