DomGarguilo commented on code in PR #3575: URL: https://github.com/apache/accumulo/pull/3575#discussion_r1262890782
########## core/src/test/java/org/apache/accumulo/core/metadata/schema/SelectedFilesTest.java: ########## @@ -0,0 +1,157 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.accumulo.core.metadata.schema; + +import static org.junit.jupiter.api.Assertions.*; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import org.apache.accumulo.core.metadata.StoredTabletFile; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +public class SelectedFilesTest { + + final String filePathPrefix = "hdfs://namenode:9020/accumulo/tables/1/default_tablet/"; + + /** + * Make sure a SelectedFiles object is equal to another SelectedFiles object that was created + * using its metadata json + */ + @Test + public void testSerializationDeserialization() { + Set<StoredTabletFile> files = getStoredTabletFiles(2); + + SelectedFiles original = new SelectedFiles(files, true, 12345L); + + String json = original.getMetadataValue(); + SelectedFiles deserialized = SelectedFiles.from(json); + + assertEquals(original, deserialized); + } + + /** + * Ensure two SelectedFiles objects created with the same parameters are equal + */ + @Test + public void testEqualSerialization() { + Set<StoredTabletFile> files = getStoredTabletFiles(16); + + SelectedFiles sf1 = new SelectedFiles(files, true, 12345L); + SelectedFiles sf2 = new SelectedFiles(files, true, 12345L); + + assertEquals(sf1.getMetadataValue(), sf2.getMetadataValue()); + assertEquals(sf1, sf2); + } + + /** + * Ensure that two SelectedFiles objects, one created with a subset of files present in the other, + * are not equal + */ + @Test + public void testJsonSuperSetSubset() { + Set<StoredTabletFile> filesSuperSet = getStoredTabletFiles(3); + Set<StoredTabletFile> filesSubSet = new HashSet<>(filesSuperSet); + // Remove an element to create a subset + filesSubSet.remove(filesSubSet.iterator().next()); + + SelectedFiles superSetSelectedFiles = new SelectedFiles(filesSuperSet, true, 123456L); + SelectedFiles subSetSelectedFiles = new SelectedFiles(filesSubSet, true, 123456L); + + String superSetJson = superSetSelectedFiles.getMetadataValue(); + String subSetJson = subSetSelectedFiles.getMetadataValue(); + + assertNotEquals(superSetJson, subSetJson, "The metadata jsons should have differing file sets"); + + // Deserialize the JSON strings back to SelectedFiles and check for equality with the original + // objects + SelectedFiles superSetDeserialized = SelectedFiles.from(superSetJson); + SelectedFiles subSetDeserialized = SelectedFiles.from(subSetJson); + + assertEquals(superSetSelectedFiles, superSetDeserialized); + assertEquals(subSetSelectedFiles, subSetDeserialized); + + assertNotEquals(superSetDeserialized, subSetDeserialized, + "The objects should have differing file sets"); + } + + private static Stream<Arguments> provideTestJsons() { + return Stream.of(Arguments.of("123456", true, 2), Arguments.of("123456", false, 2), + Arguments.of("123456", true, 3), Arguments.of("ABCDEF", false, 3)); + } + + /** + * Ensure that SelectedFiles objects that are created using {@link SelectedFiles#from(String)} are + * created correctly + */ + @ParameterizedTest + @MethodSource("provideTestJsons") + public void testJsonStrings(String txid, boolean selAll, int numPaths) { Review Comment: In 9b961b2 I think i added coverage for the second case you mention. I think the first case already exists but please double check. I made the `Arguments` differ by one parameter from one to the next to ensure that each case, where only one variable changes, is covered. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
