test_engine.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. # Licensed to the Apache Software Foundation (ASF) under one
  2. # or more contributor license agreements. See the NOTICE file
  3. # distributed with this work for additional information
  4. # regarding copyright ownership. The ASF licenses this file
  5. # to you under the Apache License, Version 2.0 (the
  6. # "License"); you may not use this file except in compliance
  7. # with the License. You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing,
  12. # software distributed under the License is distributed on an
  13. # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  14. # KIND, either express or implied. See the License for the
  15. # specific language governing permissions and limitations
  16. # under the License.
  17. """Test Task Engine."""
  18. from unittest.mock import patch
  19. import pytest
  20. from pydolphinscheduler.core.engine import Engine, ProgramType
  21. TEST_ENGINE_TASK_TYPE = "ENGINE"
  22. TEST_MAIN_CLASS = "org.apache.examples.mock.Mock"
  23. TEST_MAIN_PACKAGE = "Mock.jar"
  24. TEST_PROGRAM_TYPE = ProgramType.JAVA
  25. @patch(
  26. "pydolphinscheduler.core.task.Task.gen_code_and_version",
  27. return_value=(123, 1),
  28. )
  29. @patch(
  30. "pydolphinscheduler.core.engine.Engine.get_resource_info",
  31. return_value=({"id": 1, "name": "mock_name"}),
  32. )
  33. def test_get_jar_detail(mock_resource, mock_code_version):
  34. """Test :func:`get_jar_id` can return expect value."""
  35. name = "test_get_jar_detail"
  36. task = Engine(
  37. name,
  38. TEST_ENGINE_TASK_TYPE,
  39. TEST_MAIN_CLASS,
  40. TEST_MAIN_PACKAGE,
  41. TEST_PROGRAM_TYPE,
  42. )
  43. assert 1 == task.get_jar_id()
  44. @pytest.mark.parametrize(
  45. "attr, expect",
  46. [
  47. (
  48. {
  49. "name": "test-task-params",
  50. "task_type": "test-engine",
  51. "main_class": "org.apache.examples.mock.Mock",
  52. "main_package": "TestMock.jar",
  53. "program_type": ProgramType.JAVA,
  54. },
  55. {
  56. "mainClass": "org.apache.examples.mock.Mock",
  57. "mainJar": {
  58. "id": 1,
  59. },
  60. "programType": ProgramType.JAVA,
  61. "localParams": [],
  62. "resourceList": [],
  63. "dependence": {},
  64. "conditionResult": {"successNode": [""], "failedNode": [""]},
  65. "waitStartTimeout": {},
  66. },
  67. )
  68. ],
  69. )
  70. @patch(
  71. "pydolphinscheduler.core.task.Task.gen_code_and_version",
  72. return_value=(123, 1),
  73. )
  74. @patch(
  75. "pydolphinscheduler.core.engine.Engine.get_resource_info",
  76. return_value=({"id": 1, "name": "mock_name"}),
  77. )
  78. def test_property_task_params(mock_resource, mock_code_version, attr, expect):
  79. """Test task engine task property."""
  80. task = Engine(**attr)
  81. assert expect == task.task_params
  82. @pytest.mark.parametrize(
  83. "attr, expect",
  84. [
  85. (
  86. {
  87. "name": "test-task-test_engine_get_define",
  88. "task_type": "test-engine",
  89. "main_class": "org.apache.examples.mock.Mock",
  90. "main_package": "TestMock.jar",
  91. "program_type": ProgramType.JAVA,
  92. },
  93. {
  94. "code": 123,
  95. "name": "test-task-test_engine_get_define",
  96. "version": 1,
  97. "description": None,
  98. "delayTime": 0,
  99. "taskType": "test-engine",
  100. "taskParams": {
  101. "mainClass": "org.apache.examples.mock.Mock",
  102. "mainJar": {
  103. "id": 1,
  104. },
  105. "programType": ProgramType.JAVA,
  106. "localParams": [],
  107. "resourceList": [],
  108. "dependence": {},
  109. "conditionResult": {"successNode": [""], "failedNode": [""]},
  110. "waitStartTimeout": {},
  111. },
  112. "flag": "YES",
  113. "taskPriority": "MEDIUM",
  114. "workerGroup": "default",
  115. "environmentCode": None,
  116. "failRetryTimes": 0,
  117. "failRetryInterval": 1,
  118. "timeoutFlag": "CLOSE",
  119. "timeoutNotifyStrategy": None,
  120. "timeout": 0,
  121. },
  122. )
  123. ],
  124. )
  125. @patch(
  126. "pydolphinscheduler.core.task.Task.gen_code_and_version",
  127. return_value=(123, 1),
  128. )
  129. @patch(
  130. "pydolphinscheduler.core.engine.Engine.get_resource_info",
  131. return_value=({"id": 1, "name": "mock_name"}),
  132. )
  133. def test_engine_get_define(mock_resource, mock_code_version, attr, expect):
  134. """Test task engine function get_define."""
  135. task = Engine(**attr)
  136. assert task.get_define() == expect