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

SerializationException propagated to client when response unserializable #13777

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
Expand Up @@ -28,6 +28,7 @@
import com.hazelcast.nio.ObjectDataInput;
import com.hazelcast.nio.ObjectDataOutput;
import com.hazelcast.nio.serialization.DataSerializable;
import com.hazelcast.nio.serialization.HazelcastSerializationException;
import com.hazelcast.test.AssertTask;
import com.hazelcast.test.HazelcastParallelClassRunner;
import com.hazelcast.test.annotation.ParallelTest;
Expand All @@ -40,6 +41,7 @@
import org.junit.runner.RunWith;

import java.io.IOException;
import java.io.Serializable;
import java.util.concurrent.Callable;
import java.util.concurrent.CancellationException;
import java.util.concurrent.CountDownLatch;
Expand All @@ -48,7 +50,9 @@
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicReference;

import static com.hazelcast.test.HazelcastTestSupport.assertOpenEventually;
import static com.hazelcast.test.HazelcastTestSupport.assertTrueEventually;
import static com.hazelcast.test.HazelcastTestSupport.randomString;
import static org.junit.Assert.assertEquals;
Expand Down Expand Up @@ -249,8 +253,10 @@ public void testCallableSerializedOnce_submitToAddress() throws ExecutionExcepti
assertEquals(2, future.get());
}


static class SerializedCounterCallable implements Callable, DataSerializable {


int counter;

public SerializedCounterCallable() {
Expand All @@ -271,4 +277,46 @@ public void readData(ObjectDataInput in) throws IOException {
counter = in.readInt() + 1;
}
}

@Test(expected = HazelcastSerializationException.class)
public void testUnserializableResponse_exceptionPropagatesToClient() throws Throwable {
IExecutorService service = client.getExecutorService("executor");
TaskWithUnserialazableResponse counterCallable = new TaskWithUnserialazableResponse();
Future future = service.submit(counterCallable);
try {
future.get();
} catch (ExecutionException e) {
throw e.getCause();
}
}

@Test(expected = HazelcastSerializationException.class)
public void testUnserializableResponse_exceptionPropagatesToClientCallback() throws Throwable {
IExecutorService service = client.getExecutorService("executor");
TaskWithUnserialazableResponse counterCallable = new TaskWithUnserialazableResponse();
final CountDownLatch countDownLatch = new CountDownLatch(1);
final AtomicReference<Throwable> throwable = new AtomicReference<Throwable>();
service.submit(counterCallable, new ExecutionCallback() {
@Override
public void onResponse(Object response) {

}

@Override
public void onFailure(Throwable t) {
throwable.set(t.getCause());
countDownLatch.countDown();
}
});
assertOpenEventually(countDownLatch);
throw throwable.get();
}

private static class TaskWithUnserialazableResponse implements Callable, Serializable {
@Override
public Object call() throws Exception {
return new Object();
}
}

}
Expand Up @@ -185,8 +185,12 @@ private void checkPermissions(ClientEndpoint endpoint) {
protected abstract void processMessage() throws Throwable;

protected void sendResponse(Object response) {
ClientMessage clientMessage = encodeResponse(response);
sendClientMessage(clientMessage);
try {
ClientMessage clientMessage = encodeResponse(response);
sendClientMessage(clientMessage);
} catch (Exception e) {
handleProcessingFailure(e);
}
}

protected void sendClientMessage(ClientMessage resultClientMessage) {
Expand Down
Expand Up @@ -67,6 +67,7 @@
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;

import static com.hazelcast.config.ExecutorConfig.DEFAULT_POOL_SIZE;
import static org.junit.Assert.assertEquals;
Expand Down Expand Up @@ -1097,4 +1098,55 @@ public Object getPartitionKey() {
return "key";
}
}


@Test(expected = HazelcastSerializationException.class)
public void testUnserializableResponse_exceptionPropagatesToCaller() throws Throwable {
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
HazelcastInstance instance1 = factory.newHazelcastInstance();
HazelcastInstance instance2 = factory.newHazelcastInstance();

IExecutorService service = instance1.getExecutorService("executor");
TaskWithUnserialazableResponse counterCallable = new TaskWithUnserialazableResponse();
Future future = service.submitToMember(counterCallable, instance2.getCluster().getLocalMember());
try {
future.get();
} catch (ExecutionException e) {
throw e.getCause();
}
}

@Test(expected = HazelcastSerializationException.class)
public void testUnserializableResponse_exceptionPropagatesToCallerCallback() throws Throwable {
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
HazelcastInstance instance1 = factory.newHazelcastInstance();
HazelcastInstance instance2 = factory.newHazelcastInstance();


IExecutorService service = instance1.getExecutorService("executor");
TaskWithUnserialazableResponse counterCallable = new TaskWithUnserialazableResponse();
final CountDownLatch countDownLatch = new CountDownLatch(1);
final AtomicReference<Throwable> throwable = new AtomicReference<Throwable>();
service.submitToMember(counterCallable, instance2.getCluster().getLocalMember(), new ExecutionCallback() {
@Override
public void onResponse(Object response) {

}

@Override
public void onFailure(Throwable t) {
throwable.set(t);
countDownLatch.countDown();
}
});
assertOpenEventually(countDownLatch);
throw throwable.get();
}

private static class TaskWithUnserialazableResponse implements Callable, Serializable {
@Override
public Object call() throws Exception {
return new Object();
}
}
}