pvary commented on code in PR #12774: URL: https://github.com/apache/iceberg/pull/12774#discussion_r2444536477
########## core/src/test/java/org/apache/iceberg/formats/TestFormatModelRegistry.java: ########## @@ -0,0 +1,134 @@ +/* + * 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 + * + * http://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.iceberg.formats; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; + +import org.apache.iceberg.FileFormat; +import org.apache.iceberg.io.InputFile; +import org.apache.iceberg.io.OutputFile; +import org.apache.iceberg.util.Pair; +import org.junit.jupiter.api.Test; + +class TestFormatModelRegistry { + /** Tests that registering the same class with the same configuration is successful. */ + @Test + void testSuccessfulReRegister() { + // It is fine to register the same classes with the same configuration multiple times Review Comment: Moved ########## core/src/test/java/org/apache/iceberg/formats/TestFormatModelRegistry.java: ########## @@ -0,0 +1,134 @@ +/* + * 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 + * + * http://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.iceberg.formats; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; + +import org.apache.iceberg.FileFormat; +import org.apache.iceberg.io.InputFile; +import org.apache.iceberg.io.OutputFile; +import org.apache.iceberg.util.Pair; +import org.junit.jupiter.api.Test; + +class TestFormatModelRegistry { + /** Tests that registering the same class with the same configuration is successful. */ + @Test + void testSuccessfulReRegister() { + // It is fine to register the same classes with the same configuration multiple times + DummyFormatModel model = new DummyFormatModel(Object.class, Object.class); + FormatModelRegistry.register(model); + assertThat(FormatModelRegistry.models()) + .containsEntry(Pair.of(FileFormat.PARQUET, Object.class), model); + FormatModelRegistry.register(model); + assertThat(FormatModelRegistry.models()) + .containsEntry(Pair.of(FileFormat.PARQUET, Object.class), model); + } + + /** Tests that registering the same class with the same configuration updates the registration. */ + @Test + void testUpdatedRegistration() { + DummyFormatModel model1 = new DummyFormatModel(Object.class, Object.class); + DummyFormatModel model2 = new DummyFormatModel(Object.class, Object.class); + FormatModelRegistry.register(model1); + assertThat(FormatModelRegistry.models().get(Pair.of(model1.format(), model1.type()))) + .isEqualTo(model1); + + // Registering a new model with the same format and schema type should replace the old one + FormatModelRegistry.register(model2); + assertThat(FormatModelRegistry.models().get(Pair.of(model1.format(), model1.type()))) + .isNotEqualTo(model1); + assertThat(FormatModelRegistry.models().get(Pair.of(model1.format(), model1.type()))) + .isEqualTo(model2); Review Comment: Changed -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
