This is an automated email from the ASF dual-hosted git repository.
sammichen 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 7287e1d HDDS-3651 Add tests for SCMRatisRequest. (#1112)
7287e1d is described below
commit 7287e1dfc2e00d9eefaec3b046be2a583cacbfed
Author: Li Cheng <[email protected]>
AuthorDate: Sun Jun 28 18:06:27 2020 +0800
HDDS-3651 Add tests for SCMRatisRequest. (#1112)
---
.../apache/hadoop/hdds/scm/ha/SCMRatisRequest.java | 1 +
.../hadoop/hdds/scm/ha/TestSCMRatisRequest.java | 63 ++++++++++++++++++++++
2 files changed, 64 insertions(+)
diff --git
a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/ha/SCMRatisRequest.java
b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/ha/SCMRatisRequest.java
index 3e51653..fbba4d0 100644
---
a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/ha/SCMRatisRequest.java
+++
b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/ha/SCMRatisRequest.java
@@ -106,6 +106,7 @@ public final class SCMRatisRequest {
args.add(argBuilder.build());
}
methodBuilder.addAllArgs(args);
+ requestProtoBuilder.setMethod(methodBuilder.build());
return Message.valueOf(
org.apache.ratis.thirdparty.com.google.protobuf.ByteString.copyFrom(
requestProtoBuilder.build().toByteArray()));
diff --git
a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/ha/TestSCMRatisRequest.java
b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/ha/TestSCMRatisRequest.java
new file mode 100644
index 0000000..52d2ff3
--- /dev/null
+++
b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/ha/TestSCMRatisRequest.java
@@ -0,0 +1,63 @@
+/**
+ * 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.hadoop.hdds.scm.pipeline.PipelineID;
+import org.apache.ratis.protocol.Message;
+import org.junit.Assert;
+import org.junit.Test;
+
+import static
org.apache.hadoop.hdds.protocol.proto.SCMRatisProtocol.RequestType.PIPELINE;
+
+/**
+ * Test for SCMRatisRequest.
+ */
+public class TestSCMRatisRequest {
+
+ @Test
+ public void testEncodeAndDecodeSuccess() throws Exception {
+ PipelineID pipelineID = PipelineID.randomId();
+ Object[] args = new Object[] {pipelineID.getProtobuf()};
+ String operation = "test";
+ SCMRatisRequest request = SCMRatisRequest.of(PIPELINE, operation, args);
+ Assert.assertEquals(operation,
+ SCMRatisRequest.decode(request.encode()).getOperation());
+ Assert.assertEquals(args[0],
+ SCMRatisRequest.decode(request.encode()).getArguments()[0]);
+ }
+
+ @Test(expected = InvalidProtocolBufferException.class)
+ public void testEncodeWithNonProto() throws Exception{
+ PipelineID pipelineID = PipelineID.randomId();
+ // Non proto args
+ Object[] args = new Object[] {pipelineID};
+ SCMRatisRequest request = SCMRatisRequest.of(PIPELINE, "test", args);
+ // Should throw exception there.
+ request.encode();
+ }
+
+ @Test(expected = InvalidProtocolBufferException.class)
+ public void testDecodeWithNonProto() throws Exception {
+ // Non proto message
+ Message message = Message.valueOf("randomMessage");
+ // Should throw exception there.
+ SCMRatisRequest.decode(message);
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]