Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle error on query for HD path correctly #18081

Merged
merged 1 commit into from
Jan 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ public void run() {
Result result
= queryRunner.runPartitionIndexOrPartitionScanQueryOnGivenOwnedPartition(query, partitionId);
future.addResult(partitionId, result);
} catch (Exception ex) {
} catch (Throwable ex) {
future.completeExceptionally(ex);
}
}
Expand All @@ -285,7 +285,7 @@ public void accept(AtomicReferenceArray<Result> response, Throwable throwable) {
Result combinedResult = queryRunner.populateEmptyResult(query, Collections.emptyList());
populateResult(response, combinedResult);
QueryOperation.this.sendResponse(combinedResult);
} catch (Exception e) {
} catch (Throwable e) {
QueryOperation.this.sendResponse(e);
throw rethrow(e);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
import com.hazelcast.config.IndexConfig;
import com.hazelcast.config.IndexType;
import com.hazelcast.config.MapStoreConfig;
import com.hazelcast.core.HazelcastException;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.internal.util.RootCauseMatcher;
import com.hazelcast.map.IMap;
import com.hazelcast.map.MapStoreAdapter;
import com.hazelcast.map.listener.EntryExpiredListener;
Expand All @@ -37,8 +39,10 @@
import com.hazelcast.test.TestHazelcastInstanceFactory;
import com.hazelcast.test.annotation.ParallelJVMTest;
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;
Expand All @@ -59,6 +63,9 @@
@Category({QuickTest.class, ParallelJVMTest.class})
public class QueryAdvancedTest extends HazelcastTestSupport {

@Rule
public ExpectedException expected = ExpectedException.none();

@Override
protected Config getConfig() {
return smallInstanceConfig();
Expand Down Expand Up @@ -114,7 +121,7 @@ public void testQueryWithTTL() {

String mapName = "default";
config.getMapConfig(mapName)
.setTimeToLiveSeconds(3);
.setTimeToLiveSeconds(3);

HazelcastInstance instance = createHazelcastInstance(config);

Expand Down Expand Up @@ -520,8 +527,8 @@ public void testUnknownPortableField_notCausesQueryException_withIndex() {
Config config = getConfig();
config.getSerializationConfig().addPortableFactory(666, classId -> new PortableEmployee());
config.getMapConfig(mapName)
.addIndexConfig(new IndexConfig(IndexType.HASH, "notExist"))
.addIndexConfig(new IndexConfig(IndexType.HASH, "n"));
.addIndexConfig(new IndexConfig(IndexType.HASH, "notExist"))
.addIndexConfig(new IndexConfig(IndexType.HASH, "n"));

HazelcastInstance hazelcastInstance = createHazelcastInstance(config);

Expand All @@ -533,4 +540,20 @@ public void testUnknownPortableField_notCausesQueryException_withIndex() {
Collection values = map.values(Predicates.sql("n = name_2 OR notExist = name_0"));
assertEquals(1, values.size());
}

@Test
public void testClassNotFoundErrorDelegatedToCallerOnQuery() {
Config config = getConfig();
HazelcastInstance hazelcastInstance = createHazelcastInstance(config);

IMap<Integer, Integer> 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(HazelcastException.class);
expected.expectCause(new RootCauseMatcher(NoClassDefFoundError.class));
map.values(new ErrorThrowingPredicate());
}
}