|
| 1 | +import pytest |
| 2 | + |
| 3 | +import ydb |
| 4 | +from ydb import aio |
| 5 | + |
| 6 | +from ydb.coordination import ( |
| 7 | + NodeConfig, |
| 8 | + ConsistencyMode, |
| 9 | + RateLimiterCountersMode, |
| 10 | + CoordinationClient, |
| 11 | +) |
| 12 | + |
| 13 | + |
| 14 | +class TestCoordination: |
| 15 | + def test_coordination_node_lifecycle(self, driver_sync: ydb.Driver): |
| 16 | + client = CoordinationClient(driver_sync) |
| 17 | + node_path = "/local/test_node_lifecycle" |
| 18 | + |
| 19 | + try: |
| 20 | + client.delete_node(node_path) |
| 21 | + except ydb.SchemeError: |
| 22 | + pass |
| 23 | + |
| 24 | + with pytest.raises(ydb.SchemeError): |
| 25 | + client.describe_node(node_path) |
| 26 | + |
| 27 | + initial_config = NodeConfig( |
| 28 | + session_grace_period_millis=1000, |
| 29 | + attach_consistency_mode=ConsistencyMode.STRICT, |
| 30 | + read_consistency_mode=ConsistencyMode.STRICT, |
| 31 | + rate_limiter_counters_mode=RateLimiterCountersMode.UNSET, |
| 32 | + self_check_period_millis=0, |
| 33 | + ) |
| 34 | + client.create_node(node_path, initial_config) |
| 35 | + |
| 36 | + node_conf = client.describe_node(node_path) |
| 37 | + assert node_conf == initial_config |
| 38 | + |
| 39 | + updated_config = NodeConfig( |
| 40 | + session_grace_period_millis=12345, |
| 41 | + attach_consistency_mode=ConsistencyMode.STRICT, |
| 42 | + read_consistency_mode=ConsistencyMode.RELAXED, |
| 43 | + rate_limiter_counters_mode=RateLimiterCountersMode.DETAILED, |
| 44 | + self_check_period_millis=10, |
| 45 | + ) |
| 46 | + client.alter_node(node_path, updated_config) |
| 47 | + |
| 48 | + node_conf = client.describe_node(node_path) |
| 49 | + assert node_conf == updated_config |
| 50 | + |
| 51 | + client.delete_node(node_path) |
| 52 | + |
| 53 | + with pytest.raises(ydb.SchemeError): |
| 54 | + client.describe_node(node_path) |
| 55 | + |
| 56 | + async def test_coordination_node_lifecycle_async(self, aio_connection): |
| 57 | + client = aio.CoordinationClient(aio_connection) |
| 58 | + node_path = "/local/test_node_lifecycle" |
| 59 | + |
| 60 | + try: |
| 61 | + await client.delete_node(node_path) |
| 62 | + except ydb.SchemeError: |
| 63 | + pass |
| 64 | + |
| 65 | + with pytest.raises(ydb.SchemeError): |
| 66 | + await client.describe_node(node_path) |
| 67 | + |
| 68 | + initial_config = NodeConfig( |
| 69 | + session_grace_period_millis=1000, |
| 70 | + attach_consistency_mode=ConsistencyMode.STRICT, |
| 71 | + read_consistency_mode=ConsistencyMode.STRICT, |
| 72 | + rate_limiter_counters_mode=RateLimiterCountersMode.UNSET, |
| 73 | + self_check_period_millis=0, |
| 74 | + ) |
| 75 | + await client.create_node(node_path, initial_config) |
| 76 | + |
| 77 | + node_conf = await client.describe_node(node_path) |
| 78 | + assert node_conf == initial_config |
| 79 | + |
| 80 | + updated_config = NodeConfig( |
| 81 | + session_grace_period_millis=12345, |
| 82 | + attach_consistency_mode=ConsistencyMode.STRICT, |
| 83 | + read_consistency_mode=ConsistencyMode.RELAXED, |
| 84 | + rate_limiter_counters_mode=RateLimiterCountersMode.DETAILED, |
| 85 | + self_check_period_millis=10, |
| 86 | + ) |
| 87 | + await client.alter_node(node_path, updated_config) |
| 88 | + |
| 89 | + node_conf = await client.describe_node(node_path) |
| 90 | + assert node_conf == updated_config |
| 91 | + |
| 92 | + await client.delete_node(node_path) |
| 93 | + |
| 94 | + with pytest.raises(ydb.SchemeError): |
| 95 | + await client.describe_node(node_path) |
0 commit comments