From 71a601241c140954cc178d75ea6afdb98a97d296 Mon Sep 17 00:00:00 2001 From: litao Date: Fri, 17 Sep 2021 14:45:14 +0800 Subject: [PATCH] HADOOP-17914. Print RPC response length in the exception message (#3436) --- .../src/main/java/org/apache/hadoop/ipc/Client.java | 6 ++++-- .../src/test/java/org/apache/hadoop/ipc/TestIPC.java | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/Client.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/Client.java index 712db04d0e..89967744d7 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/Client.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/Client.java @@ -1907,10 +1907,12 @@ public ByteBuffer readResponse() throws IOException { } } if (length <= 0) { - throw new RpcException("RPC response has invalid length"); + throw new RpcException(String.format("RPC response has " + + "invalid length of %d", length)); } if (maxResponseLength > 0 && length > maxResponseLength) { - throw new RpcException("RPC response exceeds maximum data length"); + throw new RpcException(String.format("RPC response has a " + + "length of %d exceeds maximum data length", length)); } ByteBuffer bb = ByteBuffer.allocate(length); in.readFully(bb.array()); diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ipc/TestIPC.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ipc/TestIPC.java index 99047ffd0e..95ff302103 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ipc/TestIPC.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ipc/TestIPC.java @@ -1638,8 +1638,8 @@ public void testRpcResponseLimit() throws Throwable { } catch (IOException ioe) { Assert.assertNotNull(ioe); Assert.assertEquals(RpcException.class, ioe.getClass()); - Assert.assertEquals("RPC response exceeds maximum data length", - ioe.getMessage()); + Assert.assertTrue(ioe.getMessage().contains( + "exceeds maximum data length")); return; } Assert.fail("didn't get limit exceeded");