diff --git a/hazelcast/src/test/java/com/hazelcast/map/impl/query/ErrorThrowingPredicate.java b/hazelcast/src/test/java/com/hazelcast/map/impl/query/ErrorThrowingPredicate.java new file mode 100644 index 000000000000..fc3d43f84d27 --- /dev/null +++ b/hazelcast/src/test/java/com/hazelcast/map/impl/query/ErrorThrowingPredicate.java @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2008-2020, Hazelcast, Inc. All Rights Reserved. + * + * Licensed 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 com.hazelcast.map.impl.query; + +import com.hazelcast.query.Predicate; + +import java.io.Serializable; +import java.util.Map; + +public class ErrorThrowingPredicate implements Predicate, Serializable { + @Override + public boolean apply(Map.Entry mapEntry) { + throw new NoClassDefFoundError(); + } +} diff --git a/hazelcast/src/test/java/com/hazelcast/map/impl/query/QueryAdvancedTest.java b/hazelcast/src/test/java/com/hazelcast/map/impl/query/QueryAdvancedTest.java index f26c8f795429..529f12e80c35 100644 --- a/hazelcast/src/test/java/com/hazelcast/map/impl/query/QueryAdvancedTest.java +++ b/hazelcast/src/test/java/com/hazelcast/map/impl/query/QueryAdvancedTest.java @@ -40,8 +40,10 @@ import com.hazelcast.test.TestHazelcastInstanceFactory; import com.hazelcast.test.annotation.ParallelTest; import com.hazelcast.test.annotation.QuickTest; +import org.junit.Rule; import org.junit.Test; import org.junit.experimental.categories.Category; +import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; import java.io.IOException; @@ -60,6 +62,9 @@ @Category({QuickTest.class, ParallelTest.class}) public class QueryAdvancedTest extends HazelcastTestSupport { + @Rule + public ExpectedException expected = ExpectedException.none(); + @Test public void testQueryOperationAreNotSentToLiteMembers() { TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2); @@ -141,8 +146,8 @@ public void entryEvicted(EntryEvent event) { // check the query result before eviction Collection values = map.values(new SqlPredicate("active")); assertEquals(String.format("Expected %s results but got %s. Number of evicted entries: %s.", - activeEmployees, values.size(), allEmployees - latch.getCount()), - activeEmployees, values.size()); + activeEmployees, values.size(), allEmployees - latch.getCount()), + activeEmployees, values.size()); // wait until eviction is completed assertOpenEventually(latch); @@ -522,8 +527,8 @@ public Portable create(int classId) { } }); config.getMapConfig(mapName) - .addMapIndexConfig(new MapIndexConfig("notExist", false)) - .addMapIndexConfig(new MapIndexConfig("n", false)); + .addMapIndexConfig(new MapIndexConfig("notExist", false)) + .addMapIndexConfig(new MapIndexConfig("n", false)); HazelcastInstance hazelcastInstance = createHazelcastInstance(config); @@ -535,4 +540,19 @@ public Portable create(int classId) { Collection values = map.values(new SqlPredicate("n = name_2 OR notExist = name_0")); assertEquals(1, values.size()); } + + @Test + public void testClassNotFoundErrorDelegatedToCallerOnQuery() { + Config config = getConfig(); + HazelcastInstance hazelcastInstance = createHazelcastInstance(config); + + IMap map = hazelcastInstance.getMap("map"); + + map.put(1, 1); + //A remote predicate can throw Error in case of Usercodeployment and missing sub classes + //See the issue for actual problem https://github.com/hazelcast/hazelcast/issues/18052 + //We are throwing error to see if the error is delegated to the caller + expected.expect(NoClassDefFoundError.class); + map.values(new ErrorThrowingPredicate()); + } }