代码打桩

代码打桩是代码测试使用的。激活木桩后,可以执行木桩代码。木桩的名字是任意取的。

FE 和 BE 都支持代码打桩。

木桩代码示例

FE 桩子示例代码

1. private Status foo() {
2. // dbug_fe_foo_do_nothing 是一个木桩名字,
3. // 打开这个木桩之后,DebugPointUtil.isEnable("dbug_fe_foo_do_nothing") 将会返回true
4. if (DebugPointUtil.isEnable("dbug_fe_foo_do_nothing")) {
5. return Status.Nothing;
6. }

8. do_foo_action();

10. return Status.Ok;
11. }

BE 桩子示例代码

1. void Status foo() {

3. // dbug_be_foo_do_nothing 是一个木桩名字,
4. // 打开这个木桩之后,DEBUG_EXECUTE_IF 将会执行宏参数中的代码块
5. DEBUG_EXECUTE_IF("dbug_be_foo_do_nothing",  { return Status.Nothing; });

7. do_foo_action();

9. return Status.Ok;
10. }

总开关

需要把木桩总开关 enable_debug_points 打开之后,才能激活木桩。默认情况下,木桩总开关是关闭的。

总开关enable_debug_points 分别在 FE 的 fe.conf 和 BE 的 be.conf 中配置。

打开木桩

API

1. POST /api/debug_point/add/{debug_point_name}[?timeout=<int>&execute=<int>]

参数

  • debug_point_name 木桩名字。必填。
  • timeout 超时时间,单位为秒。超时之后,木桩失活。默认值-1表示永远不超时。可填。
  • execute 木桩最大激活次数。默认值-1表示不限激活次数。可填。

Request body

无

Response

1. ```
2. {
3. msg: "OK",
4. code: 0
5. }
6. ```

Examples

打开木桩 foo,最多激活5次。

1. ```
2. curl -X POST "http://127.0.0.1:8030/api/debug_point/add/foo?execute=5"

4. ```

关闭木桩

API

1. POST /api/debug_point/remove/{debug_point_name}

参数

  • debug_point_name 木桩名字。必填。

Request body

无

Response

1. {
2. msg: "OK",
3. code: 0
4. }

Examples

关闭木桩foo。

1. ```
2. curl -X POST "http://127.0.0.1:8030/api/debug_point/remove/foo"

4. ```

清除所有木桩

API

1. POST /api/debug_point/clear

Request body

无

Response

1. ```
2. {
3. msg: "OK",
4. code: 0
5. }
6. ```

Examples

清除所有木桩。

1. ```
2. curl -X POST "http://127.0.0.1:8030/api/debug_point/clear"
3. ```