You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ratis.apache.org by sz...@apache.org on 2019/11/29 00:23:35 UTC

[incubator-ratis] branch master updated: RATIS-729. Add an assertion in ClientProtoUtils#toRaftClientReplyProto. Contributed by Hanisha Koneru

This is an automated email from the ASF dual-hosted git repository.

szetszwo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-ratis.git


The following commit(s) were added to refs/heads/master by this push:
     new 22ceab2  RATIS-729. Add an assertion in ClientProtoUtils#toRaftClientReplyProto.  Contributed by Hanisha Koneru
22ceab2 is described below

commit 22ceab231cc6af7059e921bec2ff1570c1743ac2
Author: Tsz Wo Nicholas Sze <sz...@apache.org>
AuthorDate: Thu Nov 28 16:22:45 2019 -0800

    RATIS-729. Add an assertion in ClientProtoUtils#toRaftClientReplyProto.  Contributed by Hanisha Koneru
---
 .../java/org/apache/ratis/client/impl/ClientProtoUtils.java | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/ratis-client/src/main/java/org/apache/ratis/client/impl/ClientProtoUtils.java b/ratis-client/src/main/java/org/apache/ratis/client/impl/ClientProtoUtils.java
index 6492c23..e3d4dea 100644
--- a/ratis-client/src/main/java/org/apache/ratis/client/impl/ClientProtoUtils.java
+++ b/ratis-client/src/main/java/org/apache/ratis/client/impl/ClientProtoUtils.java
@@ -17,6 +17,7 @@
  */
 package org.apache.ratis.client.impl;
 
+import java.util.Optional;
 import org.apache.ratis.protocol.*;
 import org.apache.ratis.thirdparty.com.google.protobuf.ByteString;
 import org.apache.ratis.proto.RaftProtos.*;
@@ -194,6 +195,18 @@ public interface ClientProtoUtils {
             .setServerId(ProtoUtils.toRaftGroupMemberIdProtoBuilder(lnre.getServerId()));
         b.setLeaderNotReadyException(lnreBuilder);
       }
+
+      final RaftClientReplyProto serialized = b.build();
+      final RaftException e = reply.getException();
+      if (e != null) {
+        final RaftClientReply deserialized = toRaftClientReply(serialized);
+        if (!Optional.ofNullable(deserialized.getException())
+            .map(Object::getClass).filter(e.getClass()::equals).isPresent()) {
+          throw new AssertionError("Corruption while serializing reply= " + reply
+              + " but serialized=" + serialized + " and deserialized=" + deserialized, e);
+        }
+      }
+      return serialized;
     }
     return b.build();
   }