This is an automated email from the ASF dual-hosted git repository.
xyao pushed a commit to branch HDDS-2823
in repository https://gitbox.apache.org/repos/asf/hadoop-ozone.git
The following commit(s) were added to refs/heads/HDDS-2823 by this push:
new 8d74c0c HDDS-3652 Add test for SCMRatisResponse. (#1113)
8d74c0c is described below
commit 8d74c0ce586d18a1d5cd2b239dbb886b549df296
Author: Li Cheng <[email protected]>
AuthorDate: Fri Jun 26 07:52:35 2020 +0800
HDDS-3652 Add test for SCMRatisResponse. (#1113)
---
.../hadoop/hdds/scm/ha/TestSCMRatisResponse.java | 73 ++++++++++++++++++++++
1 file changed, 73 insertions(+)
diff --git
a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/ha/TestSCMRatisResponse.java
b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/ha/TestSCMRatisResponse.java
new file mode 100644
index 0000000..daf0856
--- /dev/null
+++
b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/ha/TestSCMRatisResponse.java
@@ -0,0 +1,73 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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 org.apache.hadoop.hdds.scm.ha;
+
+import com.google.protobuf.InvalidProtocolBufferException;
+import org.apache.ratis.protocol.ClientId;
+import org.apache.ratis.protocol.LeaderNotReadyException;
+import org.apache.ratis.protocol.Message;
+import org.apache.ratis.protocol.RaftClientReply;
+import org.apache.ratis.protocol.RaftException;
+import org.apache.ratis.protocol.RaftGroupId;
+import org.apache.ratis.protocol.RaftGroupMemberId;
+import org.apache.ratis.protocol.RaftPeerId;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Test for SCMRatisResponse.
+ */
+public class TestSCMRatisResponse {
+ private RaftGroupMemberId raftId;
+
+ @Before
+ public void init() {
+ raftId = RaftGroupMemberId.valueOf(
+ RaftPeerId.valueOf("peer"), RaftGroupId.randomId());
+ }
+
+ @Test
+ public void testEncodeAndDecodeSuccess() throws Exception {
+ SCMRatisResponse response = SCMRatisResponse.decode(new RaftClientReply(
+ ClientId.randomId(), raftId, 1L, true, Message.EMPTY,
+ null, 1L, null));
+ Assert.assertTrue(response.isSuccess());
+ Assert.assertEquals(Message.EMPTY,
+ SCMRatisResponse.encode(response.getResult()));
+ }
+
+ @Test
+ public void testDecodeOperationFailureWithException() throws Exception {
+ SCMRatisResponse response = SCMRatisResponse.decode(new RaftClientReply(
+ ClientId.randomId(), raftId, 1L, false, Message.EMPTY,
+ new LeaderNotReadyException(raftId), 1L, null));
+ Assert.assertFalse(response.isSuccess());
+ Assert.assertTrue(response.getException() instanceof RaftException);
+ Assert.assertNull(response.getResult());
+ }
+
+ @Test(expected = InvalidProtocolBufferException.class)
+ public void testEncodeFailureWithNonProto() throws Exception {
+ // Non proto input
+ Message message = Message.valueOf("test");
+ // Should fail with exception.
+ SCMRatisResponse.encode(message);
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]