-
Notifications
You must be signed in to change notification settings - Fork 106
Expand file tree
/
Copy pathnegative_test.py
More file actions
158 lines (147 loc) · 4.89 KB
/
negative_test.py
File metadata and controls
158 lines (147 loc) · 4.89 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import unittest
from feldera import PipelineBuilder, Pipeline
from feldera.testutils import (
unique_pipeline_name,
FELDERA_TEST_NUM_WORKERS,
FELDERA_TEST_NUM_HOSTS,
)
from tests import TEST_CLIENT
from feldera.runtime_config import RuntimeConfig
class NegativeCompilationTests(unittest.TestCase):
def test_sql_error(self):
pipeline_name = unique_pipeline_name("sql_error")
sql = """
CREATE TABLE student(
id INT,
name STRING
);
CREATE VIEW s AS SELECT * FROM blah;
"""
expected = f"""
Pipeline {pipeline_name} failed to compile:
Compilation error
From line 5, column 32 to line 5, column 35: Object 'blah' not found
Code snippet:
4|);
5|CREATE VIEW s AS SELECT * FROM blah;
^^^^""".strip()
with self.assertRaises(Exception) as err:
PipelineBuilder(
TEST_CLIENT,
name=pipeline_name,
sql=sql,
runtime_config=RuntimeConfig(
workers=FELDERA_TEST_NUM_WORKERS,
hosts=FELDERA_TEST_NUM_HOSTS,
),
).create_or_replace()
got_err: str = err.exception.args[0].strip()
assert expected == got_err
pipeline = Pipeline.get(pipeline_name, TEST_CLIENT)
pipeline.clear_storage()
def test_rust_error(self):
pipeline_name = unique_pipeline_name("rust_error")
sql = ""
with self.assertRaises(Exception) as err:
PipelineBuilder(
TEST_CLIENT,
name=pipeline_name,
sql=sql,
udf_rust="Davy Jones",
runtime_config=RuntimeConfig(
workers=FELDERA_TEST_NUM_WORKERS,
hosts=FELDERA_TEST_NUM_HOSTS,
),
).create_or_replace()
assert "Davy Jones" in err.exception.args[0].strip()
def test_program_error0(self):
sql = "create taabl;"
name = unique_pipeline_name("test_program_error0")
try:
_ = PipelineBuilder(
TEST_CLIENT,
name,
sql,
runtime_config=RuntimeConfig(
workers=FELDERA_TEST_NUM_WORKERS,
hosts=FELDERA_TEST_NUM_HOSTS,
),
).create_or_replace()
except Exception:
pass
pipeline = Pipeline.get(name, TEST_CLIENT)
err = pipeline.program_error()
assert err["sql_compilation"] != 0
pipeline.stop(force=True)
pipeline.clear_storage()
def test_program_error1(self):
sql = ""
name = unique_pipeline_name("test_program_error1")
_ = PipelineBuilder(
TEST_CLIENT,
name,
sql,
runtime_config=RuntimeConfig(
workers=FELDERA_TEST_NUM_WORKERS,
hosts=FELDERA_TEST_NUM_HOSTS,
),
).create_or_replace()
pipeline = Pipeline.get(name, TEST_CLIENT)
err = pipeline.program_error()
assert err["sql_compilation"]["exit_code"] == 0
assert err["rust_compilation"]["exit_code"] == 0
pipeline.stop(force=True)
pipeline.clear_storage()
def test_errors0(self):
sql = "SELECT invalid"
name = unique_pipeline_name("test_errors0")
try:
_ = PipelineBuilder(
TEST_CLIENT,
name,
sql,
runtime_config=RuntimeConfig(
workers=FELDERA_TEST_NUM_WORKERS,
hosts=FELDERA_TEST_NUM_HOSTS,
),
).create_or_replace()
except Exception:
pass
pipeline = Pipeline.get(name, TEST_CLIENT)
assert pipeline.errors()[0]["sql_compilation"]["exit_code"] != 0
def test_initialization_error(self):
sql = """
CREATE TABLE t0 (
c0 INT NOT NULL
) with (
'connectors' = '[{
"transport": {
"name": "datagen",
"config": {
"plan": [{
"fields": {
"c1": { "strategy": "uniform", "range": [100, 10000] }
}
}]
}
}
}]'
);
"""
pipeline = PipelineBuilder(
TEST_CLIENT,
name=unique_pipeline_name("test_initialization_error"),
sql=sql,
runtime_config=RuntimeConfig(
workers=FELDERA_TEST_NUM_WORKERS,
hosts=FELDERA_TEST_NUM_HOSTS,
),
).create_or_replace()
with self.assertRaises(RuntimeError) as err:
pipeline.start()
pipeline.stop(force=True)
pipeline.clear_storage()
got_err: str = err.exception.args[0].strip()
assert "Unable to START the pipeline" in got_err
if __name__ == "__main__":
unittest.main()