zoukankan      html  css  js  c++  java
  • 6. jam-sandbox之官方modules

    官方提供的样例包名是sandbox-debug-module.jar

    添加成功后,键入命令,可以看到如下信息

    debug-ralph :无敌破坏王,故障注入(延时、熔断、并发限流、TPS限流)
    debug-trace :模仿GREYS的trace命令
    debug-watch :模仿GREYS的watch命令
    debug-exception-logger :记录下你的应用都发生了哪些异常
    debug-servlet-access :记录下你的应用的HTTP服务请求

    沿用之前的例子(https://www.cnblogs.com/moonpool/p/14510129.html),来验证上面的module

    1. debug-trace

    参数

    需要两个参数,class和method

    调用命令

    命令行方式:

    ./sandbox.sh -p 27376 -P 37710 -n trace -d 'debug-trace/trace?class=*Controller*&method=*sandbox*'

    http方式:

    http://172.20.0.59:37710/sandbox/trace/module/http/debug-trace/trace?class=*Controller*&method=sandbox*

     

    使用命令行,会看到下面信息,表示trace成功

    当代码被执行时,会输出下面内容

    下面是浏览器执行命令后输出的内容

    2.debug-watch

    参数

    需要4个参数,class、 method、 at、  watch

    参数

    说明

    备注

    class

    类名

    类名前面最好带上*,这样就不用写完整的包名

    method

    方法名

    at

    触发点

    BEFORE,RETURN,THROWS

    watch

    观察点

    参考下表

    变量

    说明

    备注

    class

    method

    方法

    params

    入参

    是一个数组,可以打印也可以修改

    target

    目标类实例

    return

    返回值

    throws

    异常

    调用命令

    2.1 参看参数

    2.1.1 调用时参看参数

    使用下面的命令可以查看sum方法,被调用时,参数a的值

    ./sandbox.sh -p 5701 -P 37710 -n watch -d 'debug-watch/watch?class=*SandBoxImpl&method=sum&at=BEFORE&watch=params[0]'

    2.1.2 调用前后查看参数

    使用下面命令可以查看sum方法,被调用前后,参数a的值

    ./sandbox.sh -p 5701 -P 37710 -n watch -d 'debug-watch/watch?class=*SandBoxImpl&method=sum&at=BEFORE&at=RETURN&watch=params[0]'

    2.2 调用目标类的方法

    使用下面命令可以调用目标类的方法

    ./sandbox.sh -p 5701 -P 37710 -n watch -d 'debug-watch/watch?class=*SandBoxImpl&method=sum&at=BEFORE&at=RETURN&watch=target.sum(7,8)'

    2.3 查看方法的返回值

    使用下面命令可以查看方法的返回值

    ./sandbox.sh -p 5701 -P 37710 -n watch -d 'debug-watch/watch?class=*SandBoxImpl&method=sum&at=RETURN&watch=return'

    2.4 关于异常的watch

    使下面的b参数为0,来测试watch为throws的情况

    使用下面命令可以查看自己抛出的异常

    ./sandbox.sh -p 17608 -P 37710 -n watch -d 'debug-watch/watch?class=*SandBoxImpl&method=div&at=THROWS&watch=throws'

    将自己抛出的异常注释掉

    使用同样的命令,可以查看到默认抛出的异常

    ./sandbox.sh -p 17870 -P 37710 -n watch -d 'debug-watch/watch?class=*SandBoxImpl&method=div&at=THROWS&watch=throws'

    2.5 修改参数

    请求中参数b的值是0

    使用下面命令修改参数b的值,改为3,注意at=BEFORE

    ./sandbox.sh -p 17870 -P 37710 -n watch -d 'debug-watch/watch?class=mock.impl.SandBoxImpl&method=div&at=BEFORE&watch=params[1]=3'

    最终响应,为12

    2.6 在触发点调用其他类库方法

    下面命令在出发点,调用了math中min方法

    ./sandbox.sh -p 17870 -P 37710 -n watch -d 'debug-watch/watch?class=*SandBoxImpl&method=sum&at=BEFORE&watch=@@min(10,4)'

    这里的min的参数也可以使用被观察方法的入参。

    3. debug-servlet-access

    该模块使用了加载后直接触发执行的方式,所以不需要命令来启动

    /home/mock/logs/sandbox/debug/servlet-access.log

    日志内容(可以直接打印form格式参数)

    2020-12-25 18:32:18 INFO  172.18.6.105;200;POST;14ms;/basetest/base/post/form/test;[name=test&age=18&createTime=20201207&expireTime=20201208];Apache-HttpClient/4.5.12 (Java/1.8.0_251);

    4.debug-exception-logger

    使用方式同debug-servlet-access

    5.debug-ralph

  • 相关阅读:
    Struts2+Spring3+Mybatis3开发环境搭建
    spring+struts2+mybatis
    【LeetCode】Populating Next Right Pointers in Each Node
    【LeetCode】Remove Duplicates from Sorted Array
    【LeetCode】Remove Duplicates from Sorted Array II
    【LeetCode】Binary Tree Inorder Traversal
    【LeetCode】Merge Two Sorted Lists
    【LeetCode】Reverse Integer
    【LeetCode】Same Tree
    【LeetCode】Maximum Depth of Binary Tree
  • 原文地址:https://www.cnblogs.com/moonpool/p/14513008.html
Copyright © 2011-2022 走看看