Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
javalover123888
SkyWalking
提交
b5378e75
S
SkyWalking
项目概览
javalover123888
/
SkyWalking
与 Fork 源项目一致
Fork自
山不在高_有仙则灵 / SkyWalking
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
SkyWalking
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b5378e75
编写于
8月 30, 2018
作者:
wu-sheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add optional test case for Alarm core. Wouldn't execute in CI.
上级
c58861be
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
84 addition
and
3 deletion
+84
-3
oap-server/server-alarm-plugin/src/main/java/org/apache/skywalking/oap/server/core/alarm/provider/AlarmCore.java
.../skywalking/oap/server/core/alarm/provider/AlarmCore.java
+2
-3
oap-server/server-alarm-plugin/src/test/java/org/apache/skywalking/oap/server/core/alarm/provider/AlarmCoreTest.java
...walking/oap/server/core/alarm/provider/AlarmCoreTest.java
+82
-0
未找到文件。
oap-server/server-alarm-plugin/src/main/java/org/apache/skywalking/oap/server/core/alarm/provider/AlarmCore.java
浏览文件 @
b5378e75
...
...
@@ -65,17 +65,16 @@ public class AlarmCore {
Executors
.
newSingleThreadScheduledExecutor
().
scheduleAtFixedRate
(()
->
runningContext
.
values
().
forEach
(
ruleList
->
ruleList
.
forEach
(
runningRule
->
{
LocalDateTime
checkTime
=
LocalDateTime
.
now
();
int
minutes
=
Minutes
.
minutesBetween
(
checkTime
,
lastExecute
Time
).
getMinutes
();
int
minutes
=
Minutes
.
minutesBetween
(
lastExecuteTime
,
check
Time
).
getMinutes
();
if
(
minutes
>
0
)
{
runningRule
.
moveTo
(
checkTime
);
/**
*
At least, run 15 seconds in 1 min, alarm check should run
.
*
Don't run in the first quarter per min, avoid to trigger alarm
.
*/
if
(
checkTime
.
getSecondOfMinute
()
>
15
)
{
runningRule
.
check
();
// Set the last execute time, and make sure the second is `00`, such as: 18:30:00
lastExecuteTime
=
checkTime
.
minusSeconds
(
checkTime
.
getSecondOfMinute
());
runningRule
.
check
();
}
}
})),
10
,
10
,
TimeUnit
.
SECONDS
);
...
...
oap-server/server-alarm-plugin/src/test/java/org/apache/skywalking/oap/server/core/alarm/provider/AlarmCoreTest.java
浏览文件 @
b5378e75
...
...
@@ -18,5 +18,87 @@
package
org.apache.skywalking.oap.server.core.alarm.provider
;
import
java.util.ArrayList
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.Map
;
import
org.joda.time.LocalDateTime
;
import
org.junit.Assert
;
import
org.junit.Test
;
import
org.mockito.invocation.InvocationOnMock
;
import
org.mockito.stubbing.Answer
;
import
org.powermock.api.mockito.PowerMockito
;
import
org.powermock.reflect.Whitebox
;
/**
* Alarm core is the trigger, which should run once per minute, also run after the first quarter in one single minute.
*
* @author wusheng
*/
public
class
AlarmCoreTest
{
/**
* This case will cost several minutes, which causes CI very slow, so it only runs when -DAlarmCoreTest=true
* existed.
*/
@Test
public
void
testTriggerTimePoint
()
throws
InterruptedException
{
String
test
=
System
.
getProperty
(
"AlarmCoreTest"
);
if
(
test
==
null
)
{
return
;
}
Rules
emptyRules
=
new
Rules
();
emptyRules
.
setRules
(
new
ArrayList
<>(
0
));
emptyRules
.
setWebhooks
(
new
ArrayList
<>(
0
));
AlarmCore
core
=
new
AlarmCore
(
emptyRules
);
Map
<
String
,
List
<
RunningRule
>>
runningContext
=
Whitebox
.
getInternalState
(
core
,
"runningContext"
);
List
<
RunningRule
>
rules
=
new
ArrayList
<>(
1
);
RunningRule
mockRule
=
PowerMockito
.
mock
(
RunningRule
.
class
);
List
<
LocalDateTime
>
checkTime
=
new
LinkedList
<>();
final
boolean
[]
isAdd
=
{
true
};
PowerMockito
.
doAnswer
(
new
Answer
<
Object
>()
{
@Override
public
Object
answer
(
InvocationOnMock
mock
)
throws
Throwable
{
if
(
isAdd
[
0
])
{
checkTime
.
add
(
LocalDateTime
.
now
());
}
return
null
;
}
}).
when
(
mockRule
).
check
();
rules
.
add
(
mockRule
);
runningContext
.
put
(
"mock"
,
rules
);
core
.
start
(
new
ArrayList
<>(
0
));
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
Thread
.
sleep
(
60
*
1000L
);
if
(
checkTime
.
size
()
>=
3
)
{
isAdd
[
0
]
=
false
;
Assert
.
assertTrue
(
checkTimePoints
(
checkTime
));
break
;
}
}
}
private
boolean
checkTimePoints
(
List
<
LocalDateTime
>
checkTime
)
{
LocalDateTime
last
=
null
;
for
(
LocalDateTime
time
:
checkTime
)
{
if
(
time
.
getSecondOfMinute
()
<=
15
)
{
return
false
;
}
if
(
last
!=
null
)
{
int
lastMinuteOfHour
=
last
.
getMinuteOfHour
();
int
minuteOfHour
=
time
.
getMinuteOfHour
();
if
(!((
minuteOfHour
-
lastMinuteOfHour
==
1
)
||
(
minuteOfHour
==
0
&&
lastMinuteOfHour
==
59
)))
{
return
false
;
}
}
last
=
time
;
}
return
true
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录