chaosblade-help-zh-CN
  • README
  • blade
  • blade create
  • blade create cpu load
  • blade create disk burn
  • blade create disk fill
  • blade create mem load
  • blade create network delay
  • blade create network dns
  • blade create network drop
  • blade create network loss
  • blade create network corrupt
  • blade create network reorder
  • blade create network duplicate
  • blade create network occupy
  • blade create process kill
  • blade create process stop
  • blade create script delay
  • blade create script exit
  • blade create docker
    • blade create docker cpu
    • blade create docker network
    • blade create docker process
    • blade create docker container
  • blade create k8s
    • blade create k8s node-cpu
    • blade create k8s node-network
    • blade create k8s node-process
    • blade create k8s node-disk
    • blade create k8s pod-pod
    • blade create k8s pod-IO
    • blade create k8s pod-network
    • blade create k8s container-cpu
    • blade create k8s container-network
    • blade create k8s container-process
    • blade create k8s container-container
  • blade prepare jvm
  • blade create jvm
    • blade create jvm delay
    • blade create jvm return
    • blade create jvm script
    • blade create jvm cpufullload
    • blade create jvm OutOfMemoryError
    • blade create jvm CodeCacheFilling
    • blade create jvm throwCustomException
  • blade create servlet
    • blade create servlet delay
    • blade create servlet throwCustomException
  • blade server
  • blade status
  • blade version
Powered by GitBook
On this page
  • 介绍
  • 参数
  • 案例
  • 常见问题

Was this helpful?

  1. blade create jvm

blade create jvm return

介绍

指定类方法的返回值,仅支持基本类型、null 和 String 类型的返回值。

参数

以下是此场景特有参数,通用参数详见:[blade create jvm](blade create jvm.md)

--effect-count string     影响的请求条数
--effect-percent string   影响的请求百分比
--value string     返回指定值,仅支持基本类型和字符串类型,如果想返回 null,可以设置为 --value null 。必选项

案例

指定com.example.controller.DubboController类,下面业务方法返回 "hello-chaosblade"

@RequestMapping(value = "hello")
@ResponseBody
public String hello(String name, int code) {
    if (name == null) {
        name = "friend";
    }
    StringBuilder result = null;
    try {
        result = new StringBuilder(sayHello(name));
    } catch (Exception e) {
        return e.getMessage() + "\n";
    }
    return result.toString() + "\n";
}

故障注入命令如下:

blade c jvm return --value hello-chaosblade --classname com.example.controller.DubboController --methodname hello --process tomcat

停止实验:

blade d d31e24dea782a275

上述代码调用 sayHello 方法,我们对 sayHello 方法注入返回 null 故障,sayHello 方法如下:

private String sayHello(String name) throws BeansException {
    demoService = (DemoService)SpringContextUtil.getBean("demoService");
    StringBuilder result = new StringBuilder();
    result.append(demoService.sayHello(name));
    return result.toString();
}

执行以下命令:

blade c jvm return --value null --classname com.example.controller.DubboController --methodname sayHello --process tomcat

常见问题

Previousblade create jvm delayNextblade create jvm script

Last updated 3 years ago

Was this helpful?

故障注入之前:

故障注入之后:

故障注入之后: