-
Notifications
You must be signed in to change notification settings - Fork 107
Expand file tree
/
Copy pathtest_update_runtime.py
More file actions
84 lines (63 loc) · 2.66 KB
/
test_update_runtime.py
File metadata and controls
84 lines (63 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import unittest
from feldera.pipeline_builder import PipelineBuilder
from feldera.runtime_config import RuntimeConfig
from feldera.testutils import (
unique_pipeline_name,
FELDERA_TEST_NUM_WORKERS,
FELDERA_TEST_NUM_HOSTS,
)
from tests import TEST_CLIENT
from feldera.enums import PipelineStatus
class TestPipeline(unittest.TestCase):
def test_update_runtime(self):
"""
Test the /update_runtime API.
Pipeline's platform version should only be updated to the current version on-demand
(by calling /update_runtime) or when updating the pipeline code.
"""
pipeline_name = unique_pipeline_name("test_update_runtime")
sql = """
CREATE TABLE tbl(id INT) WITH ('materialized' = 'true');
CREATE MATERIALIZED VIEW v0 AS SELECT * FROM tbl;
"""
pipeline = PipelineBuilder(
TEST_CLIENT,
pipeline_name,
sql=sql,
runtime_config=RuntimeConfig(
workers=FELDERA_TEST_NUM_WORKERS,
hosts=FELDERA_TEST_NUM_HOSTS,
logging="debug",
),
).create_or_replace()
# Make sure the pipeline gets compiled, so we can set its platform version
# without having it overwriten by the compiler.
pipeline.start()
assert pipeline.status() == PipelineStatus.RUNNING
pipeline.stop(force=True)
pipeline.testing_force_update_platform_version("0.0.1")
assert pipeline.platform_version() == "0.0.1"
# Run pipeline compiled by a previous version of the platform without triggering recompilation.
pipeline.start()
assert pipeline.status() == PipelineStatus.RUNNING
assert pipeline.platform_version() == "0.0.1"
# update_runtime fails while the pipeline is running
with self.assertRaises(Exception):
pipeline.update_runtime()
pipeline.stop(force=True)
# update_runtime works when the pipeline is stopped
pipeline.update_runtime()
assert pipeline.platform_version() != "0.0.1"
pipeline.start()
assert pipeline.status() == PipelineStatus.RUNNING
pipeline.stop(force=True)
# Modifying program code updates platform version automatically.
pipeline.testing_force_update_platform_version("0.0.1")
assert pipeline.platform_version() == "0.0.1"
pipeline.modify(sql=sql + "\nCREATE MATERIALIZED VIEW v1 AS SELECT * FROM tbl;")
pipeline.start()
assert pipeline.status() == PipelineStatus.RUNNING
assert pipeline.platform_version() != "0.0.1"
pipeline.stop(force=True)
if __name__ == "__main__":
unittest.main()