|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * 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, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +package org.apache.seatunnel.connectors.seatunnel.prometheus; |
| 19 | + |
| 20 | +import org.apache.seatunnel.api.configuration.ReadonlyConfig; |
| 21 | +import org.apache.seatunnel.connectors.seatunnel.prometheus.config.PrometheusSourceParameter; |
| 22 | + |
| 23 | +import org.junit.jupiter.api.Assertions; |
| 24 | +import org.junit.jupiter.api.Test; |
| 25 | + |
| 26 | +import java.util.HashMap; |
| 27 | +import java.util.Map; |
| 28 | + |
| 29 | +public class PrometheusParamCheckTest { |
| 30 | + |
| 31 | + @Test |
| 32 | + public void checkTime() { |
| 33 | + final PrometheusSourceParameter prometheusSourceParameter = new PrometheusSourceParameter(); |
| 34 | + Map<String, Object> map1 = new HashMap<>(); |
| 35 | + map1.put("url", "http://localhost:9090"); |
| 36 | + map1.put("query", "node_cpu_seconds_total"); |
| 37 | + map1.put("query_type", "Range"); |
| 38 | + map1.put("start", "2025-05-13T02:25:23Z"); |
| 39 | + map1.put("end", "2025-05-13T02:25:23.001Z"); |
| 40 | + prometheusSourceParameter.buildWithConfig(ReadonlyConfig.fromMap(map1)); |
| 41 | + |
| 42 | + Map<String, Object> map2 = new HashMap<>(); |
| 43 | + map2.put("url", "http://localhost:9090"); |
| 44 | + map2.put("query", "node_cpu_seconds_total"); |
| 45 | + map2.put("query_type", "Range"); |
| 46 | + map2.put("start", "2025-05-13T02:25:23Z"); |
| 47 | + map2.put("end", "2025-05-13T02:25:23.001"); |
| 48 | + Assertions.assertThrows( |
| 49 | + Exception.class, |
| 50 | + () -> prometheusSourceParameter.buildWithConfig(ReadonlyConfig.fromMap(map2))); |
| 51 | + |
| 52 | + Map<String, Object> map3 = new HashMap<>(); |
| 53 | + map3.put("url", "http://localhost:9090"); |
| 54 | + map3.put("query", "node_cpu_seconds_total"); |
| 55 | + map3.put("query_type", "Range"); |
| 56 | + map3.put("start", "1747103123.083"); |
| 57 | + map3.put("end", "1747106723"); |
| 58 | + prometheusSourceParameter.buildWithConfig(ReadonlyConfig.fromMap(map3)); |
| 59 | + |
| 60 | + Map<String, Object> map4 = new HashMap<>(); |
| 61 | + map4.put("url", "http://localhost:9090"); |
| 62 | + map4.put("query", "node_cpu_seconds_total"); |
| 63 | + map4.put("query_type", "Range"); |
| 64 | + map4.put("start", "CURRENT_TIMESTAMP"); |
| 65 | + map4.put("end", "CURRENT_TIMESTAMP"); |
| 66 | + prometheusSourceParameter.buildWithConfig(ReadonlyConfig.fromMap(map4)); |
| 67 | + } |
| 68 | +} |
0 commit comments