Skip to content

Commit 0306957

Browse files
committed
MINIFICPP-2682 Move Lua tests to modular docker tests
1 parent 8dfeed6 commit 0306957

File tree

8 files changed

+70
-4
lines changed

8 files changed

+70
-4
lines changed

behave_framework/src/minifi_test_framework/minifi/processor.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,14 @@ def __init__(self, class_name: str, proc_name: str, scheduling_strategy: str = "
2828
self.scheduling_period: str = scheduling_period
2929
self.properties: dict[str, str] = {}
3030
self.auto_terminated_relationships: list[str] = []
31+
self.max_concurrent_tasks: int | None = None
3132

3233
def add_property(self, property_name: str, property_value: str):
3334
self.properties[property_name] = property_value
3435

36+
def set_max_concurrent_tasks(self, max_concurrent_tasks: int):
37+
self.max_concurrent_tasks = max_concurrent_tasks
38+
3539
def remove_property(self, property_name: str):
3640
if property_name in self.properties:
3741
del self.properties[property_name]
@@ -49,6 +53,8 @@ def to_yaml_dict(self) -> dict:
4953
}
5054
if self.auto_terminated_relationships:
5155
data['auto-terminated relationships list'] = self.auto_terminated_relationships
56+
if self.max_concurrent_tasks is not None:
57+
data['max concurrent tasks'] = self.max_concurrent_tasks
5258

5359
# The YAML format capitalizes 'Properties'
5460
data['Properties'] = self.properties

behave_framework/src/minifi_test_framework/steps/checking_steps.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@ def step_impl(context: MinifiTestContext, message: str, duration: str):
8484
context=context)
8585

8686

87+
@then("the Minifi logs contain the following message: \"{log_message}\" {count:d} times after {duration}")
88+
def step_impl(context, log_message, count, duration):
89+
duration_seconds = humanfriendly.parse_timespan(duration)
90+
time.sleep(duration_seconds)
91+
assert context.get_default_minifi_container().get_logs().count(log_message) == count or context.get_default_minifi_container().log_app_output()
92+
93+
8794
@then("the Minifi logs match the following regex: \"{regex}\" in less than {duration}")
8895
def step_impl(context, regex, duration):
8996
duration_seconds = humanfriendly.parse_timespan(duration)

behave_framework/src/minifi_test_framework/steps/flow_building_steps.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,12 @@ def step_impl(context: MinifiTestContext, property_name: str, processor_name: st
256256
processor.add_property(property_name, filtering)
257257

258258

259+
@given("the max concurrent tasks attribute of the {processor_name} processor is set to {max_concurrent_tasks:d}")
260+
def step_impl(context, processor_name: str, max_concurrent_tasks: int):
261+
processor = context.get_or_create_default_minifi_container().flow_definition.get_processor(processor_name)
262+
processor.set_max_concurrent_tasks(max_concurrent_tasks)
263+
264+
259265
@given("the \"{property_name}\" properties of the {processor_name_one} and {processor_name_two} processors are set to the same random guid")
260266
def step_impl(context, property_name, processor_name_one, processor_name_two):
261267
uuid_str = str(uuid.uuid4())

docker/test/integration/cluster/DockerTestDirectoryBindings.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ def create_new_data_directories(self):
5555
# Add resources
5656
test_dir = os.environ['TEST_DIRECTORY'] # Based on DockerVerify.sh
5757
shutil.copytree(test_dir + "/resources/python", self.data_directories[self.feature_id]["resources_dir"] + "/python")
58-
shutil.copytree(test_dir + "/resources/lua", self.data_directories[self.feature_id]["resources_dir"] + "/lua")
5958
shutil.copytree(test_dir + "/resources/minifi", self.data_directories[self.feature_id]["minifi_config_dir"], dirs_exist_ok=True)
6059
shutil.copytree(test_dir + "/resources/minifi-controller", self.data_directories[self.feature_id]["resources_dir"] + "/minifi-controller")
6160

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one or more
2+
# contributor license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright ownership.
4+
# The ASF licenses this file to You under the Apache License, Version 2.0
5+
# (the "License"); you may not use this file except in compliance with
6+
# the License. You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
import os
17+
18+
from minifi_test_framework.core.hooks import common_before_scenario
19+
from minifi_test_framework.core.hooks import common_after_scenario
20+
21+
22+
def before_scenario(context, scenario):
23+
common_before_scenario(context, scenario)
24+
context.resource_dir = os.path.join(os.path.dirname(__file__), 'resources')
25+
26+
27+
def after_scenario(context, scenario):
28+
common_after_scenario(context, scenario)

docker/test/integration/features/lua_script.feature renamed to extensions/lua/tests/features/lua_script.feature

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,17 @@
1515

1616
@ENABLE_LUA_SCRIPTING
1717
Feature: MiNiFi can execute Lua scripts
18-
Background:
19-
Given the content of "/tmp/output" is monitored
2018

2119
Scenario: ExecuteScript should only allow the number of parallel tasks defined by the max concurrent tasks attribute for Lua scripts
2220
Given a GenerateFlowFile processor with the "File Size" property set to "0B"
2321
And the scheduling period of the GenerateFlowFile processor is set to "500 ms"
22+
And a host resource file "sleep_forever.lua" is bound to the "/tmp/resources/lua/sleep_forever.lua" path in the MiNiFi container
2423
And a ExecuteScript processor with the "Script File" property set to "/tmp/resources/lua/sleep_forever.lua"
24+
And ExecuteScript is EVENT_DRIVEN
2525
And the "Script Engine" property of the ExecuteScript processor is set to "lua"
2626
And the max concurrent tasks attribute of the ExecuteScript processor is set to 3
2727
And the "success" relationship of the GenerateFlowFile processor is connected to the ExecuteScript
28+
And ExecuteScript's success relationship is auto-terminated
2829

29-
When all instances start up
30+
When the MiNiFi instance starts up
3031
Then the Minifi logs contain the following message: "Sleeping forever" 3 times after 5 seconds

docker/test/integration/resources/lua/sleep_forever.lua renamed to extensions/lua/tests/features/resources/sleep_forever.lua

File renamed without changes.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one or more
2+
# contributor license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright ownership.
4+
# The ASF licenses this file to You under the Apache License, Version 2.0
5+
# (the "License"); you may not use this file except in compliance with
6+
# the License. You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
from minifi_test_framework.steps import checking_steps # noqa: F401
17+
from minifi_test_framework.steps import configuration_steps # noqa: F401
18+
from minifi_test_framework.steps import core_steps # noqa: F401
19+
from minifi_test_framework.steps import flow_building_steps # noqa: F401

0 commit comments

Comments
 (0)