|
| 1 | +// Copyright 2023 Datafuse Labs. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +use chrono::DateTime; |
| 16 | +use databend_common_meta_app::principal as mt; |
| 17 | +use databend_common_meta_app::principal::ScheduleOptions; |
| 18 | +use databend_common_meta_app::principal::ScheduleType; |
| 19 | +use databend_common_meta_app::principal::WarehouseOptions; |
| 20 | +use fastrace::func_name; |
| 21 | +use maplit::btreemap; |
| 22 | + |
| 23 | +use crate::common; |
| 24 | + |
| 25 | +#[test] |
| 26 | +fn test_decode_v138_task_message() -> anyhow::Result<()> { |
| 27 | + let want_task = || mt::Task { |
| 28 | + task_id: 11, |
| 29 | + task_name: "task_c".to_string(), |
| 30 | + query_text: "SELECT * FROM t1".to_string(), |
| 31 | + when_condition: Some("c1 > 1".to_string()), |
| 32 | + after: vec!["task_a".to_string(), "task_b".to_string()], |
| 33 | + comment: Some("comment".to_string()), |
| 34 | + owner: "public".to_string(), |
| 35 | + owner_user: "me".to_string(), |
| 36 | + schedule_options: Some(ScheduleOptions { |
| 37 | + interval: Some(11), |
| 38 | + cron: Some("30 12 * * *".to_string()), |
| 39 | + time_zone: Some("UTC".to_string()), |
| 40 | + schedule_type: ScheduleType::IntervalType, |
| 41 | + milliseconds_interval: Some(11), |
| 42 | + }), |
| 43 | + warehouse_options: Some(WarehouseOptions { |
| 44 | + warehouse: Some("warehouse_a".to_string()), |
| 45 | + using_warehouse_size: Some("10".to_string()), |
| 46 | + }), |
| 47 | + next_scheduled_at: Some(DateTime::from_timestamp(10, 0).unwrap()), |
| 48 | + suspend_task_after_num_failures: Some(10), |
| 49 | + error_integration: None, |
| 50 | + status: mt::Status::Suspended, |
| 51 | + created_at: DateTime::from_timestamp(11, 0).unwrap(), |
| 52 | + updated_at: DateTime::from_timestamp(12, 0).unwrap(), |
| 53 | + last_suspended_at: Some(DateTime::from_timestamp(13, 0).unwrap()), |
| 54 | + session_params: btreemap! { s("a") => s("b") }, |
| 55 | + }; |
| 56 | + |
| 57 | + { |
| 58 | + let task_message_execute_v138 = vec![ |
| 59 | + 10, 239, 1, 8, 11, 18, 6, 116, 97, 115, 107, 95, 99, 34, 16, 83, 69, 76, 69, 67, 84, |
| 60 | + 32, 42, 32, 70, 82, 79, 77, 32, 116, 49, 42, 7, 99, 111, 109, 109, 101, 110, 116, 50, |
| 61 | + 6, 112, 117, 98, 108, 105, 99, 58, 22, 8, 11, 18, 11, 51, 48, 32, 49, 50, 32, 42, 32, |
| 62 | + 42, 32, 42, 26, 3, 85, 84, 67, 40, 11, 66, 17, 10, 11, 119, 97, 114, 101, 104, 111, |
| 63 | + 117, 115, 101, 95, 97, 18, 2, 49, 48, 74, 23, 49, 57, 55, 48, 45, 48, 49, 45, 48, 49, |
| 64 | + 32, 48, 48, 58, 48, 48, 58, 49, 48, 32, 85, 84, 67, 80, 10, 114, 23, 49, 57, 55, 48, |
| 65 | + 45, 48, 49, 45, 48, 49, 32, 48, 48, 58, 48, 48, 58, 49, 49, 32, 85, 84, 67, 122, 23, |
| 66 | + 49, 57, 55, 48, 45, 48, 49, 45, 48, 49, 32, 48, 48, 58, 48, 48, 58, 49, 50, 32, 85, 84, |
| 67 | + 67, 130, 1, 23, 49, 57, 55, 48, 45, 48, 49, 45, 48, 49, 32, 48, 48, 58, 48, 48, 58, 49, |
| 68 | + 51, 32, 85, 84, 67, 138, 1, 6, 116, 97, 115, 107, 95, 97, 138, 1, 6, 116, 97, 115, 107, |
| 69 | + 95, 98, 146, 1, 6, 99, 49, 32, 62, 32, 49, 154, 1, 6, 10, 1, 97, 18, 1, 98, 170, 1, 2, |
| 70 | + 109, 101, 160, 6, 137, 1, 168, 6, 24, 160, 6, 137, 1, 168, 6, 24, |
| 71 | + ]; |
| 72 | + let want_execute = || mt::TaskMessage::ExecuteTask(want_task()); |
| 73 | + |
| 74 | + common::test_pb_from_to(func_name!(), want_execute())?; |
| 75 | + common::test_load_old( |
| 76 | + func_name!(), |
| 77 | + task_message_execute_v138.as_slice(), |
| 78 | + 138, |
| 79 | + want_execute(), |
| 80 | + )?; |
| 81 | + } |
| 82 | + { |
| 83 | + let task_message_schedule_v138 = vec![ |
| 84 | + 18, 239, 1, 8, 11, 18, 6, 116, 97, 115, 107, 95, 99, 34, 16, 83, 69, 76, 69, 67, 84, |
| 85 | + 32, 42, 32, 70, 82, 79, 77, 32, 116, 49, 42, 7, 99, 111, 109, 109, 101, 110, 116, 50, |
| 86 | + 6, 112, 117, 98, 108, 105, 99, 58, 22, 8, 11, 18, 11, 51, 48, 32, 49, 50, 32, 42, 32, |
| 87 | + 42, 32, 42, 26, 3, 85, 84, 67, 40, 11, 66, 17, 10, 11, 119, 97, 114, 101, 104, 111, |
| 88 | + 117, 115, 101, 95, 97, 18, 2, 49, 48, 74, 23, 49, 57, 55, 48, 45, 48, 49, 45, 48, 49, |
| 89 | + 32, 48, 48, 58, 48, 48, 58, 49, 48, 32, 85, 84, 67, 80, 10, 114, 23, 49, 57, 55, 48, |
| 90 | + 45, 48, 49, 45, 48, 49, 32, 48, 48, 58, 48, 48, 58, 49, 49, 32, 85, 84, 67, 122, 23, |
| 91 | + 49, 57, 55, 48, 45, 48, 49, 45, 48, 49, 32, 48, 48, 58, 48, 48, 58, 49, 50, 32, 85, 84, |
| 92 | + 67, 130, 1, 23, 49, 57, 55, 48, 45, 48, 49, 45, 48, 49, 32, 48, 48, 58, 48, 48, 58, 49, |
| 93 | + 51, 32, 85, 84, 67, 138, 1, 6, 116, 97, 115, 107, 95, 97, 138, 1, 6, 116, 97, 115, 107, |
| 94 | + 95, 98, 146, 1, 6, 99, 49, 32, 62, 32, 49, 154, 1, 6, 10, 1, 97, 18, 1, 98, 170, 1, 2, |
| 95 | + 109, 101, 160, 6, 137, 1, 168, 6, 24, 160, 6, 137, 1, 168, 6, 24, |
| 96 | + ]; |
| 97 | + let want_schedule = || mt::TaskMessage::ScheduleTask(want_task()); |
| 98 | + |
| 99 | + common::test_pb_from_to(func_name!(), want_schedule())?; |
| 100 | + common::test_load_old( |
| 101 | + func_name!(), |
| 102 | + task_message_schedule_v138.as_slice(), |
| 103 | + 138, |
| 104 | + want_schedule(), |
| 105 | + )?; |
| 106 | + } |
| 107 | + { |
| 108 | + let task_message_after_v138 = vec![ |
| 109 | + 34, 239, 1, 8, 11, 18, 6, 116, 97, 115, 107, 95, 99, 34, 16, 83, 69, 76, 69, 67, 84, |
| 110 | + 32, 42, 32, 70, 82, 79, 77, 32, 116, 49, 42, 7, 99, 111, 109, 109, 101, 110, 116, 50, |
| 111 | + 6, 112, 117, 98, 108, 105, 99, 58, 22, 8, 11, 18, 11, 51, 48, 32, 49, 50, 32, 42, 32, |
| 112 | + 42, 32, 42, 26, 3, 85, 84, 67, 40, 11, 66, 17, 10, 11, 119, 97, 114, 101, 104, 111, |
| 113 | + 117, 115, 101, 95, 97, 18, 2, 49, 48, 74, 23, 49, 57, 55, 48, 45, 48, 49, 45, 48, 49, |
| 114 | + 32, 48, 48, 58, 48, 48, 58, 49, 48, 32, 85, 84, 67, 80, 10, 114, 23, 49, 57, 55, 48, |
| 115 | + 45, 48, 49, 45, 48, 49, 32, 48, 48, 58, 48, 48, 58, 49, 49, 32, 85, 84, 67, 122, 23, |
| 116 | + 49, 57, 55, 48, 45, 48, 49, 45, 48, 49, 32, 48, 48, 58, 48, 48, 58, 49, 50, 32, 85, 84, |
| 117 | + 67, 130, 1, 23, 49, 57, 55, 48, 45, 48, 49, 45, 48, 49, 32, 48, 48, 58, 48, 48, 58, 49, |
| 118 | + 51, 32, 85, 84, 67, 138, 1, 6, 116, 97, 115, 107, 95, 97, 138, 1, 6, 116, 97, 115, 107, |
| 119 | + 95, 98, 146, 1, 6, 99, 49, 32, 62, 32, 49, 154, 1, 6, 10, 1, 97, 18, 1, 98, 170, 1, 2, |
| 120 | + 109, 101, 160, 6, 137, 1, 168, 6, 24, 160, 6, 137, 1, 168, 6, 24, |
| 121 | + ]; |
| 122 | + let want_after = || mt::TaskMessage::AfterTask(want_task()); |
| 123 | + |
| 124 | + common::test_pb_from_to(func_name!(), want_after())?; |
| 125 | + common::test_load_old( |
| 126 | + func_name!(), |
| 127 | + task_message_after_v138.as_slice(), |
| 128 | + 138, |
| 129 | + want_after(), |
| 130 | + )?; |
| 131 | + } |
| 132 | + { |
| 133 | + let task_message_delete_v138 = vec![ |
| 134 | + 26, 27, 10, 6, 116, 97, 115, 107, 95, 99, 18, 17, 10, 11, 119, 97, 114, 101, 104, 111, |
| 135 | + 117, 115, 101, 95, 97, 18, 2, 49, 48, 160, 6, 137, 1, 168, 6, 24, |
| 136 | + ]; |
| 137 | + let want_delete = || { |
| 138 | + let task = want_task(); |
| 139 | + mt::TaskMessage::DeleteTask(task.task_name, task.warehouse_options) |
| 140 | + }; |
| 141 | + |
| 142 | + common::test_pb_from_to(func_name!(), want_delete())?; |
| 143 | + common::test_load_old( |
| 144 | + func_name!(), |
| 145 | + task_message_delete_v138.as_slice(), |
| 146 | + 138, |
| 147 | + want_delete(), |
| 148 | + )?; |
| 149 | + } |
| 150 | + |
| 151 | + Ok(()) |
| 152 | +} |
| 153 | + |
| 154 | +fn s(ss: impl ToString) -> String { |
| 155 | + ss.to_string() |
| 156 | +} |
0 commit comments