Skip to content

Commit

Permalink
GEODE-5747: Handling SocketException in InternalDataSerializer (apach…
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmellawatt authored Sep 21, 2018
1 parent efb2e29 commit 6006ec3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.math.BigDecimal;
import java.math.BigInteger;
import java.net.InetAddress;
import java.net.SocketException;
import java.net.URL;
import java.sql.Timestamp;
import java.util.ArrayList;
Expand Down Expand Up @@ -2480,7 +2481,7 @@ public static void invokeFromData(Object ds, DataInput in)
((DataSerializable) ds).fromData(in);
}
}
} catch (EOFException | ClassNotFoundException | CacheClosedException ex) {
} catch (EOFException | ClassNotFoundException | CacheClosedException | SocketException ex) {
// client went away - ignore
throw ex;
} catch (Exception ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,15 @@
*/
package org.apache.geode.internal;

import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;

import java.io.DataInput;
import java.io.IOException;
import java.net.SocketException;
import java.util.Properties;

import org.apache.logging.log4j.Level;
Expand All @@ -25,6 +31,7 @@
import org.junit.Test;
import org.junit.experimental.categories.Category;

import org.apache.geode.DataSerializable;
import org.apache.geode.InternalGemFireException;
import org.apache.geode.cache.execute.Function;
import org.apache.geode.cache.execute.FunctionContext;
Expand All @@ -51,6 +58,18 @@ public void testIsGemfireObject() {
InternalDataSerializer.isGemfireObject(new ExampleSecurityManager()));
}

@Test
public void testInvokeFromData_SocketExceptionRethrown()
throws IOException, ClassNotFoundException {
DataInput in = mock(DataInput.class);
DataSerializable ds = mock(DataSerializable.class);

doThrow(SocketException.class).when(ds).fromData(in);

assertThatThrownBy(() -> InternalDataSerializer.invokeFromData(ds, in))
.isInstanceOf(SocketException.class);
}

class TestFunction implements Function {
@Override
public void execute(FunctionContext context) {
Expand Down

0 comments on commit 6006ec3

Please sign in to comment.