|
1 | 1 | import time |
2 | 2 | import unittest |
3 | 3 |
|
| 4 | +from parameterized import parameterized |
4 | 5 | from crate.client import connect |
5 | 6 | import random |
6 | 7 | from random import sample |
7 | 8 |
|
8 | 9 | from crate.qa.tests import NodeProvider, insert_data, UpgradePath |
9 | 10 |
|
| 11 | +UPGRADE_42_TO_43 = ('4.2.x to 4.3.x', UpgradePath('4.2.x', '4.3.x'), 3,) |
| 12 | +UPGRADE_43_TO_LATEST = ('4.3.x to latest-nightly', UpgradePath('4.3.x', 'latest-nightly'), 3,) |
| 13 | + |
10 | 14 |
|
11 | 15 | class RecoveryTest(NodeProvider, unittest.TestCase): |
| 16 | + |
12 | 17 | """ |
13 | 18 | In depth testing of the recovery mechanism during a rolling restart. |
14 | 19 | Based on org.elasticsearch.upgrades.RecoveryIT.java |
15 | 20 | """ |
16 | | - |
17 | | - def test(self): |
18 | | - self._run_tests( |
19 | | - [ |
20 | | - UpgradePath('4.2.x', '4.3.x'), |
21 | | - UpgradePath('4.3.x', 'latest-nightly'), |
22 | | - ], |
23 | | - [ |
24 | | - self._test_relocation_with_concurrent_indexing, |
25 | | - self._test_recovery, |
26 | | - self._test_update_docs, |
27 | | - self._test_recovery_closed_index, |
28 | | - self._test_closed_index_during_rolling_upgrade, |
29 | | - self._test_relocation_with_concurrent_indexing, |
30 | | - ] |
31 | | - ) |
32 | | - |
33 | | - def test_from_4_3(self): |
34 | | - self._run_tests( |
35 | | - [ |
36 | | - UpgradePath('4.3.x', 'latest-nightly') |
37 | | - ], |
38 | | - [ |
39 | | - self._test_turnoff_translog_retention_after_upgraded, |
40 | | - self._test_operation_based_recovery, |
41 | | - ] |
42 | | - ) |
43 | | - |
44 | | - def _run_tests(self, paths, tests): |
45 | | - for path in paths: |
46 | | - for test in tests: |
47 | | - with self.subTest(repr(path)): |
48 | | - try: |
49 | | - self.setUp() |
50 | | - print(f'Run {test.__name__} upgrading versions {path}') |
51 | | - test(path, nodes=3) |
52 | | - finally: |
53 | | - self.tearDown() |
54 | | - |
55 | 21 | def _assert_num_docs_by_node_id(self, conn, schema, table_name, node_id, expected_count): |
56 | 22 | c = conn.cursor() |
57 | 23 | c.execute('''select num_docs from sys.shards where schema_name = ? and table_name = ? and node['id'] = ?''', |
@@ -94,7 +60,8 @@ def _upgrade_cluster(self, cluster, version, nodes): |
94 | 60 | new_node = self.upgrade_node(node, version) |
95 | 61 | cluster[i] = new_node |
96 | 62 |
|
97 | | - def _test_recovery_with_concurrent_indexing(self, path, nodes): |
| 63 | + @parameterized.expand([UPGRADE_42_TO_43, UPGRADE_43_TO_LATEST]) |
| 64 | + def test_recovery_with_concurrent_indexing(self, name, path, nodes): |
98 | 65 | """ |
99 | 66 | This test creates a new table and insert data at every stage of the |
100 | 67 | rolling upgrade. |
@@ -154,8 +121,8 @@ def _test_recovery_with_concurrent_indexing(self, path, nodes): |
154 | 121 | for node_id in node_ids: |
155 | 122 | self._assert_num_docs_by_node_id(conn, 'doc', 'test', node_id[0], 105) |
156 | 123 |
|
157 | | - def _test_relocation_with_concurrent_indexing(self, path, nodes): |
158 | | - |
| 124 | + @parameterized.expand([UPGRADE_42_TO_43, UPGRADE_43_TO_LATEST]) |
| 125 | + def test_relocation_with_concurrent_indexing(self, name, path, nodes): |
159 | 126 | cluster = self._new_cluster(path.from_version, nodes) |
160 | 127 | cluster.start() |
161 | 128 |
|
@@ -224,7 +191,8 @@ def _test_relocation_with_concurrent_indexing(self, path, nodes): |
224 | 191 | for node_id in node_ids: |
225 | 192 | self._assert_num_docs_by_node_id(conn, 'doc', 'test', node_id[0], 105) |
226 | 193 |
|
227 | | - def _test_recovery(self, path, nodes): |
| 194 | + @parameterized.expand([UPGRADE_42_TO_43, UPGRADE_43_TO_LATEST]) |
| 195 | + def test_recovery(self, name, path, nodes): |
228 | 196 | """ |
229 | 197 | This test creates a new table, insert data and asserts the state at every stage of the |
230 | 198 | rolling upgrade. |
@@ -261,7 +229,8 @@ def _test_recovery(self, path, nodes): |
261 | 229 |
|
262 | 230 | self._assert_is_green(conn, 'doc', 'test') |
263 | 231 |
|
264 | | - def _test_recovery_closed_index(self, path, nodes): |
| 232 | + @parameterized.expand([UPGRADE_42_TO_43, UPGRADE_43_TO_LATEST]) |
| 233 | + def test_recovery_closed_index(self, name, path, nodes): |
265 | 234 | """ |
266 | 235 | This test creates a table in the non upgraded cluster and closes it. It then |
267 | 236 | checks that the table is effectively closed and potentially replicated. |
@@ -292,7 +261,8 @@ def _test_recovery_closed_index(self, path, nodes): |
292 | 261 |
|
293 | 262 | self._assert_is_closed(conn, 'doc', 'test') |
294 | 263 |
|
295 | | - def _test_closed_index_during_rolling_upgrade(self, path, nodes): |
| 264 | + @parameterized.expand([UPGRADE_42_TO_43, UPGRADE_43_TO_LATEST]) |
| 265 | + def test_closed_index_during_rolling_upgrade(self, name, path, nodes): |
296 | 266 | """ |
297 | 267 | This test creates and closes a new table at every stage of the rolling |
298 | 268 | upgrade. It then checks that the table is effectively closed and |
@@ -341,7 +311,8 @@ def _test_closed_index_during_rolling_upgrade(self, path, nodes): |
341 | 311 |
|
342 | 312 | self._assert_is_closed(conn, 'doc', 'upgraded_cluster') |
343 | 313 |
|
344 | | - def _test_update_docs(self, path, nodes): |
| 314 | + @parameterized.expand([UPGRADE_42_TO_43, UPGRADE_43_TO_LATEST]) |
| 315 | + def test_update_docs(self, name, path, nodes): |
345 | 316 | """ |
346 | 317 | This test creates a new table, insert data and updates data at every state at every stage of the |
347 | 318 | rolling upgrade. |
@@ -391,7 +362,8 @@ def _test_update_docs(self, path, nodes): |
391 | 362 | for result in res: |
392 | 363 | self.assertEqual(result['rowcount'], 1) |
393 | 364 |
|
394 | | - def _test_operation_based_recovery(self, path, nodes): |
| 365 | + @parameterized.expand([UPGRADE_43_TO_LATEST]) |
| 366 | + def test_operation_based_recovery(self, name, path, nodes): |
395 | 367 | """ |
396 | 368 | Tests that we should perform an operation-based recovery if there were |
397 | 369 | some but not too many uncommitted documents (i.e., less than 10% of |
@@ -444,7 +416,8 @@ def _test_operation_based_recovery(self, path, nodes): |
444 | 416 |
|
445 | 417 | self._assert_ensure_checkpoints_are_synced(conn, 'doc', 'test') |
446 | 418 |
|
447 | | - def _test_turnoff_translog_retention_after_upgraded(self, path, nodes): |
| 419 | + @parameterized.expand([UPGRADE_43_TO_LATEST]) |
| 420 | + def test_turnoff_translog_retention_after_upgraded(self, name, path, nodes): |
448 | 421 | """ |
449 | 422 | Verifies that once all shard copies on the new version, we should turn |
450 | 423 | off the translog retention for indices with soft-deletes. |
|
0 commit comments