Copilot commented on code in PR #37867: URL: https://github.com/apache/shardingsphere/pull/37867#discussion_r2734979408
########## kernel/distsql/handler/src/test/java/org/apache/shardingsphere/distsql/handler/ral/updatable/variable/SetDistVariableExecutorTest.java: ########## @@ -0,0 +1,81 @@ +/* + * 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.shardingsphere.distsql.handler.ral.updatable.variable; + +import org.apache.shardingsphere.distsql.statement.type.ral.updatable.SetDistVariableStatement; +import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; +import org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey; +import org.apache.shardingsphere.infra.config.props.temporary.TemporaryConfigurationProperties; +import org.apache.shardingsphere.infra.config.props.temporary.TemporaryConfigurationPropertyKey; +import org.apache.shardingsphere.infra.exception.kernel.syntax.UnsupportedVariableException; +import org.apache.shardingsphere.infra.util.props.PropertiesBuilder; +import org.apache.shardingsphere.infra.util.props.PropertiesBuilder.Property; +import org.apache.shardingsphere.mode.manager.ContextManager; +import org.apache.shardingsphere.mode.persist.service.MetaDataManagerPersistService; +import org.junit.jupiter.api.Test; +import org.mockito.ArgumentCaptor; + +import java.util.Properties; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.Mockito.RETURNS_DEEP_STUBS; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +class SetDistVariableExecutorTest { + + private final SetDistVariableExecutor executor = new SetDistVariableExecutor(); + + @Test + void assertSetConfigVariable() { + ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS); + ConfigurationProperties props = new ConfigurationProperties(PropertiesBuilder.build(new Property(ConfigurationPropertyKey.SQL_SHOW.getKey(), Boolean.FALSE.toString()))); + when(contextManager.getMetaDataContexts().getMetaData().getProps()).thenReturn(props); + when(contextManager.getMetaDataContexts().getMetaData().getTemporaryProps()).thenReturn(new TemporaryConfigurationProperties(new Properties())); + MetaDataManagerPersistService metaDataManagerService = mock(MetaDataManagerPersistService.class); + when(contextManager.getPersistServiceFacade().getModeFacade().getMetaDataManagerService()).thenReturn(metaDataManagerService); + executor.executeUpdate(new SetDistVariableStatement("SQL_SHOW", "true"), contextManager); + ArgumentCaptor<Properties> propsCaptor = ArgumentCaptor.forClass(Properties.class); + verify(metaDataManagerService).alterProperties(propsCaptor.capture()); + assertThat(propsCaptor.getValue().get(ConfigurationPropertyKey.SQL_SHOW.getKey()), is(Boolean.TRUE)); + } + + @Test + void assertSetTemporaryVariable() { + ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS); + when(contextManager.getMetaDataContexts().getMetaData().getProps()).thenReturn(new ConfigurationProperties(new Properties())); + when(contextManager.getMetaDataContexts().getMetaData().getTemporaryProps()) + .thenReturn(new TemporaryConfigurationProperties( + PropertiesBuilder.build(new Property(TemporaryConfigurationPropertyKey.PROXY_META_DATA_COLLECTOR_ENABLED.getKey(), Boolean.FALSE.toString())))); + MetaDataManagerPersistService metaDataManagerService = mock(MetaDataManagerPersistService.class); + when(contextManager.getPersistServiceFacade().getModeFacade().getMetaDataManagerService()).thenReturn(metaDataManagerService); + executor.executeUpdate(new SetDistVariableStatement("PROXY_META_DATA_COLLECTOR_ENABLED", "true"), contextManager); + ArgumentCaptor<Properties> propsCaptor = ArgumentCaptor.forClass(Properties.class); + verify(metaDataManagerService).alterProperties(propsCaptor.capture()); + assertThat(propsCaptor.getValue().get(TemporaryConfigurationPropertyKey.PROXY_META_DATA_COLLECTOR_ENABLED.getKey()), is(Boolean.TRUE)); + } + + @Test + void assertSetInvalidVariable() { + ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS); + assertThrows(UnsupportedVariableException.class, () -> executor.executeUpdate(new SetDistVariableStatement("invalid", "true"), contextManager)); + } +} Review Comment: The migrated test file has reduced test coverage compared to the original proxy test. The original test included additional test cases for: executing with TypedSPI (proxy_frontend_database_protocol_type), invalid value handling (InvalidVariableValueException), cron variable execution, and invalid cron variable handling. These test cases should be migrated to maintain comprehensive test coverage. ########## kernel/distsql/handler/src/test/java/org/apache/shardingsphere/distsql/handler/ral/updatable/refresh/RefreshTableMetaDataExecutorTest.java: ########## @@ -0,0 +1,119 @@ +/* + * 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.shardingsphere.distsql.handler.ral.updatable.refresh; + +import org.apache.shardingsphere.database.connector.core.type.DatabaseType; +import org.apache.shardingsphere.distsql.statement.type.ral.updatable.RefreshTableMetaDataStatement; +import org.apache.shardingsphere.infra.exception.kernel.metadata.SchemaNotFoundException; +import org.apache.shardingsphere.infra.exception.kernel.metadata.TableNotFoundException; +import org.apache.shardingsphere.infra.exception.kernel.metadata.resource.storageunit.EmptyStorageUnitException; +import org.apache.shardingsphere.infra.exception.kernel.metadata.resource.storageunit.MissingRequiredStorageUnitsException; +import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; +import org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData; +import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnit; +import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; +import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema; +import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereTable; +import org.apache.shardingsphere.mode.manager.ContextManager; +import org.junit.jupiter.api.Test; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.Mockito.RETURNS_DEEP_STUBS; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +class RefreshTableMetaDataExecutorTest { + + private final RefreshTableMetaDataExecutor executor = new RefreshTableMetaDataExecutor(); + + @Test + void assertExecuteWithSchemaAndStorageUnit() { + ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS); + ShardingSphereDatabase database = mockDatabase(); + executor.setDatabase(database); + executor.executeUpdate(new RefreshTableMetaDataStatement("foo_table", "foo_ds", "foo_schema"), contextManager); + verify(contextManager).reloadTable(database, "foo_schema", "foo_ds", "foo_table"); + } + + @Test + void assertExecuteWithMissingSchema() { + ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS); + ShardingSphereDatabase database = mockDatabase(); + when(database.containsSchema("missing")).thenReturn(false); + executor.setDatabase(database); + assertThrows(SchemaNotFoundException.class, () -> executor.executeUpdate(new RefreshTableMetaDataStatement("foo_table", "foo_ds", "missing"), contextManager)); + } + + @Test + void assertExecuteWithMissingTable() { + ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS); + ShardingSphereDatabase database = mockDatabase(); + when(database.getSchema("foo_schema").containsTable("missing")).thenReturn(false); + executor.setDatabase(database); + assertThrows(TableNotFoundException.class, () -> executor.executeUpdate(new RefreshTableMetaDataStatement("missing", null, "foo_schema"), contextManager)); + } + + @Test + void assertExecuteWithMissingStorageUnit() { + ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS); + ShardingSphereDatabase database = mockDatabase(); + executor.setDatabase(database); + assertThrows(MissingRequiredStorageUnitsException.class, () -> executor.executeUpdate(new RefreshTableMetaDataStatement("foo_table", "missing", "foo_schema"), contextManager)); + } + + @Test + void assertExecuteWithEmptyStorageUnits() { + ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS); + ResourceMetaData resourceMetaData = new ResourceMetaData(Collections.emptyMap(), Collections.emptyMap()); + when(database.getResourceMetaData()).thenReturn(resourceMetaData); + when(database.getName()).thenReturn("foo_db"); + when(database.getProtocolType()).thenReturn(mock(DatabaseType.class)); + ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS); + executor.setDatabase(database); + assertThrows(EmptyStorageUnitException.class, () -> executor.executeUpdate(new RefreshTableMetaDataStatement("foo_table", null, "foo_schema"), contextManager)); + } + + private ShardingSphereDatabase mockDatabase() { + return mockDatabase(new HashMap<>()); + } + + private ShardingSphereDatabase mockDatabase(final Map<String, StorageUnit> storageUnits) { + Map<String, StorageUnit> mutableStorageUnits = new HashMap<>(storageUnits); + if (mutableStorageUnits.isEmpty()) { + StorageUnit storageUnit = mock(StorageUnit.class, RETURNS_DEEP_STUBS); + mutableStorageUnits.put("foo_ds", storageUnit); + } + ResourceMetaData resourceMetaData = new ResourceMetaData(Collections.emptyMap(), mutableStorageUnits); + ShardingSphereSchema schema = mock(ShardingSphereSchema.class, RETURNS_DEEP_STUBS); + when(schema.containsTable("foo_table")).thenReturn(true); + when(schema.getTable("foo_table")).thenReturn(mock(ShardingSphereTable.class, RETURNS_DEEP_STUBS)); + ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS); + when(database.getResourceMetaData()).thenReturn(resourceMetaData); + when(database.containsSchema("foo_schema")).thenReturn(true); + when(database.getSchema("foo_schema")).thenReturn(schema); + when(database.getName()).thenReturn("foo_db"); + when(database.getProtocolType()).thenReturn(mock(DatabaseType.class)); + when(database.getRuleMetaData()).thenReturn(mock(RuleMetaData.class, RETURNS_DEEP_STUBS)); + return database; + } +} Review Comment: The migrated test file is missing test coverage for several scenarios that were present in the original proxy test: reloading a schema with a storage unit, reloading a table without specifying a storage unit, and reloading an entire database. These test cases should be migrated to maintain comprehensive test coverage for all execution paths. -- 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]
