|
| 1 | +/* |
| 2 | + * PlanCacheSchemaKeyTest.java |
| 3 | + * |
| 4 | + * This source file is part of the FoundationDB open source project |
| 5 | + * |
| 6 | + * Copyright 2021-2025 Apple Inc. and the FoundationDB project authors |
| 7 | + * |
| 8 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 | + * you may not use this file except in compliance with the License. |
| 10 | + * You may obtain a copy of the License at |
| 11 | + * |
| 12 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | + * |
| 14 | + * Unless required by applicable law or agreed to in writing, software |
| 15 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 16 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 | + * See the License for the specific language governing permissions and |
| 18 | + * limitations under the License. |
| 19 | + */ |
| 20 | + |
| 21 | +package com.apple.foundationdb.relational.recordlayer.query.cache; |
| 22 | + |
| 23 | +import org.junit.jupiter.api.Test; |
| 24 | + |
| 25 | +import java.util.Arrays; |
| 26 | +import java.util.List; |
| 27 | + |
| 28 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 29 | +import static org.junit.jupiter.api.Assertions.assertNotEquals; |
| 30 | + |
| 31 | +class PlanCacheSchemaKeyTest { |
| 32 | + |
| 33 | + @Test |
| 34 | + void ofCollectionProducesSortedKey() { |
| 35 | + final List<String> names = Arrays.asList("schema_b", "schema_a", "schema_c"); |
| 36 | + final PlanCacheSchemaKey key = PlanCacheSchemaKey.of(names); |
| 37 | + assertEquals(List.of("schema_a", "schema_b", "schema_c"), List.copyOf(key.getSchemaNames())); |
| 38 | + } |
| 39 | + |
| 40 | + @Test |
| 41 | + void ofCollectionEqualsSingletonOfForSingleElement() { |
| 42 | + final PlanCacheSchemaKey fromCollection = PlanCacheSchemaKey.of(List.of("my_schema")); |
| 43 | + final PlanCacheSchemaKey fromSingle = PlanCacheSchemaKey.of("my_schema"); |
| 44 | + assertEquals(fromSingle, fromCollection); |
| 45 | + assertEquals(fromSingle.hashCode(), fromCollection.hashCode()); |
| 46 | + } |
| 47 | + |
| 48 | + @Test |
| 49 | + void ofCollectionOrderIndependent() { |
| 50 | + final PlanCacheSchemaKey k1 = PlanCacheSchemaKey.of(Arrays.asList("alpha", "beta")); |
| 51 | + final PlanCacheSchemaKey k2 = PlanCacheSchemaKey.of(Arrays.asList("beta", "alpha")); |
| 52 | + assertEquals(k1, k2); |
| 53 | + assertEquals(k1.hashCode(), k2.hashCode()); |
| 54 | + } |
| 55 | + |
| 56 | + @Test |
| 57 | + void toStringSingleSchema() { |
| 58 | + assertEquals("my_schema", PlanCacheSchemaKey.of("my_schema").toString()); |
| 59 | + } |
| 60 | + |
| 61 | + @Test |
| 62 | + void toStringMultiSchemaJoinedWithPipe() { |
| 63 | + final PlanCacheSchemaKey key = PlanCacheSchemaKey.of(Arrays.asList("schema_b", "schema_a")); |
| 64 | + assertEquals("schema_a|schema_b", key.toString()); |
| 65 | + } |
| 66 | + |
| 67 | + @Test |
| 68 | + void differentSchemasDontMatch() { |
| 69 | + assertNotEquals(PlanCacheSchemaKey.of("schema_x"), PlanCacheSchemaKey.of("schema_y")); |
| 70 | + } |
| 71 | +} |
0 commit comments