[ 
https://issues.apache.org/jira/browse/SCB-324?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16407299#comment-16407299
 ] 

ASF GitHub Bot commented on SCB-324:
------------------------------------

liubao68 commented on a change in pull request #615: [SCB-324] Fault-Injection 
handler implementation
URL: 
https://github.com/apache/incubator-servicecomb-java-chassis/pull/615#discussion_r175967421
 
 

 ##########
 File path: 
handlers/handler-fault-injection/src/main/java/org/apache/servicecomb/faultinjection/DelayFault.java
 ##########
 @@ -0,0 +1,81 @@
+/*
+ * 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
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.servicecomb.faultinjection;
+
+import java.util.concurrent.CountDownLatch;
+
+import org.apache.servicecomb.core.Invocation;
+import org.apache.servicecomb.foundation.vertx.VertxUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+import io.vertx.core.Handler;
+import io.vertx.core.Vertx;
+
+@Component
+public class DelayFault extends AbstractFault {
+  private static final Logger LOGGER = 
LoggerFactory.getLogger(FaultInjectionHandler.class);
+
+  @Override
+  public int getPriority() {
+    return FaultInjectionConst.FAULTINJECTION_PRIORITY_MAX;
+  }
+
+  @Override
+  public FaultResponse injectFault(Invocation invocation, FaultParam 
faultAttributes) {
+    int delayPercent = FaultInjectionUtil.getFaultInjectionConfig(invocation,
+        "delay.percent");
+
+    if (delayPercent == FaultInjectionConst.FAULT_INJECTION_CFG_NULL) {
+      LOGGER.info("Fault injection: delay percentage is not configured");
+      return new FaultResponse();
+    }
+
+    // check fault delay condition.
+    boolean isDelay = 
FaultInjectionUtil.checkFaultInjectionDelayAndAbort(faultAttributes.getReqCount(),
 delayPercent);
+    if (isDelay) {
+      LOGGER.info("Fault injection: delay is added for the request by fault 
inject handler");
+      long delay = FaultInjectionUtil.getFaultInjectionConfig(invocation,
+          "delay.fixedDelay");
+
+      if (delay == FaultInjectionConst.FAULT_INJECTION_CFG_NULL) {
+        LOGGER.info("Fault injection: delay is not configured");
+        return new FaultResponse();
+      }
+
+      CountDownLatch latch = new CountDownLatch(1);
+      Vertx vertx = VertxUtils.getOrCreateVertxByName("faultinjection", null);
+      vertx.setTimer(delay, new Handler<Long>() {
+        @Override
+        public void handle(Long timeID) {
+          latch.countDown();
+        }
+      });
+
+      try {
+        latch.await();
+      } catch (InterruptedException e) {
+        LOGGER.info("Interrupted exception is received");
+      }
 
 Review comment:
   This code may cause dead lock

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Chassis must support network failure simulation, so that I can developers can 
> enhance the robustness of the app
> ---------------------------------------------------------------------------------------------------------------
>
>                 Key: SCB-324
>                 URL: https://issues.apache.org/jira/browse/SCB-324
>             Project: Apache ServiceComb
>          Issue Type: Task
>          Components: Java-Chassis
>            Reporter: sukesh
>            Assignee: sukesh
>            Priority: Minor
>             Fix For: java-chassis-1.0.0-m2
>
>
> Add new handler for fault injection.
> 1) If handler 'fault-injection' is added in application property 
> file(microservice.yaml) then fault-injection handler should include in 
> handler chain.
> 2) When handler is called read the configuration and listen the configuration 
> event related to fault inject. The sample configuration file is in next slide.
> 3) The configuration mainly consist
>     -delay
>     -abort
>  *delay:*can set the delay for requests based on percentage configured. The 
> unit is ms. The delay percentage default value is 100%
>  *abort*: Abort the requests based on percentage configured. For rest 
> transport protocol error code can be configurable(500, 421) and highway 
> protocol does not support for error return. The abort percentage default 
> value is 100%
> 4) This features currently supports at consumer side.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to