GlenGeng commented on a change in pull request #1650:
URL: https://github.com/apache/ozone/pull/1650#discussion_r550410187
##########
File path:
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/ha/MockSCMHAManager.java
##########
@@ -92,11 +92,20 @@ public void shutdown() throws IOException {
ratisServer.stop();
}
- private class MockRatisServer implements SCMRatisServer {
+ /**
+ * Mock RatisServer implementation for testing.
Review comment:
Hey Rui, changes in MockSCMHAManager.java may not be needed, since
MockRatisServer is an inner class of MockSCMHAManager,
##########
File path:
hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/ha/TestReplicationAnnotation.java
##########
@@ -0,0 +1,139 @@
+/*
+ * 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 org.apache.hadoop.hdds.protocol.proto.HddsProtos;
+import org.apache.hadoop.hdds.protocol.proto.SCMRatisProtocol.RequestType;
+import org.apache.hadoop.hdds.scm.container.ContainerID;
+import org.apache.hadoop.hdds.scm.container.ContainerInfo;
+import org.apache.hadoop.hdds.scm.container.ContainerReplica;
+import org.apache.hadoop.hdds.scm.container.ContainerStateManagerV2;
+import org.apache.hadoop.hdds.scm.pipeline.PipelineID;
+import
org.apache.hadoop.ozone.common.statemachine.InvalidStateTransitionException;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.util.Map;
+import java.util.NavigableSet;
+import java.util.Set;
+
+/**
+ * Tests on {@link org.apache.hadoop.hdds.scm.metadata.Replicate}.
+ */
+public class TestReplicationAnnotation {
+ private SCMHAInvocationHandler scmhaInvocationHandler;
+ private ContainerStateManagerV2 mockCSM;
+
+ @Before
+ public void setup() {
+ SCMHAManager mock = MockSCMHAManager.getInstance(true);
+ mockCSM = new ContainerStateManagerV2() {
+ @Override
+ public boolean contains(HddsProtos.ContainerID containerID) {
+ return false;
+ }
+
+ @Override
+ public Set<ContainerID> getContainerIDs() {
+ return null;
+ }
+
+ @Override
+ public Set<ContainerID> getContainerIDs(
+ HddsProtos.LifeCycleState state) {
+ return null;
+ }
+
+ @Override
+ public ContainerInfo getContainer(HddsProtos.ContainerID id) {
+ return null;
+ }
+
+ @Override
+ public Set<ContainerReplica> getContainerReplicas(
+ HddsProtos.ContainerID id) {
+ return null;
+ }
+
+ @Override
+ public void updateContainerReplica(
+ HddsProtos.ContainerID id, ContainerReplica replica) {
+
+ }
+
+ @Override
+ public void removeContainerReplica(
+ HddsProtos.ContainerID id, ContainerReplica replica) {
+
+ }
+
+ @Override
+ public void addContainer(HddsProtos.ContainerInfoProto containerInfo)
+ throws IOException {
+
+ }
+
+ @Override
+ public void updateContainerState(
+ HddsProtos.ContainerID id, HddsProtos.LifeCycleEvent event)
+ throws IOException, InvalidStateTransitionException {
+
+ }
+
+ @Override
+ public void updateDeleteTransactionId(
+ Map<ContainerID, Long> deleteTransactionMap) throws IOException {
+
+ }
+
+ @Override
+ public ContainerInfo getMatchingContainer(
+ long size, String owner, PipelineID pipelineID,
+ NavigableSet<ContainerID> containerIDs) {
+ return null;
+ }
+
+ @Override
+ public void removeContainer(HddsProtos.ContainerID containerInfo)
+ throws IOException {
+ }
+
+ @Override
+ public void close() throws IOException {
+
+ }
+ };
+
+ scmhaInvocationHandler = new SCMHAInvocationHandler(
+ RequestType.CONTAINER, mockCSM, mock.getRatisServer());
+ }
+
+ @Test
+ public void testReplicateAnnotationBasic() throws Throwable {
+ // test whether this call will hit the Ratis based replication
+ // code path in SCMHAInvocationHandler. The invoke() can return means the
+ // request is handled properly thus response is successful. Expected
+ // result is null because the function returns nothing.
+ Object[] arguments = {HddsProtos.ContainerInfoProto.getDefaultInstance()};
+ Assert.assertEquals(null, scmhaInvocationHandler.invoke(new Object(),
Review comment:
Hey Rui, I consider you have to use my anonymous version of
SCMRatisServer,
because of
```
@Override
public SCMRatisResponse submitRequest(SCMRatisRequest request) throws
IOException, ExecutionException, InterruptedException {
throw new IOException("submitRequest is called.");
}
```
,
from the IOException
```
ContainerStateManagerV2 proxy = (ContainerStateManagerV2)
Proxy.newProxyInstance(
SCMHAInvocationHandler.class.getClassLoader(),
new Class<?>[]{ContainerStateManagerV2.class}, invocationHandler);
try {
proxy.addContainer(HddsProtos.ContainerInfoProto.getDefaultInstance());
Assert.fail();
} catch (IOException ignore) {
}
```
we can know that `invokeRatis()` is called, due to the annotation.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]