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