|
| 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 | + |
| 18 | +package org.apache.doris.mysql.privilege; |
| 19 | + |
| 20 | +import org.apache.doris.persist.gson.GsonUtils; |
| 21 | +import org.apache.doris.resource.Tag; |
| 22 | + |
| 23 | +import org.junit.Assert; |
| 24 | +import org.junit.Test; |
| 25 | + |
| 26 | +import java.util.Collections; |
| 27 | + |
| 28 | +public class CommonUserPropertiesTest { |
| 29 | + private static final String RESOURCE_TAG_JSON = "[{\"type\":\"location\",\"value\":\"group_a\"}]"; |
| 30 | + |
| 31 | + @Test |
| 32 | + public void testDeserializeResourceTagsFromAllFieldNames() { |
| 33 | + for (String fieldName : new String[] {"rt", "resourceTag", "resourceTags"}) { |
| 34 | + String json = String.format("{\"%s\":%s}", fieldName, RESOURCE_TAG_JSON); |
| 35 | + CommonUserProperties properties = GsonUtils.GSON.fromJson(json, CommonUserProperties.class); |
| 36 | + |
| 37 | + Assert.assertEquals(Collections.singleton(Tag.createNotCheck(Tag.TYPE_LOCATION, "group_a")), |
| 38 | + properties.getResourceTags()); |
| 39 | + } |
| 40 | + } |
| 41 | + |
| 42 | + @Test |
| 43 | + public void testDeserializeSqlBlockRulesFromAllFieldNames() { |
| 44 | + for (String fieldName : new String[] {"sbr", "sqlBlockRule", "sqlBlockRules"}) { |
| 45 | + String json = String.format("{\"%s\":\"rule_a, rule_b\"}", fieldName); |
| 46 | + CommonUserProperties properties = GsonUtils.GSON.fromJson(json, CommonUserProperties.class); |
| 47 | + |
| 48 | + Assert.assertEquals("rule_a, rule_b", properties.getSqlBlockRules()); |
| 49 | + Assert.assertArrayEquals(new String[] {"rule_a", "rule_b"}, properties.getSqlBlockRulesSplit()); |
| 50 | + } |
| 51 | + } |
| 52 | + |
| 53 | + @Test |
| 54 | + public void testDeserializeLegacyCommonUserProperties() { |
| 55 | + String json = "{" |
| 56 | + + "\"maxConn\":101," |
| 57 | + + "\"maxQueryInstances\":102," |
| 58 | + + "\"parallelFragmentExecInstanceNum\":103," |
| 59 | + + "\"sqlBlockRules\":\"rule_a, rule_b\"," |
| 60 | + + "\"cpuResourceLimit\":104," |
| 61 | + + "\"resourceTags\":" + RESOURCE_TAG_JSON + "," |
| 62 | + + "\"execMemLimit\":105," |
| 63 | + + "\"queryTimeout\":106," |
| 64 | + + "\"insertTimeout\":107," |
| 65 | + + "\"workloadGroup\":\"legacy_group\"," |
| 66 | + + "\"enablePreferCachedRowset\":true," |
| 67 | + + "\"queryFreshnessTolerance\":108" |
| 68 | + + "}"; |
| 69 | + CommonUserProperties properties = GsonUtils.GSON.fromJson(json, CommonUserProperties.class); |
| 70 | + |
| 71 | + Assert.assertEquals(101L, properties.getMaxConn()); |
| 72 | + Assert.assertEquals(102L, properties.getMaxQueryInstances()); |
| 73 | + Assert.assertEquals(103, properties.getParallelFragmentExecInstanceNum()); |
| 74 | + Assert.assertEquals("rule_a, rule_b", properties.getSqlBlockRules()); |
| 75 | + Assert.assertArrayEquals(new String[] {"rule_a", "rule_b"}, properties.getSqlBlockRulesSplit()); |
| 76 | + Assert.assertEquals(104, properties.getCpuResourceLimit()); |
| 77 | + Assert.assertEquals(Collections.singleton(Tag.createNotCheck(Tag.TYPE_LOCATION, "group_a")), |
| 78 | + properties.getResourceTags()); |
| 79 | + Assert.assertEquals(105L, properties.getExecMemLimit()); |
| 80 | + Assert.assertEquals(106, properties.getQueryTimeout()); |
| 81 | + Assert.assertEquals(107, properties.getInsertTimeout()); |
| 82 | + Assert.assertEquals("legacy_group", properties.getWorkloadGroup()); |
| 83 | + Assert.assertTrue(properties.getEnablePreferCachedRowset()); |
| 84 | + Assert.assertEquals(108L, properties.getQueryFreshnessToleranceMs()); |
| 85 | + } |
| 86 | +} |
0 commit comments