|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | +package org.apache.hadoop.hive.metastore.utils; |
| 19 | + |
| 20 | +import org.apache.hadoop.conf.Configuration; |
| 21 | +import org.apache.hadoop.hive.metastore.annotation.MetastoreUnitTest; |
| 22 | +import org.apache.hadoop.hive.metastore.conf.MetastoreConf; |
| 23 | +import org.junit.Test; |
| 24 | +import org.junit.experimental.categories.Category; |
| 25 | + |
| 26 | +import static org.apache.hadoop.hive.metastore.utils.MetaStoreUtils.parseDbName; |
| 27 | +import static org.junit.Assert.assertArrayEquals; |
| 28 | + |
| 29 | +@Category(MetastoreUnitTest.class) |
| 30 | +public class TestMetastoreUtilsParseDbName { |
| 31 | + |
| 32 | + @Test |
| 33 | + public void testParseDbNameEdgeCases() { |
| 34 | + Configuration conf = MetastoreConf.newMetastoreConf(); |
| 35 | + MetastoreConf.setVar(conf, MetastoreConf.ConfVars.CATALOG_DEFAULT, "hive"); |
| 36 | + |
| 37 | + assertArrayEquals(new String[]{"hive", "@"}, parseDbName("@", conf)); |
| 38 | + assertArrayEquals(new String[]{"hive", "@!"}, parseDbName("@!", conf)); |
| 39 | + assertArrayEquals(new String[]{"", null}, parseDbName("@#", conf)); |
| 40 | + assertArrayEquals(new String[]{"", "db1"}, parseDbName("@#db1", conf)); |
| 41 | + assertArrayEquals(new String[]{"hive", "@cat1"}, parseDbName("@cat1", conf)); |
| 42 | + assertArrayEquals(new String[]{"cat1", null}, parseDbName("@cat1#", conf)); |
| 43 | + assertArrayEquals(new String[]{"cat1", ""}, parseDbName("@cat1#!", conf)); |
| 44 | + assertArrayEquals(new String[]{"cat1", "@db1"}, parseDbName("@cat1#@db1", conf)); |
| 45 | + assertArrayEquals(new String[]{"cat1", "#db1"}, parseDbName("@cat1##db1", conf)); |
| 46 | + assertArrayEquals(new String[]{"cat1", "db1"}, parseDbName("@cat1#db1", conf)); |
| 47 | + assertArrayEquals(new String[]{"cat1", "db1!"}, parseDbName("@cat1#db1!", conf)); |
| 48 | + assertArrayEquals(new String[]{"hive", "@cat1!"}, parseDbName("@cat1!", conf)); |
| 49 | + assertArrayEquals(new String[]{"hive", "#db1"}, parseDbName("#db1", conf)); |
| 50 | + assertArrayEquals(new String[]{"hive", "#!"}, parseDbName("#!", conf)); |
| 51 | + assertArrayEquals(new String[]{"hive", "#"}, parseDbName("#", conf)); |
| 52 | + } |
| 53 | +} |
0 commit comments