Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@ def __init__(self, class_name: str, proc_name: str, scheduling_strategy: str = "
self.penalization_period: str = penalization_period
self.properties: dict[str, str] = {}
self.auto_terminated_relationships: list[str] = []
self.max_concurrent_tasks: int | None = None

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

def set_max_concurrent_tasks(self, max_concurrent_tasks: int):
self.max_concurrent_tasks = max_concurrent_tasks

def remove_property(self, property_name: str):
if property_name in self.properties:
del self.properties[property_name]
Expand All @@ -51,6 +55,8 @@ def to_yaml_dict(self) -> dict:
}
if self.auto_terminated_relationships:
data['auto-terminated relationships list'] = self.auto_terminated_relationships
if self.max_concurrent_tasks is not None:
data['max concurrent tasks'] = self.max_concurrent_tasks

# The YAML format capitalizes 'Properties'
data['Properties'] = self.properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ def step_impl(context: MinifiTestContext, message: str, duration: str):
context=context)


@then("the Minifi logs contain the following message: \"{log_message}\" {count:d} times after {duration}")
def step_impl(context, log_message, count, duration):
duration_seconds = humanfriendly.parse_timespan(duration)
time.sleep(duration_seconds)
assert context.get_default_minifi_container().get_logs().count(log_message) == count or context.get_default_minifi_container().log_app_output()


@then("the Minifi logs match the following regex: \"{regex}\" in less than {duration}")
def step_impl(context, regex, duration):
duration_seconds = humanfriendly.parse_timespan(duration)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,12 @@ def step_impl(context: MinifiTestContext, property_name: str, processor_name: st
processor.add_property(property_name, filtering)


@given("the max concurrent tasks attribute of the {processor_name} processor is set to {max_concurrent_tasks:d}")
def step_impl(context, processor_name: str, max_concurrent_tasks: int):
processor = context.get_or_create_default_minifi_container().flow_definition.get_processor(processor_name)
processor.set_max_concurrent_tasks(max_concurrent_tasks)


@given("the \"{property_name}\" properties of the {processor_name_one} and {processor_name_two} processors are set to the same random UUID")
def step_impl(context, property_name, processor_name_one, processor_name_two):
uuid_str = str(uuid.uuid4())
Expand Down
3 changes: 2 additions & 1 deletion docker/RunBehaveTests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -205,4 +205,5 @@ exec \
"${docker_dir}/../extensions/elasticsearch/tests/features" \
"${docker_dir}/../extensions/splunk/tests/features" \
"${docker_dir}/../extensions/gcp/tests/features" \
"${docker_dir}/../extensions/grafana-loki/tests/features"
"${docker_dir}/../extensions/grafana-loki/tests/features" \
"${docker_dir}/../extensions/lua/tests/features/"
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ def create_new_data_directories(self):
# Add resources
test_dir = os.environ['TEST_DIRECTORY'] # Based on DockerVerify.sh
shutil.copytree(test_dir + "/resources/python", self.data_directories[self.feature_id]["resources_dir"] + "/python")
shutil.copytree(test_dir + "/resources/lua", self.data_directories[self.feature_id]["resources_dir"] + "/lua")
shutil.copytree(test_dir + "/resources/minifi", self.data_directories[self.feature_id]["minifi_config_dir"], dirs_exist_ok=True)
shutil.copytree(test_dir + "/resources/minifi-controller", self.data_directories[self.feature_id]["resources_dir"] + "/minifi-controller")

Expand Down
28 changes: 28 additions & 0 deletions extensions/lua/tests/features/environment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os

from minifi_test_framework.core.hooks import common_before_scenario
from minifi_test_framework.core.hooks import common_after_scenario


def before_scenario(context, scenario):
common_before_scenario(context, scenario)
context.resource_dir = os.path.join(os.path.dirname(__file__), 'resources')


def after_scenario(context, scenario):
common_after_scenario(context, scenario)
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@

@ENABLE_LUA_SCRIPTING
Feature: MiNiFi can execute Lua scripts
Background:
Given the content of "/tmp/output" is monitored

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

When all instances start up
When the MiNiFi instance starts up
Then the Minifi logs contain the following message: "Sleeping forever" 3 times after 5 seconds
19 changes: 19 additions & 0 deletions extensions/lua/tests/features/steps/steps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from minifi_test_framework.steps import checking_steps # noqa: F401
from minifi_test_framework.steps import configuration_steps # noqa: F401
from minifi_test_framework.steps import core_steps # noqa: F401
from minifi_test_framework.steps import flow_building_steps # noqa: F401
Loading