test_map_reduce.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 MR."""
  18. from unittest.mock import patch
  19. from pydolphinscheduler.tasks.map_reduce import MR, ProgramType
  20. @patch(
  21. "pydolphinscheduler.core.engine.Engine.get_resource_info",
  22. return_value=({"id": 1, "name": "test"}),
  23. )
  24. def test_mr_get_define(mock_resource):
  25. """Test task mr function get_define."""
  26. code = 123
  27. version = 1
  28. name = "test_mr_get_define"
  29. main_class = "org.apache.mr.test_main_class"
  30. main_package = "test_main_package"
  31. program_type = ProgramType.JAVA
  32. main_args = "/dolphinscheduler/resources/file.txt /output/ds"
  33. expect = {
  34. "code": code,
  35. "name": name,
  36. "version": 1,
  37. "description": None,
  38. "delayTime": 0,
  39. "taskType": "MR",
  40. "taskParams": {
  41. "mainClass": main_class,
  42. "mainJar": {
  43. "id": 1,
  44. },
  45. "programType": program_type,
  46. "appName": None,
  47. "mainArgs": main_args,
  48. "others": None,
  49. "localParams": [],
  50. "resourceList": [],
  51. "dependence": {},
  52. "conditionResult": {"successNode": [""], "failedNode": [""]},
  53. "waitStartTimeout": {},
  54. },
  55. "flag": "YES",
  56. "taskPriority": "MEDIUM",
  57. "workerGroup": "default",
  58. "failRetryTimes": 0,
  59. "failRetryInterval": 1,
  60. "timeoutFlag": "CLOSE",
  61. "timeoutNotifyStrategy": None,
  62. "timeout": 0,
  63. }
  64. with patch(
  65. "pydolphinscheduler.core.task.Task.gen_code_and_version",
  66. return_value=(code, version),
  67. ):
  68. task = MR(name, main_class, main_package, program_type, main_args=main_args)
  69. assert task.get_define() == expect