This is an automated email from the ASF dual-hosted git repository. alexpl pushed a commit to branch ignite-2.8.1 in repository https://gitbox.apache.org/repos/asf/ignite.git
commit 6b5eb30ab7bf6f2c0db91d3bb51912acf4f103dd Author: Aleksey Plekhanov <plehanov.a...@gmail.com> AuthorDate: Thu Apr 30 11:18:31 2020 +0300 IGNITE-12933 Fixed node failure after put incorrect key class for cache with indexed types - Fixes #7721. Signed-off-by: Aleksey Plekhanov <plehanov.a...@gmail.com> (cherry picked from commit 3f888afc03126ccae4e0ea36b630d84600dff5ba) --- .../processors/query/GridQueryProcessor.java | 2 +- .../processors/cache/WrongIndexedTypesTest.java | 76 ++++++++++++++++++++++ .../IgniteCacheWithIndexingTestSuite.java | 5 +- 3 files changed, 81 insertions(+), 2 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java index 5dfffee..d333a9c 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java @@ -3115,7 +3115,7 @@ public class GridQueryProcessor extends GridProcessorAdapter { */ public void validateKeyAndValue(CacheObjectContext coctx, KeyCacheObject key, CacheObject val) throws IgniteCheckedException { - QueryTypeDescriptorImpl desc = typeByValue(coctx.cacheName(), coctx, key, val, false); + QueryTypeDescriptorImpl desc = typeByValue(coctx.cacheName(), coctx, key, val, true); if (desc == null) return; diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/WrongIndexedTypesTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/WrongIndexedTypesTest.java new file mode 100644 index 0000000..c6978be --- /dev/null +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/WrongIndexedTypesTest.java @@ -0,0 +1,76 @@ +/* + * 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 org.apache.ignite.Ignite; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.internal.util.typedef.F; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; +import org.junit.Test; + +import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC; +import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL; + +/** + * Test for put wrong value types to cache with indexed types. + */ +public class WrongIndexedTypesTest extends GridCommonAbstractTest { + /** Failed. */ + private boolean failed; + + /** Transactional cache name. */ + private static final String TX_CACHE = "tx_cache"; + + /** Atomic cache name. */ + private static final String ATOMIC_CACHE = "atomic_cache"; + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { + return super.getConfiguration(igniteInstanceName) + .setFailureHandler((ignite, ctx) -> failed = true) + .setCacheConfiguration( + new CacheConfiguration<>(TX_CACHE).setAtomicityMode(TRANSACTIONAL) + .setIndexedTypes(String.class, String.class), + new CacheConfiguration<>(ATOMIC_CACHE).setAtomicityMode(ATOMIC) + .setIndexedTypes(String.class, String.class)); + } + + /** + * + */ + @Test + public void testPutIndexedType() throws Exception { + Ignite ignite = startGrids(2); + + for (String cacheName : F.asList(TX_CACHE, ATOMIC_CACHE)) { + for (int i = 0; i < 10; i++) { + try { + ignite.cache(cacheName).put(i, "val" + i); + + fail("Exception expected"); + } + catch (Exception expected) { + // No-op. + } + } + } + + assertFalse(failed); + } +} diff --git a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheWithIndexingTestSuite.java b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheWithIndexingTestSuite.java index 414f4c0..b89b7da 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheWithIndexingTestSuite.java +++ b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheWithIndexingTestSuite.java @@ -39,6 +39,7 @@ import org.apache.ignite.internal.processors.cache.IgniteCacheConfigurationPrimi import org.apache.ignite.internal.processors.cache.IgniteCacheGroupsSqlTest; import org.apache.ignite.internal.processors.cache.IgniteCacheStarvationOnRebalanceTest; import org.apache.ignite.internal.processors.cache.IgniteClientReconnectQueriesTest; +import org.apache.ignite.internal.processors.cache.WrongIndexedTypesTest; import org.apache.ignite.internal.processors.cache.index.H2TreeCorruptedTreeExceptionTest; import org.apache.ignite.internal.processors.cache.persistence.RebuildIndexLogMessageTest; import org.apache.ignite.internal.processors.cache.ttl.CacheTtlAtomicLocalSelfTest; @@ -100,7 +101,9 @@ import org.junit.runners.Suite; RebuildIndexLogMessageTest.class, - H2TreeCorruptedTreeExceptionTest.class + H2TreeCorruptedTreeExceptionTest.class, + + WrongIndexedTypesTest.class }) public class IgniteCacheWithIndexingTestSuite { }