Copilot commented on code in PR #10475: URL: https://github.com/apache/gravitino/pull/10475#discussion_r2958246368
########## flink-connector/flink/src/test/java/org/apache/gravitino/flink/connector/paimon/TestGravitinoPaimonCatalog.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 + * + * 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.gravitino.flink.connector.paimon; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; + +import com.google.common.collect.ImmutableMap; +import org.apache.flink.table.catalog.CatalogBaseTable; +import org.apache.flink.table.catalog.ObjectPath; +import org.apache.flink.table.catalog.exceptions.CatalogException; +import org.apache.flink.table.catalog.exceptions.TableNotExistException; +import org.apache.flink.table.factories.CatalogFactory; +import org.apache.gravitino.flink.connector.PartitionConverter; +import org.apache.gravitino.flink.connector.SchemaAndTablePropertiesConverter; +import org.apache.paimon.flink.FlinkCatalog; +import org.apache.paimon.flink.FlinkCatalogFactory; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.MockedConstruction; +import org.mockito.Mockito; + +/** + * Unit tests for {@link GravitinoPaimonCatalog}, specifically verifying that {@link + * GravitinoPaimonCatalog#getTable(ObjectPath)} and {@link + * GravitinoPaimonCatalog#tableExists(ObjectPath)} delegate to the underlying Paimon FlinkCatalog. + * + * <p>Background: the parent {@link + * org.apache.gravitino.flink.connector.catalog.BaseCatalog#getTable(ObjectPath)} loads a table via + * Gravitino's REST API and returns a plain Flink {@link + * org.apache.flink.table.catalog.CatalogTable}. This causes {@code + * AbstractFlinkTableFactory.buildPaimonTable()} to create a {@code FileStoreTable} with {@code + * CatalogEnvironment.empty()} (catalogLoader = null), so {@code partitionHandler()} returns null + * and {@code AddPartitionCommitCallback} is never registered, resulting in Hive partition metadata + * never being updated after commits. + * + * <p>The fix overrides {@code getTable()} to delegate to the underlying Paimon {@code + * FlinkCatalog}, which returns a {@code DataCatalogTable} wrapping a {@code FileStoreTable} with a + * proper {@code CatalogEnvironment}. These tests verify this delegation contract. + */ +public class TestGravitinoPaimonCatalog { + + private static final String TEST_DB = "testDb"; + private static final String TEST_TABLE = "testTable"; + + private FlinkCatalog mockPaimonCatalog; + private GravitinoPaimonCatalog catalog; + + @BeforeEach + void setUp() { + mockPaimonCatalog = Mockito.mock(FlinkCatalog.class); + CatalogFactory.Context mockContext = Mockito.mock(CatalogFactory.Context.class); + when(mockContext.getName()).thenReturn("test-paimon-catalog"); + when(mockContext.getOptions()) + .thenReturn( + ImmutableMap.of( + "type", GravitinoPaimonCatalogFactoryOptions.IDENTIFIER, + "warehouse", "file:///tmp/test_warehouse", + "metastore", "filesystem")); + + // MockedConstruction intercepts new FlinkCatalogFactory() during GravitinoPaimonCatalog's + // constructor, injecting mockPaimonCatalog. The try block only needs to cover construction; + // the already-created mock remains valid after the MockedConstruction is closed. + try (MockedConstruction<FlinkCatalogFactory> ignored = + Mockito.mockConstruction( + FlinkCatalogFactory.class, + (mock, ctx) -> when(mock.createCatalog(any())).thenReturn(mockPaimonCatalog))) { Review Comment: This test relies on Mockito construction mocking (Mockito.mockConstruction), which requires the inline mock maker. The flink-connector/flink module currently only declares mockito-core; without adding mockito-inline (or a mockito-extensions/org.mockito.plugins.MockMaker file enabling mock-maker-inline), this test will fail at runtime when trying to mock constructors. -- 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]
