oleg-vlsk commented on code in PR #13583: URL: https://github.com/apache/ignite/pull/13583#discussion_r4056496803
########## modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/CacheConfigurationQueryEntityMergeTest.java: ########## @@ -0,0 +1,1202 @@ +/* + * 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.ignite.internal.processors.cache; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import javax.cache.CacheException; +import org.apache.ignite.cache.QueryEntity; +import org.apache.ignite.cache.QueryIndex; +import org.apache.ignite.cache.QueryIndexType; +import org.apache.ignite.cache.query.annotations.QuerySqlField; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.processors.query.QueryUtils; +import org.apache.ignite.spi.systemview.view.SystemView; +import org.apache.ignite.spi.systemview.view.sql.SqlIndexView; +import org.apache.ignite.spi.systemview.view.sql.SqlTableColumnView; +import org.apache.ignite.spi.systemview.view.sql.SqlTableView; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; +import org.junit.Test; + +import static org.apache.ignite.internal.processors.query.schema.management.SchemaManager.SQL_TBLS_VIEW; +import static org.apache.ignite.internal.processors.query.schema.management.SchemaManager.SQL_TBL_COLS_VIEW; +import static org.apache.ignite.testframework.GridTestUtils.assertThrows; + +/** Tests for merging QueryEntity metadata in CacheConfiguration. */ +public class CacheConfigurationQueryEntityMergeTest extends GridCommonAbstractTest { + /** */ + private static final String CACHE_NAME = "query-entity-merge-cache"; + + /** */ + private static final String COMPOSITE_IDX = "PERSON_NAME_AGE_IDX"; + + /** */ + private static final String NAME_IDX = "EXPLICIT_NAME_IDX"; + + /** */ + private static final String AGE_IDX = "EXPLICIT_AGE_IDX"; + + /** */ + private static final String NAME_FIELD = "name"; + + /** */ + private static final String AGE_FIELD = "age"; + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + stopAllGrids(); + + super.afterTest(); + } + + /** Query entities with different value types must not be merged. */ + @Test + public void testDifferentValueTypesAreNotMerged() throws Exception { + IgniteEx node = startGrid(0); + + CacheConfiguration<Integer, Object> ccfg = new CacheConfiguration<>(CACHE_NAME); + + QueryEntity first = new QueryEntity() + .setKeyType(Integer.class.getName()) + .setValueType(Person.class.getName()) + .setFields(fields(NAME_FIELD, String.class)); + + QueryEntity second = new QueryEntity() + .setKeyType(Integer.class.getName()) + .setValueType(AnnotatedPerson.class.getName()) + .setFields(fields(NAME_FIELD, String.class)); + + ccfg.setQueryEntities(Collections.singleton(first)); + ccfg.setQueryEntities(Collections.singleton(second)); + + node.createCache(ccfg); + + Collection<QueryEntity> entities = entities(node); + + assertEquals(2, entities.size()); + + for (Class<?> cls : List.of(Person.class, AnnotatedPerson.class)) + assertTrue(entities.stream().anyMatch(e -> cls.getName().equals(e.getValueType()))); + } + + /** Query entities with the same value type but different key type are a conflict. */ + @Test + public void testConflictingKeyTypesFail() { Review Comment: This test covers a different scenario and should remain. `testQueryEntitiesWithSameKeyTypeAndDifferentValueTypesAreNotMerged()` checks that we can have entities with the same key type but different value types. This test checks that 2 entities with the same value type are a conflict, even though they have different key types. Before my changes one of such entities was silently discarded. ########## modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/CacheConfigurationQueryEntityMergeTest.java: ########## @@ -0,0 +1,1202 @@ +/* + * 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.ignite.internal.processors.cache; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import javax.cache.CacheException; +import org.apache.ignite.cache.QueryEntity; +import org.apache.ignite.cache.QueryIndex; +import org.apache.ignite.cache.QueryIndexType; +import org.apache.ignite.cache.query.annotations.QuerySqlField; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.processors.query.QueryUtils; +import org.apache.ignite.spi.systemview.view.SystemView; +import org.apache.ignite.spi.systemview.view.sql.SqlIndexView; +import org.apache.ignite.spi.systemview.view.sql.SqlTableColumnView; +import org.apache.ignite.spi.systemview.view.sql.SqlTableView; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; +import org.junit.Test; + +import static org.apache.ignite.internal.processors.query.schema.management.SchemaManager.SQL_TBLS_VIEW; +import static org.apache.ignite.internal.processors.query.schema.management.SchemaManager.SQL_TBL_COLS_VIEW; +import static org.apache.ignite.testframework.GridTestUtils.assertThrows; + +/** Tests for merging QueryEntity metadata in CacheConfiguration. */ +public class CacheConfigurationQueryEntityMergeTest extends GridCommonAbstractTest { Review Comment: Done. -- 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]
