From 86f2aff5841e41ac3223233d5c446bded1ddfe16 Mon Sep 17 00:00:00 2001 From: Minwoo Jung Date: Wed, 19 Aug 2015 11:56:32 +0900 Subject: [PATCH] [#762] add serviceType infomation for rule because select box component need service type information. --- .../navercorp/pinpoint/web/alarm/vo/Rule.java | 20 +- .../main/resources/mapper/Alarm2Mapper.xml | 70 ---- web/src/main/resources/mapper/AlarmMapper.xml | 6 +- .../resources/sql/CreateTableStatement.sql | 3 +- .../web/alarm/CheckerCategoryTest.java | 98 +++--- .../pinpoint/web/alarm/ReaderTest.java | 3 +- .../pinpoint/web/alarm/WriterTest.java | 168 +++++----- .../alarm/checker/ErrorCountCheckerTest.java | 209 ++++++------ .../checker/ErrorCountToCalleCheckerTest.java | 7 +- .../alarm/checker/ErrorRateCheckerTest.java | 207 ++++++------ .../checker/ErrorRateToCalleCheckerTest.java | 8 +- .../web/alarm/checker/GcCountCheckerTest.java | 265 +++++++-------- .../checker/HeapUsageRateCheckerTest.java | 303 +++++++++--------- .../checker/JvmCpuUsageRateCheckerTest.java | 265 +++++++-------- .../checker/ResponseCountCheckerTest.java | 211 ++++++------ .../alarm/checker/SlowCountCheckerTest.java | 255 +++++++-------- .../checker/SlowCountToCalleCheckerTest.java | 7 +- .../alarm/checker/SlowRateCheckerTest.java | 211 ++++++------ .../checker/SlowRateToCalleCheckerTest.java | 7 +- .../checker/TotalCountToCalleCheckerTest.java | 7 +- .../web/controller/AlarmControllerTest.java | 21 +- 21 files changed, 1156 insertions(+), 1195 deletions(-) delete mode 100644 web/src/main/resources/mapper/Alarm2Mapper.xml diff --git a/web/src/main/java/com/navercorp/pinpoint/web/alarm/vo/Rule.java b/web/src/main/java/com/navercorp/pinpoint/web/alarm/vo/Rule.java index 58a2bcc86..983ad8660 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/alarm/vo/Rule.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/alarm/vo/Rule.java @@ -23,7 +23,8 @@ public class Rule { private String ruleId; private String applicationId; - private String CheckerName; + private String serviceType; + private String checkerName; private Integer threshold; private String userGroupId; private boolean smsSend; @@ -33,9 +34,10 @@ public class Rule { public Rule() { } - public Rule(String applicationId, String checkerName, Integer Threshold, String userGroupId, boolean smsSend, boolean emailSend, String notes) { + public Rule(String applicationId, String serviceType, String checkerName, Integer Threshold, String userGroupId, boolean smsSend, boolean emailSend, String notes) { this.applicationId = applicationId; - this.CheckerName = checkerName; + this.serviceType = serviceType; + this.checkerName = checkerName; this.threshold = Threshold; this.userGroupId = userGroupId; this.smsSend = smsSend; @@ -51,12 +53,20 @@ public class Rule { this.applicationId = applicationId; } + public String getServiceType() { + return serviceType; + } + + public void setServiceType(String serviceType) { + this.serviceType = serviceType; + } + public String getCheckerName() { - return CheckerName; + return checkerName; } public void setCheckerName(String checkerName) { - CheckerName = checkerName; + this.checkerName = checkerName; } public Integer getThreshold() { diff --git a/web/src/main/resources/mapper/Alarm2Mapper.xml b/web/src/main/resources/mapper/Alarm2Mapper.xml deleted file mode 100644 index 64a77013b..000000000 --- a/web/src/main/resources/mapper/Alarm2Mapper.xml +++ /dev/null @@ -1,70 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/web/src/main/resources/mapper/AlarmMapper.xml b/web/src/main/resources/mapper/AlarmMapper.xml index 3d31e3e12..562d32706 100644 --- a/web/src/main/resources/mapper/AlarmMapper.xml +++ b/web/src/main/resources/mapper/AlarmMapper.xml @@ -4,9 +4,9 @@ - INSERT INTO alarm_rule(application_id, checker_name, threshold, user_group_id, sms_send, email_send, notes) + INSERT INTO alarm_rule(application_id, service_type, checker_name, threshold, user_group_id, sms_send, email_send, notes) VALUES - (#{applicationId}, #{checkerName}, #{threshold}, #{userGroupId}, #{smsSend}, #{emailSend}, #{notes}) + (#{applicationId}, #{serviceType}, #{checkerName}, #{threshold}, #{userGroupId}, #{smsSend}, #{emailSend}, #{notes}) @@ -35,7 +35,7 @@ UPDATE alarm_rule - SET application_id = #{applicationId}, checker_name = #{checkerName}, threshold = #{threshold}, user_group_id = #{userGroupId}, sms_send = #{smsSend}, email_send = #{emailSend}, notes = #{notes} + SET application_id = #{applicationId}, service_type = #{serviceType}, checker_name = #{checkerName}, threshold = #{threshold}, user_group_id = #{userGroupId}, sms_send = #{smsSend}, email_send = #{emailSend}, notes = #{notes} WHERE rule_id = #{ruleId} diff --git a/web/src/main/resources/sql/CreateTableStatement.sql b/web/src/main/resources/sql/CreateTableStatement.sql index 688c74785..5d5727625 100644 --- a/web/src/main/resources/sql/CreateTableStatement.sql +++ b/web/src/main/resources/sql/CreateTableStatement.sql @@ -28,12 +28,13 @@ CREATE TABLE `user` ( CREATE TABLE `alarm_rule` ( `rule_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, `application_id` VARCHAR(30) NOT NULL, + `service_type` VARCHAR(30) NOT NULL, `checker_name` VARCHAR(30) NOT NULL, `threshold` INT(10) DEFAULT NULL, `user_group_id` VARCHAR(30) NOT NULL, `sms_send` CHAR(1) DEFAULT NULL, `email_send` CHAR(1) DEFAULT NULL, `notes` VARCHAR(50) DEFAULT NULL, - PRIMARY KEY (`rule_id`), + PRIMARY KEY (`rule_id`) ); ALTER TABLE alarm_rule ADD UNIQUE KEY application_id_checker_name_user_group_id_idx (application_id, user_group_id, checker_name); diff --git a/web/src/test/java/com/navercorp/pinpoint/web/alarm/CheckerCategoryTest.java b/web/src/test/java/com/navercorp/pinpoint/web/alarm/CheckerCategoryTest.java index bf44212da..b3c86da33 100644 --- a/web/src/test/java/com/navercorp/pinpoint/web/alarm/CheckerCategoryTest.java +++ b/web/src/test/java/com/navercorp/pinpoint/web/alarm/CheckerCategoryTest.java @@ -1,49 +1,49 @@ -/* - * Copyright 2014 NAVER Corp. - * - * Licensed 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 com.navercorp.pinpoint.web.alarm; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNotSame; - -import org.junit.Test; - -import com.navercorp.pinpoint.web.alarm.CheckerCategory; -import com.navercorp.pinpoint.web.alarm.checker.SlowCountChecker; -import com.navercorp.pinpoint.web.alarm.vo.Rule; - -public class CheckerCategoryTest { - - @Test - public void createCheckerTest() { - CheckerCategory slowCount = CheckerCategory.getValue("slow_count"); - - Rule rule = new Rule(null, CheckerCategory.SLOW_COUNT.getName(), 75, "testGroup", false, false, ""); - SlowCountChecker checker = (SlowCountChecker) slowCount.createChecker(null, rule); - rule = new Rule(null, CheckerCategory.SLOW_COUNT.getName(), 63, "testGroup", false, false, ""); - SlowCountChecker checker2 = (SlowCountChecker) slowCount.createChecker(null, rule); - - assertNotSame(checker, checker2); - - assertNotNull(checker); - assertEquals(75, (int)checker.getRule().getThreshold()); - - assertNotNull(checker2); - assertEquals(63, (int)checker2.getRule().getThreshold()); - } - -} +/* + * Copyright 2014 NAVER Corp. + * + * Licensed 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 com.navercorp.pinpoint.web.alarm; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNotSame; + +import org.junit.Test; + +import com.navercorp.pinpoint.web.alarm.CheckerCategory; +import com.navercorp.pinpoint.web.alarm.checker.SlowCountChecker; +import com.navercorp.pinpoint.web.alarm.vo.Rule; + +public class CheckerCategoryTest { + + @Test + public void createCheckerTest() { + CheckerCategory slowCount = CheckerCategory.getValue("slow_count"); + + Rule rule = new Rule(null, "", CheckerCategory.SLOW_COUNT.getName(), 75, "testGroup", false, false, ""); + SlowCountChecker checker = (SlowCountChecker) slowCount.createChecker(null, rule); + rule = new Rule(null, "", CheckerCategory.SLOW_COUNT.getName(), 63, "testGroup", false, false, ""); + SlowCountChecker checker2 = (SlowCountChecker) slowCount.createChecker(null, rule); + + assertNotSame(checker, checker2); + + assertNotNull(checker); + assertEquals(75, (int)checker.getRule().getThreshold()); + + assertNotNull(checker2); + assertEquals(63, (int)checker2.getRule().getThreshold()); + } + +} diff --git a/web/src/test/java/com/navercorp/pinpoint/web/alarm/ReaderTest.java b/web/src/test/java/com/navercorp/pinpoint/web/alarm/ReaderTest.java index ca30735c7..d9bf21eee 100644 --- a/web/src/test/java/com/navercorp/pinpoint/web/alarm/ReaderTest.java +++ b/web/src/test/java/com/navercorp/pinpoint/web/alarm/ReaderTest.java @@ -44,6 +44,7 @@ public class ReaderTest { private static AlarmService alarmService; private static DataCollectorFactory dataCollectorFactory; private static final String APP_NAME = "app"; + private static final String SERVICE_TYPE = "tomcat"; @Test public void readTest() { @@ -127,7 +128,7 @@ public class ReaderTest { ruleMap = new HashMap(); for(int i = 0; i <=6; i++) { - ruleMap.put(APP_NAME + i, new Rule(APP_NAME + i, CheckerCategory.SLOW_COUNT.getName(), 76, "testGroup", false, false, "")); + ruleMap.put(APP_NAME + i, new Rule(APP_NAME + i, SERVICE_TYPE, CheckerCategory.SLOW_COUNT.getName(), 76, "testGroup", false, false, "")); } } diff --git a/web/src/test/java/com/navercorp/pinpoint/web/alarm/WriterTest.java b/web/src/test/java/com/navercorp/pinpoint/web/alarm/WriterTest.java index 369228d0a..d3ad13b5c 100644 --- a/web/src/test/java/com/navercorp/pinpoint/web/alarm/WriterTest.java +++ b/web/src/test/java/com/navercorp/pinpoint/web/alarm/WriterTest.java @@ -1,84 +1,84 @@ -/* - * Copyright 2014 NAVER Corp. - * - * Licensed 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 com.navercorp.pinpoint.web.alarm; - -import java.util.LinkedList; -import java.util.List; - -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import com.navercorp.pinpoint.web.alarm.AlarmWriter; -import com.navercorp.pinpoint.web.alarm.CheckerCategory; -import com.navercorp.pinpoint.web.alarm.checker.AlarmChecker; -import com.navercorp.pinpoint.web.alarm.checker.SlowCountChecker; -import com.navercorp.pinpoint.web.alarm.vo.Rule; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration("classpath:applicationContext-test.xml") -public class WriterTest { - - @Autowired - AlarmWriter writer; - - @Ignore - @Test - public void smsSendTest() throws Exception { - Rule rule = new Rule("testService", CheckerCategory.SLOW_COUNT.getName(), 100, "testGroup", true, false, ""); - SlowCountChecker checker = new SlowCountChecker(null, rule) { - @Override - public boolean isDetected() { - return true; - } - - @Override - protected long getDetectedValue() { - return 10000; - } - }; - - List checkers = new LinkedList(); - checkers.add(checker); - writer.write(checkers); - } - - @Ignore - @Test - public void emailSendTest() throws Exception { - Rule rule = new Rule("testService", CheckerCategory.SLOW_COUNT.getName(), 100, "testGroup", false, true, ""); - SlowCountChecker checker = new SlowCountChecker(null, rule) { - @Override - public boolean isDetected() { - return true; - } - - @Override - protected long getDetectedValue() { - return 10000; - } - }; - - List checkers = new LinkedList(); - checkers.add(checker); - writer.write(checkers); - } - -} +/* + * Copyright 2014 NAVER Corp. + * + * Licensed 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 com.navercorp.pinpoint.web.alarm; + +import java.util.LinkedList; +import java.util.List; + +import org.junit.Ignore; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import com.navercorp.pinpoint.web.alarm.AlarmWriter; +import com.navercorp.pinpoint.web.alarm.CheckerCategory; +import com.navercorp.pinpoint.web.alarm.checker.AlarmChecker; +import com.navercorp.pinpoint.web.alarm.checker.SlowCountChecker; +import com.navercorp.pinpoint.web.alarm.vo.Rule; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration("classpath:applicationContext-test.xml") +public class WriterTest { + + @Autowired + AlarmWriter writer; + + @Ignore + @Test + public void smsSendTest() throws Exception { + Rule rule = new Rule("testService", "tomcat", CheckerCategory.SLOW_COUNT.getName(), 100, "testGroup", true, false, ""); + SlowCountChecker checker = new SlowCountChecker(null, rule) { + @Override + public boolean isDetected() { + return true; + } + + @Override + protected long getDetectedValue() { + return 10000; + } + }; + + List checkers = new LinkedList(); + checkers.add(checker); + writer.write(checkers); + } + + @Ignore + @Test + public void emailSendTest() throws Exception { + Rule rule = new Rule("testService", "tomcat", CheckerCategory.SLOW_COUNT.getName(), 100, "testGroup", false, true, ""); + SlowCountChecker checker = new SlowCountChecker(null, rule) { + @Override + public boolean isDetected() { + return true; + } + + @Override + protected long getDetectedValue() { + return 10000; + } + }; + + List checkers = new LinkedList(); + checkers.add(checker); + writer.write(checkers); + } + +} diff --git a/web/src/test/java/com/navercorp/pinpoint/web/alarm/checker/ErrorCountCheckerTest.java b/web/src/test/java/com/navercorp/pinpoint/web/alarm/checker/ErrorCountCheckerTest.java index 22290cd03..782f1a3d6 100644 --- a/web/src/test/java/com/navercorp/pinpoint/web/alarm/checker/ErrorCountCheckerTest.java +++ b/web/src/test/java/com/navercorp/pinpoint/web/alarm/checker/ErrorCountCheckerTest.java @@ -1,104 +1,105 @@ -/* - * Copyright 2014 NAVER Corp. - * - * Licensed 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 com.navercorp.pinpoint.web.alarm.checker; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.util.LinkedList; -import java.util.List; - -import org.junit.BeforeClass; -import org.junit.Test; - -import com.navercorp.pinpoint.common.trace.ServiceType; -import com.navercorp.pinpoint.web.alarm.CheckerCategory; -import com.navercorp.pinpoint.web.alarm.DataCollectorFactory.DataCollectorCategory; -import com.navercorp.pinpoint.web.alarm.checker.ErrorCountChecker; -import com.navercorp.pinpoint.web.alarm.collector.ResponseTimeDataCollector; -import com.navercorp.pinpoint.web.alarm.vo.Rule; -import com.navercorp.pinpoint.web.applicationmap.histogram.TimeHistogram; -import com.navercorp.pinpoint.web.dao.MapResponseDao; -import com.navercorp.pinpoint.web.vo.Application; -import com.navercorp.pinpoint.web.vo.Range; -import com.navercorp.pinpoint.web.vo.ResponseTime; - -public class ErrorCountCheckerTest { - - private static final String SERVICE_NAME = "local_service"; - - private static MapResponseDao mockMapResponseDAO; - - @BeforeClass - public static void before() { - mockMapResponseDAO = new MapResponseDao() { - - @Override - public List selectResponseTime(Application application, Range range) { - List list = new LinkedList(); - long timeStamp = 1409814914298L; - ResponseTime responseTime = new ResponseTime(SERVICE_NAME, ServiceType.STAND_ALONE, timeStamp); - list.add(responseTime); - TimeHistogram histogram = null; - - for (int i=0 ; i < 5; i++) { - for (int j=0 ; j < 5; j++) { - histogram = new TimeHistogram(ServiceType.STAND_ALONE, timeStamp); - histogram.addCallCountByElapsedTime(1000); - histogram.addCallCountByElapsedTime(3000); - histogram.addCallCountByElapsedTime(-1); - histogram.addCallCountByElapsedTime(-1); - histogram.addCallCountByElapsedTime(-1); - responseTime.addResponseTime("agent_" + i + "_" + j, histogram); - } - - timeStamp += 1; - } - - return list; - } - }; - } - - /* - * alert conditions not satisfied - */ - @Test - public void checkTest1() { - Application application = new Application(SERVICE_NAME, ServiceType.STAND_ALONE); - ResponseTimeDataCollector collector = new ResponseTimeDataCollector(DataCollectorCategory.RESPONSE_TIME, application, mockMapResponseDAO, System.currentTimeMillis(), 300000); - Rule rule = new Rule(SERVICE_NAME, CheckerCategory.ERROR_COUNT.getName(), 74, "testGroup", false, false, ""); - ErrorCountChecker filter = new ErrorCountChecker(collector, rule); - - filter.check(); - assertTrue(filter.isDetected()); - } - - /* - * alert conditions not satisfied - */ - @Test - public void checkTest2() { - Application application = new Application(SERVICE_NAME, ServiceType.STAND_ALONE); - ResponseTimeDataCollector collector = new ResponseTimeDataCollector(DataCollectorCategory.RESPONSE_TIME, application, mockMapResponseDAO, System.currentTimeMillis(), 300000); - Rule rule = new Rule(SERVICE_NAME, CheckerCategory.ERROR_COUNT.getName(), 76, "testGroup", false, false, ""); - ErrorCountChecker filter = new ErrorCountChecker(collector, rule); - - filter.check(); - assertFalse(filter.isDetected()); - } -} +/* + * Copyright 2014 NAVER Corp. + * + * Licensed 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 com.navercorp.pinpoint.web.alarm.checker; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.util.LinkedList; +import java.util.List; + +import org.junit.BeforeClass; +import org.junit.Test; + +import com.navercorp.pinpoint.common.trace.ServiceType; +import com.navercorp.pinpoint.web.alarm.CheckerCategory; +import com.navercorp.pinpoint.web.alarm.DataCollectorFactory.DataCollectorCategory; +import com.navercorp.pinpoint.web.alarm.checker.ErrorCountChecker; +import com.navercorp.pinpoint.web.alarm.collector.ResponseTimeDataCollector; +import com.navercorp.pinpoint.web.alarm.vo.Rule; +import com.navercorp.pinpoint.web.applicationmap.histogram.TimeHistogram; +import com.navercorp.pinpoint.web.dao.MapResponseDao; +import com.navercorp.pinpoint.web.vo.Application; +import com.navercorp.pinpoint.web.vo.Range; +import com.navercorp.pinpoint.web.vo.ResponseTime; + +public class ErrorCountCheckerTest { + + private static final String SERVICE_NAME = "local_service"; + private static final String SERVICE_TYPE = "tomcat"; + + private static MapResponseDao mockMapResponseDAO; + + @BeforeClass + public static void before() { + mockMapResponseDAO = new MapResponseDao() { + + @Override + public List selectResponseTime(Application application, Range range) { + List list = new LinkedList(); + long timeStamp = 1409814914298L; + ResponseTime responseTime = new ResponseTime(SERVICE_NAME, ServiceType.STAND_ALONE, timeStamp); + list.add(responseTime); + TimeHistogram histogram = null; + + for (int i=0 ; i < 5; i++) { + for (int j=0 ; j < 5; j++) { + histogram = new TimeHistogram(ServiceType.STAND_ALONE, timeStamp); + histogram.addCallCountByElapsedTime(1000); + histogram.addCallCountByElapsedTime(3000); + histogram.addCallCountByElapsedTime(-1); + histogram.addCallCountByElapsedTime(-1); + histogram.addCallCountByElapsedTime(-1); + responseTime.addResponseTime("agent_" + i + "_" + j, histogram); + } + + timeStamp += 1; + } + + return list; + } + }; + } + + /* + * alert conditions not satisfied + */ + @Test + public void checkTest1() { + Application application = new Application(SERVICE_NAME, ServiceType.STAND_ALONE); + ResponseTimeDataCollector collector = new ResponseTimeDataCollector(DataCollectorCategory.RESPONSE_TIME, application, mockMapResponseDAO, System.currentTimeMillis(), 300000); + Rule rule = new Rule(SERVICE_NAME, SERVICE_TYPE, CheckerCategory.ERROR_COUNT.getName(), 74, "testGroup", false, false, ""); + ErrorCountChecker filter = new ErrorCountChecker(collector, rule); + + filter.check(); + assertTrue(filter.isDetected()); + } + + /* + * alert conditions not satisfied + */ + @Test + public void checkTest2() { + Application application = new Application(SERVICE_NAME, ServiceType.STAND_ALONE); + ResponseTimeDataCollector collector = new ResponseTimeDataCollector(DataCollectorCategory.RESPONSE_TIME, application, mockMapResponseDAO, System.currentTimeMillis(), 300000); + Rule rule = new Rule(SERVICE_NAME, SERVICE_TYPE, CheckerCategory.ERROR_COUNT.getName(), 76, "testGroup", false, false, ""); + ErrorCountChecker filter = new ErrorCountChecker(collector, rule); + + filter.check(); + assertFalse(filter.isDetected()); + } +} diff --git a/web/src/test/java/com/navercorp/pinpoint/web/alarm/checker/ErrorCountToCalleCheckerTest.java b/web/src/test/java/com/navercorp/pinpoint/web/alarm/checker/ErrorCountToCalleCheckerTest.java index 82fffb9df..0785795a7 100644 --- a/web/src/test/java/com/navercorp/pinpoint/web/alarm/checker/ErrorCountToCalleCheckerTest.java +++ b/web/src/test/java/com/navercorp/pinpoint/web/alarm/checker/ErrorCountToCalleCheckerTest.java @@ -43,6 +43,7 @@ public class ErrorCountToCalleCheckerTest { private static final String FROM_SERVICE_NAME = "from_local_service"; private static final String TO_SERVICE_NAME = "to_local_service"; + private static final String SERVICE_TYPE = "tomcat"; public static MapStatisticsCallerDao dao; @BeforeClass @@ -90,7 +91,7 @@ public class ErrorCountToCalleCheckerTest { public void checkTest() { Application application = new Application(FROM_SERVICE_NAME, ServiceType.STAND_ALONE); MapStatisticsCallerDataCollector dataCollector = new MapStatisticsCallerDataCollector(DataCollectorCategory.CALLER_STAT, application, dao, System.currentTimeMillis(), 300000); - Rule rule = new Rule(FROM_SERVICE_NAME, CheckerCategory.ERROR_COUNT_TO_CALLEE.getName(), 5, "testGroup", false, false, TO_SERVICE_NAME + 1); + Rule rule = new Rule(FROM_SERVICE_NAME, SERVICE_TYPE, CheckerCategory.ERROR_COUNT_TO_CALLEE.getName(), 5, "testGroup", false, false, TO_SERVICE_NAME + 1); ErrorCountToCalleeChecker checker = new ErrorCountToCalleeChecker(dataCollector, rule); checker.check(); @@ -101,7 +102,7 @@ public class ErrorCountToCalleCheckerTest { public void checkTest2() { Application application = new Application(FROM_SERVICE_NAME, ServiceType.STAND_ALONE); MapStatisticsCallerDataCollector dataCollector = new MapStatisticsCallerDataCollector(DataCollectorCategory.CALLER_STAT, application, dao, System.currentTimeMillis(), 300000); - Rule rule = new Rule(FROM_SERVICE_NAME, CheckerCategory.ERROR_COUNT_TO_CALLEE.getName(), 6, "testGroup", false, false, TO_SERVICE_NAME + 1); + Rule rule = new Rule(FROM_SERVICE_NAME, SERVICE_TYPE, CheckerCategory.ERROR_COUNT_TO_CALLEE.getName(), 6, "testGroup", false, false, TO_SERVICE_NAME + 1); ErrorCountToCalleeChecker checker = new ErrorCountToCalleeChecker(dataCollector, rule); checker.check(); @@ -112,7 +113,7 @@ public class ErrorCountToCalleCheckerTest { public void checkTest3() { Application application = new Application(FROM_SERVICE_NAME, ServiceType.STAND_ALONE); MapStatisticsCallerDataCollector dataCollector = new MapStatisticsCallerDataCollector(DataCollectorCategory.CALLER_STAT, application, dao, System.currentTimeMillis(), 300000); - Rule rule = new Rule(FROM_SERVICE_NAME, CheckerCategory.ERROR_COUNT_TO_CALLEE.getName(), 5, "testGroup", false, false, TO_SERVICE_NAME + 2); + Rule rule = new Rule(FROM_SERVICE_NAME, SERVICE_TYPE, CheckerCategory.ERROR_COUNT_TO_CALLEE.getName(), 5, "testGroup", false, false, TO_SERVICE_NAME + 2); ErrorCountToCalleeChecker checker = new ErrorCountToCalleeChecker(dataCollector, rule); checker.check(); diff --git a/web/src/test/java/com/navercorp/pinpoint/web/alarm/checker/ErrorRateCheckerTest.java b/web/src/test/java/com/navercorp/pinpoint/web/alarm/checker/ErrorRateCheckerTest.java index cefa134c8..2aae01f8b 100644 --- a/web/src/test/java/com/navercorp/pinpoint/web/alarm/checker/ErrorRateCheckerTest.java +++ b/web/src/test/java/com/navercorp/pinpoint/web/alarm/checker/ErrorRateCheckerTest.java @@ -1,103 +1,104 @@ -/* - * Copyright 2014 NAVER Corp. - * - * Licensed 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 com.navercorp.pinpoint.web.alarm.checker; - -import static org.junit.Assert.*; - -import java.util.LinkedList; -import java.util.List; - -import org.junit.BeforeClass; -import org.junit.Test; - -import com.navercorp.pinpoint.common.trace.ServiceType; -import com.navercorp.pinpoint.web.alarm.CheckerCategory; -import com.navercorp.pinpoint.web.alarm.DataCollectorFactory.DataCollectorCategory; -import com.navercorp.pinpoint.web.alarm.checker.ErrorRateChecker; -import com.navercorp.pinpoint.web.alarm.collector.ResponseTimeDataCollector; -import com.navercorp.pinpoint.web.alarm.vo.Rule; -import com.navercorp.pinpoint.web.applicationmap.histogram.TimeHistogram; -import com.navercorp.pinpoint.web.dao.MapResponseDao; -import com.navercorp.pinpoint.web.vo.Application; -import com.navercorp.pinpoint.web.vo.Range; -import com.navercorp.pinpoint.web.vo.ResponseTime; - -public class ErrorRateCheckerTest { - - private static final String SERVICE_NAME = "local_service"; - - private static MapResponseDao mockMapResponseDAO; - - @BeforeClass - public static void before() { - mockMapResponseDAO = new MapResponseDao() { - - @Override - public List selectResponseTime(Application application, Range range) { - List list = new LinkedList(); - long timeStamp = 1409814914298L; - ResponseTime responseTime = new ResponseTime(SERVICE_NAME, ServiceType.STAND_ALONE, timeStamp); - list.add(responseTime); - TimeHistogram histogram = null; - - for (int i=0 ; i < 5; i++) { - for (int j=0 ; j < 5; j++) { - histogram = new TimeHistogram(ServiceType.STAND_ALONE, timeStamp); - histogram.addCallCountByElapsedTime(1000); - histogram.addCallCountByElapsedTime(3000); - histogram.addCallCountByElapsedTime(-1); - histogram.addCallCountByElapsedTime(-1); - histogram.addCallCountByElapsedTime(-1); - responseTime.addResponseTime("agent_" + i + "_" + j, histogram); - } - - timeStamp += 1; - } - - return list; - } - }; - } - - /* - * alert conditions not satisfied - */ - @Test - public void checkTest1() { - Application application = new Application(SERVICE_NAME, ServiceType.STAND_ALONE); - ResponseTimeDataCollector collector = new ResponseTimeDataCollector(DataCollectorCategory.RESPONSE_TIME, application, mockMapResponseDAO, System.currentTimeMillis(), 300000); - Rule rule = new Rule(SERVICE_NAME, CheckerCategory.ERROR_RATE.getName(), 60, "testGroup", false, false, ""); - ErrorRateChecker filter = new ErrorRateChecker(collector, rule); - - filter.check(); - assertTrue(filter.isDetected()); - } - - /* - * alert conditions not satisfied - */ - @Test - public void checkTest2() { - Application application = new Application(SERVICE_NAME, ServiceType.STAND_ALONE); - ResponseTimeDataCollector collector = new ResponseTimeDataCollector(DataCollectorCategory.RESPONSE_TIME, application, mockMapResponseDAO, System.currentTimeMillis(), 300000); - Rule rule = new Rule(SERVICE_NAME, CheckerCategory.ERROR_RATE.getName(), 61, "testGroup", false, false, ""); - ErrorRateChecker filter = new ErrorRateChecker(collector, rule); - - filter.check(); - assertFalse(filter.isDetected()); - } -} +/* + * Copyright 2014 NAVER Corp. + * + * Licensed 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 com.navercorp.pinpoint.web.alarm.checker; + +import static org.junit.Assert.*; + +import java.util.LinkedList; +import java.util.List; + +import org.junit.BeforeClass; +import org.junit.Test; + +import com.navercorp.pinpoint.common.trace.ServiceType; +import com.navercorp.pinpoint.web.alarm.CheckerCategory; +import com.navercorp.pinpoint.web.alarm.DataCollectorFactory.DataCollectorCategory; +import com.navercorp.pinpoint.web.alarm.checker.ErrorRateChecker; +import com.navercorp.pinpoint.web.alarm.collector.ResponseTimeDataCollector; +import com.navercorp.pinpoint.web.alarm.vo.Rule; +import com.navercorp.pinpoint.web.applicationmap.histogram.TimeHistogram; +import com.navercorp.pinpoint.web.dao.MapResponseDao; +import com.navercorp.pinpoint.web.vo.Application; +import com.navercorp.pinpoint.web.vo.Range; +import com.navercorp.pinpoint.web.vo.ResponseTime; + +public class ErrorRateCheckerTest { + + private static final String SERVICE_NAME = "local_service"; + private static final String SERVICE_TYPE = "tomcat"; + + private static MapResponseDao mockMapResponseDAO; + + @BeforeClass + public static void before() { + mockMapResponseDAO = new MapResponseDao() { + + @Override + public List selectResponseTime(Application application, Range range) { + List list = new LinkedList(); + long timeStamp = 1409814914298L; + ResponseTime responseTime = new ResponseTime(SERVICE_NAME, ServiceType.STAND_ALONE, timeStamp); + list.add(responseTime); + TimeHistogram histogram = null; + + for (int i=0 ; i < 5; i++) { + for (int j=0 ; j < 5; j++) { + histogram = new TimeHistogram(ServiceType.STAND_ALONE, timeStamp); + histogram.addCallCountByElapsedTime(1000); + histogram.addCallCountByElapsedTime(3000); + histogram.addCallCountByElapsedTime(-1); + histogram.addCallCountByElapsedTime(-1); + histogram.addCallCountByElapsedTime(-1); + responseTime.addResponseTime("agent_" + i + "_" + j, histogram); + } + + timeStamp += 1; + } + + return list; + } + }; + } + + /* + * alert conditions not satisfied + */ + @Test + public void checkTest1() { + Application application = new Application(SERVICE_NAME, ServiceType.STAND_ALONE); + ResponseTimeDataCollector collector = new ResponseTimeDataCollector(DataCollectorCategory.RESPONSE_TIME, application, mockMapResponseDAO, System.currentTimeMillis(), 300000); + Rule rule = new Rule(SERVICE_NAME, SERVICE_TYPE, CheckerCategory.ERROR_RATE.getName(), 60, "testGroup", false, false, ""); + ErrorRateChecker filter = new ErrorRateChecker(collector, rule); + + filter.check(); + assertTrue(filter.isDetected()); + } + + /* + * alert conditions not satisfied + */ + @Test + public void checkTest2() { + Application application = new Application(SERVICE_NAME, ServiceType.STAND_ALONE); + ResponseTimeDataCollector collector = new ResponseTimeDataCollector(DataCollectorCategory.RESPONSE_TIME, application, mockMapResponseDAO, System.currentTimeMillis(), 300000); + Rule rule = new Rule(SERVICE_NAME, SERVICE_TYPE, CheckerCategory.ERROR_RATE.getName(), 61, "testGroup", false, false, ""); + ErrorRateChecker filter = new ErrorRateChecker(collector, rule); + + filter.check(); + assertFalse(filter.isDetected()); + } +} diff --git a/web/src/test/java/com/navercorp/pinpoint/web/alarm/checker/ErrorRateToCalleCheckerTest.java b/web/src/test/java/com/navercorp/pinpoint/web/alarm/checker/ErrorRateToCalleCheckerTest.java index 1d0bf1386..0b8210525 100644 --- a/web/src/test/java/com/navercorp/pinpoint/web/alarm/checker/ErrorRateToCalleCheckerTest.java +++ b/web/src/test/java/com/navercorp/pinpoint/web/alarm/checker/ErrorRateToCalleCheckerTest.java @@ -43,6 +43,8 @@ public class ErrorRateToCalleCheckerTest { private static final String FROM_SERVICE_NAME = "from_local_service"; private static final String TO_SERVICE_NAME = "to_local_service"; + private static final String SERVICE_TYPE = "tomcat"; + public static MapStatisticsCallerDao dao; @BeforeClass @@ -90,7 +92,7 @@ public class ErrorRateToCalleCheckerTest { public void checkTest() { Application application = new Application(FROM_SERVICE_NAME, ServiceType.STAND_ALONE); MapStatisticsCallerDataCollector dataCollector = new MapStatisticsCallerDataCollector(DataCollectorCategory.CALLER_STAT, application, dao, System.currentTimeMillis(), 300000); - Rule rule = new Rule(FROM_SERVICE_NAME, CheckerCategory.ERROR_RATE_TO_CALLEE.getName(), 50, "testGroup", false, false, TO_SERVICE_NAME + 1); + Rule rule = new Rule(FROM_SERVICE_NAME, SERVICE_TYPE, CheckerCategory.ERROR_RATE_TO_CALLEE.getName(), 50, "testGroup", false, false, TO_SERVICE_NAME + 1); ErrorRateToCalleeChecker checker = new ErrorRateToCalleeChecker(dataCollector, rule); checker.check(); @@ -101,7 +103,7 @@ public class ErrorRateToCalleCheckerTest { public void checkTest2() { Application application = new Application(FROM_SERVICE_NAME, ServiceType.STAND_ALONE); MapStatisticsCallerDataCollector dataCollector = new MapStatisticsCallerDataCollector(DataCollectorCategory.CALLER_STAT, application, dao, System.currentTimeMillis(), 300000); - Rule rule = new Rule(FROM_SERVICE_NAME, CheckerCategory.ERROR_RATE_TO_CALLEE.getName(), 51, "testGroup", false, false, TO_SERVICE_NAME + 1); + Rule rule = new Rule(FROM_SERVICE_NAME, SERVICE_TYPE, CheckerCategory.ERROR_RATE_TO_CALLEE.getName(), 51, "testGroup", false, false, TO_SERVICE_NAME + 1); ErrorRateToCalleeChecker checker = new ErrorRateToCalleeChecker(dataCollector, rule); checker.check(); @@ -112,7 +114,7 @@ public class ErrorRateToCalleCheckerTest { public void checkTest3() { Application application = new Application(FROM_SERVICE_NAME, ServiceType.STAND_ALONE); MapStatisticsCallerDataCollector dataCollector = new MapStatisticsCallerDataCollector(DataCollectorCategory.CALLER_STAT, application, dao, System.currentTimeMillis(), 300000); - Rule rule = new Rule(FROM_SERVICE_NAME, CheckerCategory.ERROR_RATE_TO_CALLEE.getName(), 50, "testGroup", false, false, TO_SERVICE_NAME + 2); + Rule rule = new Rule(FROM_SERVICE_NAME, SERVICE_TYPE, CheckerCategory.ERROR_RATE_TO_CALLEE.getName(), 50, "testGroup", false, false, TO_SERVICE_NAME + 2); ErrorRateToCalleeChecker checker = new ErrorRateToCalleeChecker(dataCollector, rule); checker.check(); diff --git a/web/src/test/java/com/navercorp/pinpoint/web/alarm/checker/GcCountCheckerTest.java b/web/src/test/java/com/navercorp/pinpoint/web/alarm/checker/GcCountCheckerTest.java index 0da9da425..42203bfc8 100644 --- a/web/src/test/java/com/navercorp/pinpoint/web/alarm/checker/GcCountCheckerTest.java +++ b/web/src/test/java/com/navercorp/pinpoint/web/alarm/checker/GcCountCheckerTest.java @@ -1,132 +1,133 @@ -/* - * Copyright 2014 NAVER Corp. - * - * Licensed 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 com.navercorp.pinpoint.web.alarm.checker; - -import static org.junit.Assert.*; - -import java.util.LinkedList; -import java.util.List; - -import org.junit.BeforeClass; -import org.junit.Test; - -import com.navercorp.pinpoint.common.bo.AgentStatCpuLoadBo; -import com.navercorp.pinpoint.common.bo.AgentStatMemoryGcBo; -import com.navercorp.pinpoint.common.trace.ServiceType; -import com.navercorp.pinpoint.web.alarm.CheckerCategory; -import com.navercorp.pinpoint.web.alarm.DataCollectorFactory; -import com.navercorp.pinpoint.web.alarm.DataCollectorFactory.DataCollectorCategory; -import com.navercorp.pinpoint.web.alarm.checker.AgentChecker; -import com.navercorp.pinpoint.web.alarm.checker.GcCountChecker; -import com.navercorp.pinpoint.web.alarm.collector.AgentStatDataCollector; -import com.navercorp.pinpoint.web.alarm.vo.Rule; -import com.navercorp.pinpoint.web.dao.AgentStatDao; -import com.navercorp.pinpoint.web.dao.ApplicationIndexDao; -import com.navercorp.pinpoint.web.vo.AgentStat; -import com.navercorp.pinpoint.web.vo.Application; -import com.navercorp.pinpoint.web.vo.Range; - -public class GcCountCheckerTest { - - - private static final String SERVICE_NAME = "local_service"; - - private static ApplicationIndexDao applicationIndexDao; - - private static AgentStatDao agentStatDao; - - @BeforeClass - public static void before() { - agentStatDao = new AgentStatDao() { - - @Override - public List scanAgentStatList(String agentId, Range range) { - List AgentStatList = new LinkedList(); - - for (int i = 36; i > 0; i--) { - AgentStatMemoryGcBo.Builder memoryBuilder = new AgentStatMemoryGcBo.Builder("AGETNT_NAME", 0L, 1L); - memoryBuilder.jvmGcOldCount(i); - AgentStatMemoryGcBo memoryBo = memoryBuilder.build(); - AgentStatCpuLoadBo.Builder cpuBuilder = new AgentStatCpuLoadBo.Builder("AGETNT_NAME", 0L, 1L); - AgentStatCpuLoadBo cpuLoadBo = cpuBuilder.build(); - - AgentStat stat = new AgentStat(); - stat.setMemoryGc(memoryBo); - stat.setCpuLoad(cpuLoadBo); - - AgentStatList.add(stat); - } - - return AgentStatList; - } - }; - - applicationIndexDao = new ApplicationIndexDao() { - - @Override - public List selectAllApplicationNames() { - throw new UnsupportedOperationException(); - } - - @Override - public List selectAgentIds(String applicationName) { - if (SERVICE_NAME.equals(applicationName)) { - List agentIds = new LinkedList(); - agentIds.add("local_tomcat"); - return agentIds; - } - - throw new IllegalArgumentException(); - } - - @Override - public void deleteApplicationName(String applicationName) { - throw new UnsupportedOperationException(); - } - - @Override - public void deleteAgentId(String applicationName, String agentId) { - throw new UnsupportedOperationException(); - } - - }; - } - - - @Test - public void checkTest1() { - Rule rule = new Rule(SERVICE_NAME, CheckerCategory.GC_COUNT.getName(), 35, "testGroup", false, false, ""); - Application application = new Application(SERVICE_NAME, ServiceType.STAND_ALONE); - AgentStatDataCollector collector = new AgentStatDataCollector(DataCollectorCategory.AGENT_STAT, application, agentStatDao, applicationIndexDao, System.currentTimeMillis(), DataCollectorFactory.SLOT_INTERVAL_FIVE_MIN); - AgentChecker checker = new GcCountChecker(collector, rule); - - checker.check(); - assertTrue(checker.isDetected()); - } - - @Test - public void checkTest2() { - Rule rule = new Rule(SERVICE_NAME, CheckerCategory.GC_COUNT.getName(), 36, "testGroup", false, false, ""); - Application application = new Application(SERVICE_NAME, ServiceType.STAND_ALONE); - AgentStatDataCollector collector = new AgentStatDataCollector(DataCollectorCategory.AGENT_STAT, application, agentStatDao, applicationIndexDao, System.currentTimeMillis(), DataCollectorFactory.SLOT_INTERVAL_FIVE_MIN); - AgentChecker checker = new GcCountChecker(collector, rule); - - checker.check(); - assertFalse(checker.isDetected()); - } - -} +/* + * Copyright 2014 NAVER Corp. + * + * Licensed 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 com.navercorp.pinpoint.web.alarm.checker; + +import static org.junit.Assert.*; + +import java.util.LinkedList; +import java.util.List; + +import org.junit.BeforeClass; +import org.junit.Test; + +import com.navercorp.pinpoint.common.bo.AgentStatCpuLoadBo; +import com.navercorp.pinpoint.common.bo.AgentStatMemoryGcBo; +import com.navercorp.pinpoint.common.trace.ServiceType; +import com.navercorp.pinpoint.web.alarm.CheckerCategory; +import com.navercorp.pinpoint.web.alarm.DataCollectorFactory; +import com.navercorp.pinpoint.web.alarm.DataCollectorFactory.DataCollectorCategory; +import com.navercorp.pinpoint.web.alarm.checker.AgentChecker; +import com.navercorp.pinpoint.web.alarm.checker.GcCountChecker; +import com.navercorp.pinpoint.web.alarm.collector.AgentStatDataCollector; +import com.navercorp.pinpoint.web.alarm.vo.Rule; +import com.navercorp.pinpoint.web.dao.AgentStatDao; +import com.navercorp.pinpoint.web.dao.ApplicationIndexDao; +import com.navercorp.pinpoint.web.vo.AgentStat; +import com.navercorp.pinpoint.web.vo.Application; +import com.navercorp.pinpoint.web.vo.Range; + +public class GcCountCheckerTest { + + + private static final String SERVICE_NAME = "local_service"; + private static final String SERVICE_TYPE = "tomcat"; + + private static ApplicationIndexDao applicationIndexDao; + + private static AgentStatDao agentStatDao; + + @BeforeClass + public static void before() { + agentStatDao = new AgentStatDao() { + + @Override + public List scanAgentStatList(String agentId, Range range) { + List AgentStatList = new LinkedList(); + + for (int i = 36; i > 0; i--) { + AgentStatMemoryGcBo.Builder memoryBuilder = new AgentStatMemoryGcBo.Builder("AGETNT_NAME", 0L, 1L); + memoryBuilder.jvmGcOldCount(i); + AgentStatMemoryGcBo memoryBo = memoryBuilder.build(); + AgentStatCpuLoadBo.Builder cpuBuilder = new AgentStatCpuLoadBo.Builder("AGETNT_NAME", 0L, 1L); + AgentStatCpuLoadBo cpuLoadBo = cpuBuilder.build(); + + AgentStat stat = new AgentStat(); + stat.setMemoryGc(memoryBo); + stat.setCpuLoad(cpuLoadBo); + + AgentStatList.add(stat); + } + + return AgentStatList; + } + }; + + applicationIndexDao = new ApplicationIndexDao() { + + @Override + public List selectAllApplicationNames() { + throw new UnsupportedOperationException(); + } + + @Override + public List selectAgentIds(String applicationName) { + if (SERVICE_NAME.equals(applicationName)) { + List agentIds = new LinkedList(); + agentIds.add("local_tomcat"); + return agentIds; + } + + throw new IllegalArgumentException(); + } + + @Override + public void deleteApplicationName(String applicationName) { + throw new UnsupportedOperationException(); + } + + @Override + public void deleteAgentId(String applicationName, String agentId) { + throw new UnsupportedOperationException(); + } + + }; + } + + + @Test + public void checkTest1() { + Rule rule = new Rule(SERVICE_NAME, SERVICE_TYPE, CheckerCategory.GC_COUNT.getName(), 35, "testGroup", false, false, ""); + Application application = new Application(SERVICE_NAME, ServiceType.STAND_ALONE); + AgentStatDataCollector collector = new AgentStatDataCollector(DataCollectorCategory.AGENT_STAT, application, agentStatDao, applicationIndexDao, System.currentTimeMillis(), DataCollectorFactory.SLOT_INTERVAL_FIVE_MIN); + AgentChecker checker = new GcCountChecker(collector, rule); + + checker.check(); + assertTrue(checker.isDetected()); + } + + @Test + public void checkTest2() { + Rule rule = new Rule(SERVICE_NAME, SERVICE_TYPE, CheckerCategory.GC_COUNT.getName(), 36, "testGroup", false, false, ""); + Application application = new Application(SERVICE_NAME, ServiceType.STAND_ALONE); + AgentStatDataCollector collector = new AgentStatDataCollector(DataCollectorCategory.AGENT_STAT, application, agentStatDao, applicationIndexDao, System.currentTimeMillis(), DataCollectorFactory.SLOT_INTERVAL_FIVE_MIN); + AgentChecker checker = new GcCountChecker(collector, rule); + + checker.check(); + assertFalse(checker.isDetected()); + } + +} diff --git a/web/src/test/java/com/navercorp/pinpoint/web/alarm/checker/HeapUsageRateCheckerTest.java b/web/src/test/java/com/navercorp/pinpoint/web/alarm/checker/HeapUsageRateCheckerTest.java index 9417a954d..e3a0826aa 100644 --- a/web/src/test/java/com/navercorp/pinpoint/web/alarm/checker/HeapUsageRateCheckerTest.java +++ b/web/src/test/java/com/navercorp/pinpoint/web/alarm/checker/HeapUsageRateCheckerTest.java @@ -1,151 +1,152 @@ -/* - * Copyright 2014 NAVER Corp. - * - * Licensed 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 com.navercorp.pinpoint.web.alarm.checker; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.util.LinkedList; -import java.util.List; - -import org.junit.BeforeClass; -import org.junit.Test; - -import com.navercorp.pinpoint.common.bo.AgentStatCpuLoadBo; -import com.navercorp.pinpoint.common.bo.AgentStatMemoryGcBo; -import com.navercorp.pinpoint.common.trace.ServiceType; -import com.navercorp.pinpoint.web.alarm.CheckerCategory; -import com.navercorp.pinpoint.web.alarm.DataCollectorFactory; -import com.navercorp.pinpoint.web.alarm.DataCollectorFactory.DataCollectorCategory; -import com.navercorp.pinpoint.web.alarm.checker.AgentChecker; -import com.navercorp.pinpoint.web.alarm.checker.HeapUsageRateChecker; -import com.navercorp.pinpoint.web.alarm.collector.AgentStatDataCollector; -import com.navercorp.pinpoint.web.alarm.vo.Rule; -import com.navercorp.pinpoint.web.dao.AgentStatDao; -import com.navercorp.pinpoint.web.dao.ApplicationIndexDao; -import com.navercorp.pinpoint.web.vo.AgentStat; -import com.navercorp.pinpoint.web.vo.Application; -import com.navercorp.pinpoint.web.vo.Range; - -public class HeapUsageRateCheckerTest { - - private static final String SERVICE_NAME = "local_service"; - - private static ApplicationIndexDao applicationIndexDao; - - private static AgentStatDao agentStatDao; - - @BeforeClass - public static void before() { - agentStatDao = new AgentStatDao() { - - @Override - public List scanAgentStatList(String agentId, Range range) { - List AgentStatList = new LinkedList(); - - for (int i = 0; i < 36; i++) { - AgentStatMemoryGcBo.Builder memoryBuilder = new AgentStatMemoryGcBo.Builder("AGETNT_NAME", 0L, 1L); - memoryBuilder.jvmMemoryHeapUsed(70L); - memoryBuilder.jvmMemoryHeapMax(100L); - AgentStatMemoryGcBo memoryBo = memoryBuilder.build(); - AgentStatCpuLoadBo.Builder cpuBuilder = new AgentStatCpuLoadBo.Builder("AGETNT_NAME", 0L, 1L); - AgentStatCpuLoadBo cpuLoadBo = cpuBuilder.build(); - - AgentStat stat = new AgentStat(); - stat.setMemoryGc(memoryBo); - stat.setCpuLoad(cpuLoadBo); - - AgentStatList.add(stat); - } - - return AgentStatList; - } - }; - - applicationIndexDao = new ApplicationIndexDao() { - - @Override - public List selectAllApplicationNames() { - throw new UnsupportedOperationException(); - } - - @Override - public List selectAgentIds(String applicationName) { - if (SERVICE_NAME.equals(applicationName)) { - List agentIds = new LinkedList(); - agentIds.add("local_tomcat"); - return agentIds; - } - - throw new IllegalArgumentException(); - } - - @Override - public void deleteApplicationName(String applicationName) { - throw new UnsupportedOperationException(); - } - - @Override - public void deleteAgentId(String applicationName, String agentId) { - throw new UnsupportedOperationException(); - } - - }; - } - - - @Test - public void checkTest1() { - Rule rule = new Rule(SERVICE_NAME, CheckerCategory.HEAP_USAGE_RATE.getName(), 70, "testGroup", false, false, ""); - Application application = new Application(SERVICE_NAME, ServiceType.STAND_ALONE); - AgentStatDataCollector collector = new AgentStatDataCollector(DataCollectorCategory.AGENT_STAT, application, agentStatDao, applicationIndexDao, System.currentTimeMillis(), DataCollectorFactory.SLOT_INTERVAL_FIVE_MIN); - AgentChecker checker = new HeapUsageRateChecker(collector, rule); - - checker.check(); - assertTrue(checker.isDetected()); - } - - @Test - public void checkTest2() { - Rule rule = new Rule(SERVICE_NAME, CheckerCategory.HEAP_USAGE_RATE.getName(), 71, "testGroup", false, false, ""); - Application application = new Application(SERVICE_NAME, ServiceType.STAND_ALONE); - AgentStatDataCollector collector = new AgentStatDataCollector(DataCollectorCategory.AGENT_STAT, application, agentStatDao, applicationIndexDao, System.currentTimeMillis(), DataCollectorFactory.SLOT_INTERVAL_FIVE_MIN); - AgentChecker checker = new HeapUsageRateChecker(collector, rule); - - checker.check(); - assertFalse(checker.isDetected()); - } - - -// @Autowired -// private HbaseAgentStatDao hbaseAgentStatDao ; - -// @Autowired -// private HbaseApplicationIndexDao applicationIndexDao; - -// @Test -// public void checkTest1() { -// Rule rule = new Rule(SERVICE_NAME, CheckerCategory.HEAP_USAGE_RATE.getName(), 60, "testGroup", false, false); -// Application application = new Application(SERVICE_NAME, ServiceType.STAND_ALONE); -// AgentStatDataCollector collector = new AgentStatDataCollector(DataCollectorCategory.AGENT_STAT, application, hbaseAgentStatDao, applicationIndexDao, System.currentTimeMillis(), (long)300000); -// AgentChecker checker = new HeapUsageRateChecker(collector, rule); -// -// checker.check(); -// assertTrue(checker.isDetected()); -// } - -} +/* + * Copyright 2014 NAVER Corp. + * + * Licensed 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 com.navercorp.pinpoint.web.alarm.checker; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.util.LinkedList; +import java.util.List; + +import org.junit.BeforeClass; +import org.junit.Test; + +import com.navercorp.pinpoint.common.bo.AgentStatCpuLoadBo; +import com.navercorp.pinpoint.common.bo.AgentStatMemoryGcBo; +import com.navercorp.pinpoint.common.trace.ServiceType; +import com.navercorp.pinpoint.web.alarm.CheckerCategory; +import com.navercorp.pinpoint.web.alarm.DataCollectorFactory; +import com.navercorp.pinpoint.web.alarm.DataCollectorFactory.DataCollectorCategory; +import com.navercorp.pinpoint.web.alarm.checker.AgentChecker; +import com.navercorp.pinpoint.web.alarm.checker.HeapUsageRateChecker; +import com.navercorp.pinpoint.web.alarm.collector.AgentStatDataCollector; +import com.navercorp.pinpoint.web.alarm.vo.Rule; +import com.navercorp.pinpoint.web.dao.AgentStatDao; +import com.navercorp.pinpoint.web.dao.ApplicationIndexDao; +import com.navercorp.pinpoint.web.vo.AgentStat; +import com.navercorp.pinpoint.web.vo.Application; +import com.navercorp.pinpoint.web.vo.Range; + +public class HeapUsageRateCheckerTest { + + private static final String SERVICE_NAME = "local_service"; + private static final String SERVICE_TYPE = "tomcat"; + + private static ApplicationIndexDao applicationIndexDao; + + private static AgentStatDao agentStatDao; + + @BeforeClass + public static void before() { + agentStatDao = new AgentStatDao() { + + @Override + public List scanAgentStatList(String agentId, Range range) { + List AgentStatList = new LinkedList(); + + for (int i = 0; i < 36; i++) { + AgentStatMemoryGcBo.Builder memoryBuilder = new AgentStatMemoryGcBo.Builder("AGETNT_NAME", 0L, 1L); + memoryBuilder.jvmMemoryHeapUsed(70L); + memoryBuilder.jvmMemoryHeapMax(100L); + AgentStatMemoryGcBo memoryBo = memoryBuilder.build(); + AgentStatCpuLoadBo.Builder cpuBuilder = new AgentStatCpuLoadBo.Builder("AGETNT_NAME", 0L, 1L); + AgentStatCpuLoadBo cpuLoadBo = cpuBuilder.build(); + + AgentStat stat = new AgentStat(); + stat.setMemoryGc(memoryBo); + stat.setCpuLoad(cpuLoadBo); + + AgentStatList.add(stat); + } + + return AgentStatList; + } + }; + + applicationIndexDao = new ApplicationIndexDao() { + + @Override + public List selectAllApplicationNames() { + throw new UnsupportedOperationException(); + } + + @Override + public List selectAgentIds(String applicationName) { + if (SERVICE_NAME.equals(applicationName)) { + List agentIds = new LinkedList(); + agentIds.add("local_tomcat"); + return agentIds; + } + + throw new IllegalArgumentException(); + } + + @Override + public void deleteApplicationName(String applicationName) { + throw new UnsupportedOperationException(); + } + + @Override + public void deleteAgentId(String applicationName, String agentId) { + throw new UnsupportedOperationException(); + } + + }; + } + + + @Test + public void checkTest1() { + Rule rule = new Rule(SERVICE_NAME, SERVICE_TYPE, CheckerCategory.HEAP_USAGE_RATE.getName(), 70, "testGroup", false, false, ""); + Application application = new Application(SERVICE_NAME, ServiceType.STAND_ALONE); + AgentStatDataCollector collector = new AgentStatDataCollector(DataCollectorCategory.AGENT_STAT, application, agentStatDao, applicationIndexDao, System.currentTimeMillis(), DataCollectorFactory.SLOT_INTERVAL_FIVE_MIN); + AgentChecker checker = new HeapUsageRateChecker(collector, rule); + + checker.check(); + assertTrue(checker.isDetected()); + } + + @Test + public void checkTest2() { + Rule rule = new Rule(SERVICE_NAME, SERVICE_TYPE, CheckerCategory.HEAP_USAGE_RATE.getName(), 71, "testGroup", false, false, ""); + Application application = new Application(SERVICE_NAME, ServiceType.STAND_ALONE); + AgentStatDataCollector collector = new AgentStatDataCollector(DataCollectorCategory.AGENT_STAT, application, agentStatDao, applicationIndexDao, System.currentTimeMillis(), DataCollectorFactory.SLOT_INTERVAL_FIVE_MIN); + AgentChecker checker = new HeapUsageRateChecker(collector, rule); + + checker.check(); + assertFalse(checker.isDetected()); + } + + +// @Autowired +// private HbaseAgentStatDao hbaseAgentStatDao ; + +// @Autowired +// private HbaseApplicationIndexDao applicationIndexDao; + +// @Test +// public void checkTest1() { +// Rule rule = new Rule(SERVICE_NAME, CheckerCategory.HEAP_USAGE_RATE.getName(), 60, "testGroup", false, false); +// Application application = new Application(SERVICE_NAME, ServiceType.STAND_ALONE); +// AgentStatDataCollector collector = new AgentStatDataCollector(DataCollectorCategory.AGENT_STAT, application, hbaseAgentStatDao, applicationIndexDao, System.currentTimeMillis(), (long)300000); +// AgentChecker checker = new HeapUsageRateChecker(collector, rule); +// +// checker.check(); +// assertTrue(checker.isDetected()); +// } + +} diff --git a/web/src/test/java/com/navercorp/pinpoint/web/alarm/checker/JvmCpuUsageRateCheckerTest.java b/web/src/test/java/com/navercorp/pinpoint/web/alarm/checker/JvmCpuUsageRateCheckerTest.java index 8a72fb188..86ce284a5 100644 --- a/web/src/test/java/com/navercorp/pinpoint/web/alarm/checker/JvmCpuUsageRateCheckerTest.java +++ b/web/src/test/java/com/navercorp/pinpoint/web/alarm/checker/JvmCpuUsageRateCheckerTest.java @@ -1,132 +1,133 @@ -/* - * Copyright 2014 NAVER Corp. - * - * Licensed 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 com.navercorp.pinpoint.web.alarm.checker; - -import static org.junit.Assert.*; - -import java.util.LinkedList; -import java.util.List; - -import org.junit.BeforeClass; -import org.junit.Test; - -import com.navercorp.pinpoint.common.bo.AgentStatCpuLoadBo; -import com.navercorp.pinpoint.common.bo.AgentStatMemoryGcBo; -import com.navercorp.pinpoint.common.trace.ServiceType; -import com.navercorp.pinpoint.web.alarm.CheckerCategory; -import com.navercorp.pinpoint.web.alarm.DataCollectorFactory; -import com.navercorp.pinpoint.web.alarm.DataCollectorFactory.DataCollectorCategory; -import com.navercorp.pinpoint.web.alarm.checker.AgentChecker; -import com.navercorp.pinpoint.web.alarm.checker.JvmCpuUsageRateChecker; -import com.navercorp.pinpoint.web.alarm.collector.AgentStatDataCollector; -import com.navercorp.pinpoint.web.alarm.vo.Rule; -import com.navercorp.pinpoint.web.dao.AgentStatDao; -import com.navercorp.pinpoint.web.dao.ApplicationIndexDao; -import com.navercorp.pinpoint.web.vo.AgentStat; -import com.navercorp.pinpoint.web.vo.Application; -import com.navercorp.pinpoint.web.vo.Range; - -public class JvmCpuUsageRateCheckerTest { - - private static final String SERVICE_NAME = "local_service"; - - private static ApplicationIndexDao applicationIndexDao; - - private static AgentStatDao agentStatDao; - - @BeforeClass - public static void before() { - agentStatDao = new AgentStatDao() { - - @Override - public List scanAgentStatList(String agentId, Range range) { - List AgentStatList = new LinkedList(); - - for (int i = 0; i < 36; i++) { - AgentStatCpuLoadBo.Builder cpuLoadBoBuilder = new AgentStatCpuLoadBo.Builder("AGETNT_NAME", 0L, 1L); - cpuLoadBoBuilder.jvmCpuLoad(0.6); - AgentStatCpuLoadBo cpuLoadBo = cpuLoadBoBuilder.build(); - - AgentStatMemoryGcBo.Builder memoryGcBobuilder = new AgentStatMemoryGcBo.Builder("AGETNT_NAME", 0L, 1L); - AgentStatMemoryGcBo memoryGcBo = memoryGcBobuilder.build(); - - AgentStat stat = new AgentStat(); - stat.setCpuLoad(cpuLoadBo); - stat.setMemoryGc(memoryGcBo); - - AgentStatList.add(stat); - } - - return AgentStatList; - } - }; - - applicationIndexDao = new ApplicationIndexDao() { - - @Override - public List selectAllApplicationNames() { - throw new UnsupportedOperationException(); - } - - @Override - public List selectAgentIds(String applicationName) { - if (SERVICE_NAME.equals(applicationName)) { - List agentIds = new LinkedList(); - agentIds.add("local_tomcat"); - return agentIds; - } - - throw new IllegalArgumentException(); - } - - @Override - public void deleteApplicationName(String applicationName) { - throw new UnsupportedOperationException(); - } - - @Override - public void deleteAgentId(String applicationName, String agentId) { - throw new UnsupportedOperationException(); - } - - }; - } - - - @Test - public void checkTest1() { - Rule rule = new Rule(SERVICE_NAME, CheckerCategory.JVM_CPU_USAGE_RATE.getName(), 60, "testGroup", false, false, ""); - Application application = new Application(SERVICE_NAME, ServiceType.STAND_ALONE); - AgentStatDataCollector collector = new AgentStatDataCollector(DataCollectorCategory.AGENT_STAT, application, agentStatDao, applicationIndexDao, System.currentTimeMillis(), DataCollectorFactory.SLOT_INTERVAL_FIVE_MIN); - AgentChecker checker = new JvmCpuUsageRateChecker(collector, rule); - - checker.check(); - assertTrue(checker.isDetected()); - } - - @Test - public void checkTest2() { - Rule rule = new Rule(SERVICE_NAME, CheckerCategory.JVM_CPU_USAGE_RATE.getName(), 61, "testGroup", false, false, ""); - Application application = new Application(SERVICE_NAME, ServiceType.STAND_ALONE); - AgentStatDataCollector collector = new AgentStatDataCollector(DataCollectorCategory.AGENT_STAT, application, agentStatDao, applicationIndexDao, System.currentTimeMillis(), DataCollectorFactory.SLOT_INTERVAL_FIVE_MIN); - AgentChecker checker = new JvmCpuUsageRateChecker(collector, rule); - - checker.check(); - assertFalse(checker.isDetected()); - } - -} +/* + * Copyright 2014 NAVER Corp. + * + * Licensed 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 com.navercorp.pinpoint.web.alarm.checker; + +import static org.junit.Assert.*; + +import java.util.LinkedList; +import java.util.List; + +import org.junit.BeforeClass; +import org.junit.Test; + +import com.navercorp.pinpoint.common.bo.AgentStatCpuLoadBo; +import com.navercorp.pinpoint.common.bo.AgentStatMemoryGcBo; +import com.navercorp.pinpoint.common.trace.ServiceType; +import com.navercorp.pinpoint.web.alarm.CheckerCategory; +import com.navercorp.pinpoint.web.alarm.DataCollectorFactory; +import com.navercorp.pinpoint.web.alarm.DataCollectorFactory.DataCollectorCategory; +import com.navercorp.pinpoint.web.alarm.checker.AgentChecker; +import com.navercorp.pinpoint.web.alarm.checker.JvmCpuUsageRateChecker; +import com.navercorp.pinpoint.web.alarm.collector.AgentStatDataCollector; +import com.navercorp.pinpoint.web.alarm.vo.Rule; +import com.navercorp.pinpoint.web.dao.AgentStatDao; +import com.navercorp.pinpoint.web.dao.ApplicationIndexDao; +import com.navercorp.pinpoint.web.vo.AgentStat; +import com.navercorp.pinpoint.web.vo.Application; +import com.navercorp.pinpoint.web.vo.Range; + +public class JvmCpuUsageRateCheckerTest { + + private static final String SERVICE_NAME = "local_service"; + private static final String SERVICE_TYPE = "tomcat"; + + private static ApplicationIndexDao applicationIndexDao; + + private static AgentStatDao agentStatDao; + + @BeforeClass + public static void before() { + agentStatDao = new AgentStatDao() { + + @Override + public List scanAgentStatList(String agentId, Range range) { + List AgentStatList = new LinkedList(); + + for (int i = 0; i < 36; i++) { + AgentStatCpuLoadBo.Builder cpuLoadBoBuilder = new AgentStatCpuLoadBo.Builder("AGETNT_NAME", 0L, 1L); + cpuLoadBoBuilder.jvmCpuLoad(0.6); + AgentStatCpuLoadBo cpuLoadBo = cpuLoadBoBuilder.build(); + + AgentStatMemoryGcBo.Builder memoryGcBobuilder = new AgentStatMemoryGcBo.Builder("AGETNT_NAME", 0L, 1L); + AgentStatMemoryGcBo memoryGcBo = memoryGcBobuilder.build(); + + AgentStat stat = new AgentStat(); + stat.setCpuLoad(cpuLoadBo); + stat.setMemoryGc(memoryGcBo); + + AgentStatList.add(stat); + } + + return AgentStatList; + } + }; + + applicationIndexDao = new ApplicationIndexDao() { + + @Override + public List selectAllApplicationNames() { + throw new UnsupportedOperationException(); + } + + @Override + public List selectAgentIds(String applicationName) { + if (SERVICE_NAME.equals(applicationName)) { + List agentIds = new LinkedList(); + agentIds.add("local_tomcat"); + return agentIds; + } + + throw new IllegalArgumentException(); + } + + @Override + public void deleteApplicationName(String applicationName) { + throw new UnsupportedOperationException(); + } + + @Override + public void deleteAgentId(String applicationName, String agentId) { + throw new UnsupportedOperationException(); + } + + }; + } + + + @Test + public void checkTest1() { + Rule rule = new Rule(SERVICE_NAME, SERVICE_TYPE, CheckerCategory.JVM_CPU_USAGE_RATE.getName(), 60, "testGroup", false, false, ""); + Application application = new Application(SERVICE_NAME, ServiceType.STAND_ALONE); + AgentStatDataCollector collector = new AgentStatDataCollector(DataCollectorCategory.AGENT_STAT, application, agentStatDao, applicationIndexDao, System.currentTimeMillis(), DataCollectorFactory.SLOT_INTERVAL_FIVE_MIN); + AgentChecker checker = new JvmCpuUsageRateChecker(collector, rule); + + checker.check(); + assertTrue(checker.isDetected()); + } + + @Test + public void checkTest2() { + Rule rule = new Rule(SERVICE_NAME, SERVICE_TYPE, CheckerCategory.JVM_CPU_USAGE_RATE.getName(), 61, "testGroup", false, false, ""); + Application application = new Application(SERVICE_NAME, ServiceType.STAND_ALONE); + AgentStatDataCollector collector = new AgentStatDataCollector(DataCollectorCategory.AGENT_STAT, application, agentStatDao, applicationIndexDao, System.currentTimeMillis(), DataCollectorFactory.SLOT_INTERVAL_FIVE_MIN); + AgentChecker checker = new JvmCpuUsageRateChecker(collector, rule); + + checker.check(); + assertFalse(checker.isDetected()); + } + +} diff --git a/web/src/test/java/com/navercorp/pinpoint/web/alarm/checker/ResponseCountCheckerTest.java b/web/src/test/java/com/navercorp/pinpoint/web/alarm/checker/ResponseCountCheckerTest.java index cbbfe59e1..164fc44fe 100644 --- a/web/src/test/java/com/navercorp/pinpoint/web/alarm/checker/ResponseCountCheckerTest.java +++ b/web/src/test/java/com/navercorp/pinpoint/web/alarm/checker/ResponseCountCheckerTest.java @@ -1,105 +1,106 @@ -/* - * Copyright 2014 NAVER Corp. - * - * Licensed 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 com.navercorp.pinpoint.web.alarm.checker; - -import static org.junit.Assert.*; - -import java.util.LinkedList; -import java.util.List; - -import org.junit.BeforeClass; -import org.junit.Test; - -import com.navercorp.pinpoint.common.trace.ServiceType; -import com.navercorp.pinpoint.web.alarm.CheckerCategory; -import com.navercorp.pinpoint.web.alarm.DataCollectorFactory; -import com.navercorp.pinpoint.web.alarm.DataCollectorFactory.DataCollectorCategory; -import com.navercorp.pinpoint.web.alarm.checker.ResponseCountChecker; -import com.navercorp.pinpoint.web.alarm.collector.ResponseTimeDataCollector; -import com.navercorp.pinpoint.web.alarm.vo.Rule; -import com.navercorp.pinpoint.web.applicationmap.histogram.TimeHistogram; -import com.navercorp.pinpoint.web.dao.MapResponseDao; -import com.navercorp.pinpoint.web.vo.Application; -import com.navercorp.pinpoint.web.vo.Range; -import com.navercorp.pinpoint.web.vo.ResponseTime; - -public class ResponseCountCheckerTest { - - - private static final String SERVICE_NAME = "local_service"; - - private static MapResponseDao mockMapResponseDAO; - - @BeforeClass - public static void before() { - mockMapResponseDAO = new MapResponseDao() { - - @Override - public List selectResponseTime(Application application, Range range) { - List list = new LinkedList(); - long timeStamp = 1409814914298L; - ResponseTime responseTime = new ResponseTime(SERVICE_NAME, ServiceType.STAND_ALONE, timeStamp); - list.add(responseTime); - TimeHistogram histogram = null; - - for (int i=0 ; i < 5; i++) { - for (int j=0 ; j < 5; j++) { - histogram = new TimeHistogram(ServiceType.STAND_ALONE, timeStamp); - histogram.addCallCountByElapsedTime(1000); - histogram.addCallCountByElapsedTime(3000); - histogram.addCallCountByElapsedTime(-1); - histogram.addCallCountByElapsedTime(-1); - histogram.addCallCountByElapsedTime(-1); - responseTime.addResponseTime("agent_" + i + "_" + j, histogram); - } - - timeStamp += 1; - } - - return list; - } - }; - } - - /* - * alert conditions not satisfied - */ - @Test - public void checkTest1() { - Application application = new Application(SERVICE_NAME, ServiceType.STAND_ALONE); - ResponseTimeDataCollector collector = new ResponseTimeDataCollector(DataCollectorCategory.RESPONSE_TIME, application, mockMapResponseDAO, System.currentTimeMillis(), DataCollectorFactory.SLOT_INTERVAL_FIVE_MIN); - Rule rule = new Rule(SERVICE_NAME, CheckerCategory.RESPONSE_COUNT.getName(), 125, "testGroup", false, false, ""); - ResponseCountChecker filter = new ResponseCountChecker(collector, rule); - - filter.check(); - assertTrue(filter.isDetected()); - } - - /* - * alert conditions not satisfied - */ - @Test - public void checkTest2() { - Application application = new Application(SERVICE_NAME, ServiceType.STAND_ALONE); - ResponseTimeDataCollector collector = new ResponseTimeDataCollector(DataCollectorCategory.RESPONSE_TIME, application, mockMapResponseDAO, System.currentTimeMillis(), 300000); - Rule rule = new Rule(SERVICE_NAME, CheckerCategory.RESPONSE_COUNT.getName(), 126, "testGroup", false, false, ""); - ResponseCountChecker filter = new ResponseCountChecker(collector, rule); - - filter.check(); - assertFalse(filter.isDetected()); - } -} +/* + * Copyright 2014 NAVER Corp. + * + * Licensed 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 com.navercorp.pinpoint.web.alarm.checker; + +import static org.junit.Assert.*; + +import java.util.LinkedList; +import java.util.List; + +import org.junit.BeforeClass; +import org.junit.Test; + +import com.navercorp.pinpoint.common.trace.ServiceType; +import com.navercorp.pinpoint.web.alarm.CheckerCategory; +import com.navercorp.pinpoint.web.alarm.DataCollectorFactory; +import com.navercorp.pinpoint.web.alarm.DataCollectorFactory.DataCollectorCategory; +import com.navercorp.pinpoint.web.alarm.checker.ResponseCountChecker; +import com.navercorp.pinpoint.web.alarm.collector.ResponseTimeDataCollector; +import com.navercorp.pinpoint.web.alarm.vo.Rule; +import com.navercorp.pinpoint.web.applicationmap.histogram.TimeHistogram; +import com.navercorp.pinpoint.web.dao.MapResponseDao; +import com.navercorp.pinpoint.web.vo.Application; +import com.navercorp.pinpoint.web.vo.Range; +import com.navercorp.pinpoint.web.vo.ResponseTime; + +public class ResponseCountCheckerTest { + + + private static final String SERVICE_NAME = "local_service"; + private static final String SERVICE_TYPE = "tomcat"; + + private static MapResponseDao mockMapResponseDAO; + + @BeforeClass + public static void before() { + mockMapResponseDAO = new MapResponseDao() { + + @Override + public List selectResponseTime(Application application, Range range) { + List list = new LinkedList(); + long timeStamp = 1409814914298L; + ResponseTime responseTime = new ResponseTime(SERVICE_NAME, ServiceType.STAND_ALONE, timeStamp); + list.add(responseTime); + TimeHistogram histogram = null; + + for (int i=0 ; i < 5; i++) { + for (int j=0 ; j < 5; j++) { + histogram = new TimeHistogram(ServiceType.STAND_ALONE, timeStamp); + histogram.addCallCountByElapsedTime(1000); + histogram.addCallCountByElapsedTime(3000); + histogram.addCallCountByElapsedTime(-1); + histogram.addCallCountByElapsedTime(-1); + histogram.addCallCountByElapsedTime(-1); + responseTime.addResponseTime("agent_" + i + "_" + j, histogram); + } + + timeStamp += 1; + } + + return list; + } + }; + } + + /* + * alert conditions not satisfied + */ + @Test + public void checkTest1() { + Application application = new Application(SERVICE_NAME, ServiceType.STAND_ALONE); + ResponseTimeDataCollector collector = new ResponseTimeDataCollector(DataCollectorCategory.RESPONSE_TIME, application, mockMapResponseDAO, System.currentTimeMillis(), DataCollectorFactory.SLOT_INTERVAL_FIVE_MIN); + Rule rule = new Rule(SERVICE_NAME, SERVICE_TYPE, CheckerCategory.RESPONSE_COUNT.getName(), 125, "testGroup", false, false, ""); + ResponseCountChecker filter = new ResponseCountChecker(collector, rule); + + filter.check(); + assertTrue(filter.isDetected()); + } + + /* + * alert conditions not satisfied + */ + @Test + public void checkTest2() { + Application application = new Application(SERVICE_NAME, ServiceType.STAND_ALONE); + ResponseTimeDataCollector collector = new ResponseTimeDataCollector(DataCollectorCategory.RESPONSE_TIME, application, mockMapResponseDAO, System.currentTimeMillis(), 300000); + Rule rule = new Rule(SERVICE_NAME, SERVICE_TYPE, CheckerCategory.RESPONSE_COUNT.getName(), 126, "testGroup", false, false, ""); + ResponseCountChecker filter = new ResponseCountChecker(collector, rule); + + filter.check(); + assertFalse(filter.isDetected()); + } +} diff --git a/web/src/test/java/com/navercorp/pinpoint/web/alarm/checker/SlowCountCheckerTest.java b/web/src/test/java/com/navercorp/pinpoint/web/alarm/checker/SlowCountCheckerTest.java index 3d71f0670..85814080d 100644 --- a/web/src/test/java/com/navercorp/pinpoint/web/alarm/checker/SlowCountCheckerTest.java +++ b/web/src/test/java/com/navercorp/pinpoint/web/alarm/checker/SlowCountCheckerTest.java @@ -1,127 +1,128 @@ -/* - * Copyright 2014 NAVER Corp. - * - * Licensed 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 com.navercorp.pinpoint.web.alarm.checker; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.util.LinkedList; -import java.util.List; - -import org.junit.BeforeClass; -import org.junit.Test; - -import com.navercorp.pinpoint.common.trace.ServiceType; -import com.navercorp.pinpoint.web.alarm.CheckerCategory; -import com.navercorp.pinpoint.web.alarm.DataCollectorFactory.DataCollectorCategory; -import com.navercorp.pinpoint.web.alarm.checker.SlowCountChecker; -import com.navercorp.pinpoint.web.alarm.collector.ResponseTimeDataCollector; -import com.navercorp.pinpoint.web.alarm.vo.Rule; -import com.navercorp.pinpoint.web.applicationmap.histogram.TimeHistogram; -import com.navercorp.pinpoint.web.dao.MapResponseDao; -import com.navercorp.pinpoint.web.vo.Application; -import com.navercorp.pinpoint.web.vo.Range; -import com.navercorp.pinpoint.web.vo.ResponseTime; - -public class SlowCountCheckerTest { - - private static final String SERVICE_NAME = "local_service"; - - private static MapResponseDao mockMapResponseDAO; - - @BeforeClass - public static void before() { - mockMapResponseDAO = new MapResponseDao() { - - @Override - public List selectResponseTime(Application application, Range range) { - List list = new LinkedList(); - long timeStamp = 1409814914298L; - ResponseTime responseTime = new ResponseTime(SERVICE_NAME, ServiceType.STAND_ALONE, timeStamp); - list.add(responseTime); - TimeHistogram histogram = null; - - for (int i=0 ; i < 5; i++) { - for (int j=0 ; j < 5; j++) { - histogram = new TimeHistogram(ServiceType.STAND_ALONE, timeStamp); - histogram.addCallCountByElapsedTime(1000); - histogram.addCallCountByElapsedTime(3000); - histogram.addCallCountByElapsedTime(5000); - histogram.addCallCountByElapsedTime(6000); - histogram.addCallCountByElapsedTime(7000); - responseTime.addResponseTime("agent_" + i + "_" + j, histogram); - } - - timeStamp += 1; - } - - return list; - } - }; - } - - /* - * alert conditions not satisfied - */ - @Test - public void checkTest1() { - Application application = new Application(SERVICE_NAME, ServiceType.STAND_ALONE); - ResponseTimeDataCollector collector = new ResponseTimeDataCollector(DataCollectorCategory.RESPONSE_TIME, application, mockMapResponseDAO, System.currentTimeMillis(), 300000); - Rule rule = new Rule(SERVICE_NAME, CheckerCategory.SLOW_COUNT.getName(), 74, "testGroup", false, false, ""); - SlowCountChecker checker = new SlowCountChecker(collector, rule); - - checker.check(); - assertTrue(checker.isDetected()); - } - - /* - * alert conditions not satisfied - */ - @Test - public void checkTest2() { - Application application = new Application(SERVICE_NAME, ServiceType.STAND_ALONE); - ResponseTimeDataCollector collector = new ResponseTimeDataCollector(DataCollectorCategory.RESPONSE_TIME, application, mockMapResponseDAO, System.currentTimeMillis(), 300000); - Rule rule = new Rule(SERVICE_NAME, CheckerCategory.SLOW_COUNT.getName(), 76, "testGroup", false, false, ""); - SlowCountChecker checker = new SlowCountChecker(collector, rule); - - checker.check(); - assertFalse(checker.isDetected()); - } - - /* - the test data fetched directly from Hbase server. - use this in case of need because the data is not kept usually. - */ - /* - @Autowired - private HbaseMapResponseTimeDao hbaseMapResponseTimeDao; - - @Test - public void checkTest1() { - Application application = new Application(SERVICE_NAME, ServiceType.STAND_ALONE); - SlowCountFilter filter = new SlowCountFilter(application); - - AlarmRuleResource rule = new AlarmRuleResource(); - rule.setThresholdRule(10); - rule.setContinuousTime(36000000); - filter.initialize(rule); - - DefaultAlarmEvent event = new DefaultAlarmEvent(System.currentTimeMillis(), hbaseMapResponseTimeDao); - assertTrue(filter.check(event)); - } - */ -} +/* + * Copyright 2014 NAVER Corp. + * + * Licensed 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 com.navercorp.pinpoint.web.alarm.checker; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.util.LinkedList; +import java.util.List; + +import org.junit.BeforeClass; +import org.junit.Test; + +import com.navercorp.pinpoint.common.trace.ServiceType; +import com.navercorp.pinpoint.web.alarm.CheckerCategory; +import com.navercorp.pinpoint.web.alarm.DataCollectorFactory.DataCollectorCategory; +import com.navercorp.pinpoint.web.alarm.checker.SlowCountChecker; +import com.navercorp.pinpoint.web.alarm.collector.ResponseTimeDataCollector; +import com.navercorp.pinpoint.web.alarm.vo.Rule; +import com.navercorp.pinpoint.web.applicationmap.histogram.TimeHistogram; +import com.navercorp.pinpoint.web.dao.MapResponseDao; +import com.navercorp.pinpoint.web.vo.Application; +import com.navercorp.pinpoint.web.vo.Range; +import com.navercorp.pinpoint.web.vo.ResponseTime; + +public class SlowCountCheckerTest { + + private static final String SERVICE_NAME = "local_service"; + private static final String SERVICE_TYPE = "tomcat"; + + private static MapResponseDao mockMapResponseDAO; + + @BeforeClass + public static void before() { + mockMapResponseDAO = new MapResponseDao() { + + @Override + public List selectResponseTime(Application application, Range range) { + List list = new LinkedList(); + long timeStamp = 1409814914298L; + ResponseTime responseTime = new ResponseTime(SERVICE_NAME, ServiceType.STAND_ALONE, timeStamp); + list.add(responseTime); + TimeHistogram histogram = null; + + for (int i=0 ; i < 5; i++) { + for (int j=0 ; j < 5; j++) { + histogram = new TimeHistogram(ServiceType.STAND_ALONE, timeStamp); + histogram.addCallCountByElapsedTime(1000); + histogram.addCallCountByElapsedTime(3000); + histogram.addCallCountByElapsedTime(5000); + histogram.addCallCountByElapsedTime(6000); + histogram.addCallCountByElapsedTime(7000); + responseTime.addResponseTime("agent_" + i + "_" + j, histogram); + } + + timeStamp += 1; + } + + return list; + } + }; + } + + /* + * alert conditions not satisfied + */ + @Test + public void checkTest1() { + Application application = new Application(SERVICE_NAME, ServiceType.STAND_ALONE); + ResponseTimeDataCollector collector = new ResponseTimeDataCollector(DataCollectorCategory.RESPONSE_TIME, application, mockMapResponseDAO, System.currentTimeMillis(), 300000); + Rule rule = new Rule(SERVICE_NAME, SERVICE_TYPE, CheckerCategory.SLOW_COUNT.getName(), 74, "testGroup", false, false, ""); + SlowCountChecker checker = new SlowCountChecker(collector, rule); + + checker.check(); + assertTrue(checker.isDetected()); + } + + /* + * alert conditions not satisfied + */ + @Test + public void checkTest2() { + Application application = new Application(SERVICE_NAME, ServiceType.STAND_ALONE); + ResponseTimeDataCollector collector = new ResponseTimeDataCollector(DataCollectorCategory.RESPONSE_TIME, application, mockMapResponseDAO, System.currentTimeMillis(), 300000); + Rule rule = new Rule(SERVICE_NAME, SERVICE_TYPE, CheckerCategory.SLOW_COUNT.getName(), 76, "testGroup", false, false, ""); + SlowCountChecker checker = new SlowCountChecker(collector, rule); + + checker.check(); + assertFalse(checker.isDetected()); + } + + /* + the test data fetched directly from Hbase server. + use this in case of need because the data is not kept usually. + */ + /* + @Autowired + private HbaseMapResponseTimeDao hbaseMapResponseTimeDao; + + @Test + public void checkTest1() { + Application application = new Application(SERVICE_NAME, ServiceType.STAND_ALONE); + SlowCountFilter filter = new SlowCountFilter(application); + + AlarmRuleResource rule = new AlarmRuleResource(); + rule.setThresholdRule(10); + rule.setContinuousTime(36000000); + filter.initialize(rule); + + DefaultAlarmEvent event = new DefaultAlarmEvent(System.currentTimeMillis(), hbaseMapResponseTimeDao); + assertTrue(filter.check(event)); + } + */ +} diff --git a/web/src/test/java/com/navercorp/pinpoint/web/alarm/checker/SlowCountToCalleCheckerTest.java b/web/src/test/java/com/navercorp/pinpoint/web/alarm/checker/SlowCountToCalleCheckerTest.java index 2e3ee55f0..95cefd96e 100644 --- a/web/src/test/java/com/navercorp/pinpoint/web/alarm/checker/SlowCountToCalleCheckerTest.java +++ b/web/src/test/java/com/navercorp/pinpoint/web/alarm/checker/SlowCountToCalleCheckerTest.java @@ -43,6 +43,7 @@ public class SlowCountToCalleCheckerTest { private static final String FROM_SERVICE_NAME = "from_local_service"; private static final String TO_SERVICE_NAME = "to_local_service"; + private static final String SERVICE_TYPE = "tomcat"; public static MapStatisticsCallerDao dao; @BeforeClass @@ -84,7 +85,7 @@ public class SlowCountToCalleCheckerTest { public void checkTest() { Application application = new Application(FROM_SERVICE_NAME, ServiceType.STAND_ALONE); MapStatisticsCallerDataCollector dataCollector = new MapStatisticsCallerDataCollector(DataCollectorCategory.CALLER_STAT, application, dao, System.currentTimeMillis(), 300000); - Rule rule = new Rule(FROM_SERVICE_NAME, CheckerCategory.SLOW_COUNT_TO_CALLEE.getName(), 7, "testGroup", false, false, TO_SERVICE_NAME + 1); + Rule rule = new Rule(FROM_SERVICE_NAME, SERVICE_TYPE, CheckerCategory.SLOW_COUNT_TO_CALLEE.getName(), 7, "testGroup", false, false, TO_SERVICE_NAME + 1); SlowCountToCalleeChecker checker = new SlowCountToCalleeChecker(dataCollector, rule); checker.check(); @@ -95,7 +96,7 @@ public class SlowCountToCalleCheckerTest { public void checkTest2() { Application application = new Application(FROM_SERVICE_NAME, ServiceType.STAND_ALONE); MapStatisticsCallerDataCollector dataCollector = new MapStatisticsCallerDataCollector(DataCollectorCategory.CALLER_STAT, application, dao, System.currentTimeMillis(), 300000); - Rule rule = new Rule(FROM_SERVICE_NAME, CheckerCategory.SLOW_COUNT_TO_CALLEE.getName(), 8, "testGroup", false, false, TO_SERVICE_NAME + 1); + Rule rule = new Rule(FROM_SERVICE_NAME, SERVICE_TYPE, CheckerCategory.SLOW_COUNT_TO_CALLEE.getName(), 8, "testGroup", false, false, TO_SERVICE_NAME + 1); SlowCountToCalleeChecker checker = new SlowCountToCalleeChecker(dataCollector, rule); checker.check(); @@ -106,7 +107,7 @@ public class SlowCountToCalleCheckerTest { public void checkTest3() { Application application = new Application(FROM_SERVICE_NAME, ServiceType.STAND_ALONE); MapStatisticsCallerDataCollector dataCollector = new MapStatisticsCallerDataCollector(DataCollectorCategory.CALLER_STAT, application, dao, System.currentTimeMillis(), 300000); - Rule rule = new Rule(FROM_SERVICE_NAME, CheckerCategory.SLOW_COUNT_TO_CALLEE.getName(), 9, "testGroup", false, false, TO_SERVICE_NAME + 2); + Rule rule = new Rule(FROM_SERVICE_NAME, SERVICE_TYPE, CheckerCategory.SLOW_COUNT_TO_CALLEE.getName(), 9, "testGroup", false, false, TO_SERVICE_NAME + 2); SlowCountToCalleeChecker checker = new SlowCountToCalleeChecker(dataCollector, rule); checker.check(); diff --git a/web/src/test/java/com/navercorp/pinpoint/web/alarm/checker/SlowRateCheckerTest.java b/web/src/test/java/com/navercorp/pinpoint/web/alarm/checker/SlowRateCheckerTest.java index f7d1e93bc..6ff8bfeeb 100644 --- a/web/src/test/java/com/navercorp/pinpoint/web/alarm/checker/SlowRateCheckerTest.java +++ b/web/src/test/java/com/navercorp/pinpoint/web/alarm/checker/SlowRateCheckerTest.java @@ -1,105 +1,106 @@ -/* - * Copyright 2014 NAVER Corp. - * - * Licensed 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 com.navercorp.pinpoint.web.alarm.checker; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.util.LinkedList; -import java.util.List; - -import org.junit.BeforeClass; -import org.junit.Test; - -import com.navercorp.pinpoint.common.trace.ServiceType; -import com.navercorp.pinpoint.web.alarm.CheckerCategory; -import com.navercorp.pinpoint.web.alarm.DataCollectorFactory.DataCollectorCategory; -import com.navercorp.pinpoint.web.alarm.checker.SlowRateChecker; -import com.navercorp.pinpoint.web.alarm.collector.ResponseTimeDataCollector; -import com.navercorp.pinpoint.web.alarm.vo.Rule; -import com.navercorp.pinpoint.web.applicationmap.histogram.TimeHistogram; -import com.navercorp.pinpoint.web.dao.MapResponseDao; -import com.navercorp.pinpoint.web.vo.Application; -import com.navercorp.pinpoint.web.vo.Range; -import com.navercorp.pinpoint.web.vo.ResponseTime; - -public class SlowRateCheckerTest { - - private static final String SERVICE_NAME = "local_service"; - - private static MapResponseDao mockMapResponseDAO; - - @BeforeClass - public static void before() { - mockMapResponseDAO = new MapResponseDao() { - - @Override - public List selectResponseTime(Application application, Range range) { - List list = new LinkedList(); - long timeStamp = 1409814914298L; - ResponseTime responseTime = new ResponseTime(SERVICE_NAME, ServiceType.STAND_ALONE, timeStamp); - list.add(responseTime); - TimeHistogram histogram = null; - - for (int i=0 ; i < 5; i++) { - for (int j=0 ; j < 5; j++) { - histogram = new TimeHistogram(ServiceType.STAND_ALONE, timeStamp); - histogram.addCallCountByElapsedTime(1000); - histogram.addCallCountByElapsedTime(3000); - histogram.addCallCountByElapsedTime(5000); - histogram.addCallCountByElapsedTime(6000); - histogram.addCallCountByElapsedTime(7000); - responseTime.addResponseTime("agent_" + i + "_" + j, histogram); - } - - timeStamp += 1; - } - - return list; - } - }; - } - - /* - * not satisfied with alert condition - */ - @Test - public void checkTest1() { - Application application = new Application(SERVICE_NAME, ServiceType.STAND_ALONE); - ResponseTimeDataCollector collector = new ResponseTimeDataCollector(DataCollectorCategory.RESPONSE_TIME, application, mockMapResponseDAO, System.currentTimeMillis(), 300000); - Rule rule = new Rule(SERVICE_NAME, CheckerCategory.SLOW_RATE.getName(), 60, "testGroup", false, false, ""); - SlowRateChecker filter = new SlowRateChecker(collector, rule); - - filter.check(); - assertTrue(filter.isDetected()); - } - - /* - * not satisfied with alert condition - */ - @Test - public void checkTest2() { - Application application = new Application(SERVICE_NAME, ServiceType.STAND_ALONE); - ResponseTimeDataCollector collector = new ResponseTimeDataCollector(DataCollectorCategory.RESPONSE_TIME, application, mockMapResponseDAO, System.currentTimeMillis(), 300000); - Rule rule = new Rule(SERVICE_NAME, CheckerCategory.SLOW_RATE.getName(), 61, "testGroup", false, false, ""); - SlowRateChecker filter = new SlowRateChecker(collector, rule); - - filter.check(); - assertFalse(filter.isDetected()); - } - -} +/* + * Copyright 2014 NAVER Corp. + * + * Licensed 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 com.navercorp.pinpoint.web.alarm.checker; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.util.LinkedList; +import java.util.List; + +import org.junit.BeforeClass; +import org.junit.Test; + +import com.navercorp.pinpoint.common.trace.ServiceType; +import com.navercorp.pinpoint.web.alarm.CheckerCategory; +import com.navercorp.pinpoint.web.alarm.DataCollectorFactory.DataCollectorCategory; +import com.navercorp.pinpoint.web.alarm.checker.SlowRateChecker; +import com.navercorp.pinpoint.web.alarm.collector.ResponseTimeDataCollector; +import com.navercorp.pinpoint.web.alarm.vo.Rule; +import com.navercorp.pinpoint.web.applicationmap.histogram.TimeHistogram; +import com.navercorp.pinpoint.web.dao.MapResponseDao; +import com.navercorp.pinpoint.web.vo.Application; +import com.navercorp.pinpoint.web.vo.Range; +import com.navercorp.pinpoint.web.vo.ResponseTime; + +public class SlowRateCheckerTest { + + private static final String SERVICE_NAME = "local_service"; + private static final String SERVICE_TYPE = "tomcat"; + + private static MapResponseDao mockMapResponseDAO; + + @BeforeClass + public static void before() { + mockMapResponseDAO = new MapResponseDao() { + + @Override + public List selectResponseTime(Application application, Range range) { + List list = new LinkedList(); + long timeStamp = 1409814914298L; + ResponseTime responseTime = new ResponseTime(SERVICE_NAME, ServiceType.STAND_ALONE, timeStamp); + list.add(responseTime); + TimeHistogram histogram = null; + + for (int i=0 ; i < 5; i++) { + for (int j=0 ; j < 5; j++) { + histogram = new TimeHistogram(ServiceType.STAND_ALONE, timeStamp); + histogram.addCallCountByElapsedTime(1000); + histogram.addCallCountByElapsedTime(3000); + histogram.addCallCountByElapsedTime(5000); + histogram.addCallCountByElapsedTime(6000); + histogram.addCallCountByElapsedTime(7000); + responseTime.addResponseTime("agent_" + i + "_" + j, histogram); + } + + timeStamp += 1; + } + + return list; + } + }; + } + + /* + * not satisfied with alert condition + */ + @Test + public void checkTest1() { + Application application = new Application(SERVICE_NAME, ServiceType.STAND_ALONE); + ResponseTimeDataCollector collector = new ResponseTimeDataCollector(DataCollectorCategory.RESPONSE_TIME, application, mockMapResponseDAO, System.currentTimeMillis(), 300000); + Rule rule = new Rule(SERVICE_NAME, SERVICE_TYPE, CheckerCategory.SLOW_RATE.getName(), 60, "testGroup", false, false, ""); + SlowRateChecker filter = new SlowRateChecker(collector, rule); + + filter.check(); + assertTrue(filter.isDetected()); + } + + /* + * not satisfied with alert condition + */ + @Test + public void checkTest2() { + Application application = new Application(SERVICE_NAME, ServiceType.STAND_ALONE); + ResponseTimeDataCollector collector = new ResponseTimeDataCollector(DataCollectorCategory.RESPONSE_TIME, application, mockMapResponseDAO, System.currentTimeMillis(), 300000); + Rule rule = new Rule(SERVICE_NAME, SERVICE_TYPE, CheckerCategory.SLOW_RATE.getName(), 61, "testGroup", false, false, ""); + SlowRateChecker filter = new SlowRateChecker(collector, rule); + + filter.check(); + assertFalse(filter.isDetected()); + } + +} diff --git a/web/src/test/java/com/navercorp/pinpoint/web/alarm/checker/SlowRateToCalleCheckerTest.java b/web/src/test/java/com/navercorp/pinpoint/web/alarm/checker/SlowRateToCalleCheckerTest.java index 9e0f47221..e91b547e7 100644 --- a/web/src/test/java/com/navercorp/pinpoint/web/alarm/checker/SlowRateToCalleCheckerTest.java +++ b/web/src/test/java/com/navercorp/pinpoint/web/alarm/checker/SlowRateToCalleCheckerTest.java @@ -44,6 +44,7 @@ public class SlowRateToCalleCheckerTest { private static final String FROM_SERVICE_NAME = "from_local_service"; private static final String TO_SERVICE_NAME = "to_local_service"; + private static final String SERVICE_TYPE = "tomcat"; public static MapStatisticsCallerDao dao; @BeforeClass @@ -85,7 +86,7 @@ public class SlowRateToCalleCheckerTest { public void checkTest() { Application application = new Application(FROM_SERVICE_NAME, ServiceType.STAND_ALONE); MapStatisticsCallerDataCollector dataCollector = new MapStatisticsCallerDataCollector(DataCollectorCategory.CALLER_STAT, application, dao, System.currentTimeMillis(), 300000); - Rule rule = new Rule(FROM_SERVICE_NAME, CheckerCategory.SLOW_RATE_TO_CALLEE.getName(), 70, "testGroup", false, false, TO_SERVICE_NAME + 1); + Rule rule = new Rule(FROM_SERVICE_NAME, SERVICE_TYPE, CheckerCategory.SLOW_RATE_TO_CALLEE.getName(), 70, "testGroup", false, false, TO_SERVICE_NAME + 1); SlowRateToCalleeChecker checker = new SlowRateToCalleeChecker(dataCollector, rule); checker.check(); @@ -96,7 +97,7 @@ public class SlowRateToCalleCheckerTest { public void checkTest2() { Application application = new Application(FROM_SERVICE_NAME, ServiceType.STAND_ALONE); MapStatisticsCallerDataCollector dataCollector = new MapStatisticsCallerDataCollector(DataCollectorCategory.CALLER_STAT, application, dao, System.currentTimeMillis(), 300000); - Rule rule = new Rule(FROM_SERVICE_NAME, CheckerCategory.SLOW_RATE_TO_CALLEE.getName(), 71, "testGroup", false, false, TO_SERVICE_NAME + 1); + Rule rule = new Rule(FROM_SERVICE_NAME, SERVICE_TYPE, CheckerCategory.SLOW_RATE_TO_CALLEE.getName(), 71, "testGroup", false, false, TO_SERVICE_NAME + 1); SlowRateToCalleeChecker checker = new SlowRateToCalleeChecker(dataCollector, rule); checker.check(); @@ -107,7 +108,7 @@ public class SlowRateToCalleCheckerTest { public void checkTest3() { Application application = new Application(FROM_SERVICE_NAME, ServiceType.STAND_ALONE); MapStatisticsCallerDataCollector dataCollector = new MapStatisticsCallerDataCollector(DataCollectorCategory.CALLER_STAT, application, dao, System.currentTimeMillis(), 300000); - Rule rule = new Rule(FROM_SERVICE_NAME, CheckerCategory.SLOW_RATE_TO_CALLEE.getName(), 90, "testGroup", false, false, TO_SERVICE_NAME + 2); + Rule rule = new Rule(FROM_SERVICE_NAME, SERVICE_TYPE, CheckerCategory.SLOW_RATE_TO_CALLEE.getName(), 90, "testGroup", false, false, TO_SERVICE_NAME + 2); SlowRateToCalleeChecker checker = new SlowRateToCalleeChecker(dataCollector, rule); checker.check(); diff --git a/web/src/test/java/com/navercorp/pinpoint/web/alarm/checker/TotalCountToCalleCheckerTest.java b/web/src/test/java/com/navercorp/pinpoint/web/alarm/checker/TotalCountToCalleCheckerTest.java index 6a6377002..ffa91ae50 100644 --- a/web/src/test/java/com/navercorp/pinpoint/web/alarm/checker/TotalCountToCalleCheckerTest.java +++ b/web/src/test/java/com/navercorp/pinpoint/web/alarm/checker/TotalCountToCalleCheckerTest.java @@ -43,6 +43,7 @@ public class TotalCountToCalleCheckerTest { private static final String FROM_SERVICE_NAME = "from_local_service"; private static final String TO_SERVICE_NAME = "to_local_service"; + private static final String SERVICE_TYPE = "tomcat"; public static MapStatisticsCallerDao dao; @BeforeClass @@ -84,7 +85,7 @@ public class TotalCountToCalleCheckerTest { public void checkTest() { Application application = new Application(FROM_SERVICE_NAME, ServiceType.STAND_ALONE); MapStatisticsCallerDataCollector dataCollector = new MapStatisticsCallerDataCollector(DataCollectorCategory.CALLER_STAT, application, dao, System.currentTimeMillis(), 300000); - Rule rule = new Rule(FROM_SERVICE_NAME, CheckerCategory.TOTAL_COUNT_TO_CALLEE.getName(), 10, "testGroup", false, false, TO_SERVICE_NAME + 1); + Rule rule = new Rule(FROM_SERVICE_NAME, SERVICE_TYPE, CheckerCategory.TOTAL_COUNT_TO_CALLEE.getName(), 10, "testGroup", false, false, TO_SERVICE_NAME + 1); TotalCountToCalleeChecker checker = new TotalCountToCalleeChecker(dataCollector, rule); checker.check(); @@ -95,7 +96,7 @@ public class TotalCountToCalleCheckerTest { public void checkTest2() { Application application = new Application(FROM_SERVICE_NAME, ServiceType.STAND_ALONE); MapStatisticsCallerDataCollector dataCollector = new MapStatisticsCallerDataCollector(DataCollectorCategory.CALLER_STAT, application, dao, System.currentTimeMillis(), 300000); - Rule rule = new Rule(FROM_SERVICE_NAME, CheckerCategory.TOTAL_COUNT_TO_CALLEE.getName(), 11, "testGroup", false, false, TO_SERVICE_NAME + 1); + Rule rule = new Rule(FROM_SERVICE_NAME, SERVICE_TYPE, CheckerCategory.TOTAL_COUNT_TO_CALLEE.getName(), 11, "testGroup", false, false, TO_SERVICE_NAME + 1); TotalCountToCalleeChecker checker = new TotalCountToCalleeChecker(dataCollector, rule); checker.check(); @@ -106,7 +107,7 @@ public class TotalCountToCalleCheckerTest { public void checkTest3() { Application application = new Application(FROM_SERVICE_NAME, ServiceType.STAND_ALONE); MapStatisticsCallerDataCollector dataCollector = new MapStatisticsCallerDataCollector(DataCollectorCategory.CALLER_STAT, application, dao, System.currentTimeMillis(), 300000); - Rule rule = new Rule(FROM_SERVICE_NAME, CheckerCategory.TOTAL_COUNT_TO_CALLEE.getName(), 10, "testGroup", false, false, TO_SERVICE_NAME + 2); + Rule rule = new Rule(FROM_SERVICE_NAME, SERVICE_TYPE, CheckerCategory.TOTAL_COUNT_TO_CALLEE.getName(), 10, "testGroup", false, false, TO_SERVICE_NAME + 2); TotalCountToCalleeChecker checker = new TotalCountToCalleeChecker(dataCollector, rule); checker.check(); diff --git a/web/src/test/java/com/navercorp/pinpoint/web/controller/AlarmControllerTest.java b/web/src/test/java/com/navercorp/pinpoint/web/controller/AlarmControllerTest.java index c331055e4..e10dd7045 100644 --- a/web/src/test/java/com/navercorp/pinpoint/web/controller/AlarmControllerTest.java +++ b/web/src/test/java/com/navercorp/pinpoint/web/controller/AlarmControllerTest.java @@ -59,6 +59,8 @@ import com.navercorp.pinpoint.web.dao.AlarmDao; public class AlarmControllerTest { private final static String APPLICATION_ID = "test-application"; private final static String APPLICATION_ID_UPDATED = "test-application-tomcat"; + + private final static String SERVICE_TYPE = "tomcat"; private final static String USER_GROUP_ID = "test-pinpoint_group"; private final static String USER_GROUP_ID_UPDATED = "test-pinpoint_team"; @@ -98,6 +100,7 @@ public class AlarmControllerTest { public void insertAndSelectAndDeleteRule() throws Exception { String jsonParm = "{" + "\"applicationId\" : \"" + APPLICATION_ID + "\"," + + "\"serviceType\" : \"" + SERVICE_TYPE + "\"," + "\"userGroupId\" : \"" + USER_GROUP_ID + "\"," + "\"checkerName\" : \"" + CHECKER_NAME + "\"," + "\"threshold\" : " + THRESHOLD + "," + @@ -117,10 +120,11 @@ public class AlarmControllerTest { Assert.assertEquals(resultMap.get("result"), "SUCCESS"); Assert.assertNotNull(resultMap.get("ruleId")); - this.mockMvc.perform(get("/alarmRule.pinpoint").contentType(MediaType.APPLICATION_JSON).content("{\"userGroupId\" : \"" + USER_GROUP_ID + "\"}")) + this.mockMvc.perform(get("/alarmRule.pinpoint?userGroupId=" + USER_GROUP_ID)) .andExpect(status().isOk()) .andExpect(content().contentType("application/json;charset=UTF-8")) .andExpect(jsonPath("$[0]", hasKey("applicationId"))) + .andExpect(jsonPath("$[0]", hasKey("serviceType"))) .andExpect(jsonPath("$[0]", hasKey("userGroupId"))) .andExpect(jsonPath("$[0]", hasKey("checkerName"))) .andExpect(jsonPath("$[0]", hasKey("threshold"))) @@ -142,6 +146,7 @@ public class AlarmControllerTest { public void updateRule() throws Exception { String jsonParm = "{" + "\"applicationId\" : \"" + APPLICATION_ID + "\"," + + "\"serviceType\" : \"" + SERVICE_TYPE + "\"," + "\"userGroupId\" : \"" + USER_GROUP_ID + "\"," + "\"checkerName\" : \"" + CHECKER_NAME + "\"," + "\"threshold\" : " + THRESHOLD + "," + @@ -164,6 +169,7 @@ public class AlarmControllerTest { String updatedJsonParm = "{" + "\"ruleId\" : \"" + resultMap.get("ruleId") + "\"," + "\"applicationId\" : \"" + APPLICATION_ID_UPDATED + "\"," + + "\"serviceType\" : \"" + SERVICE_TYPE + "\"," + "\"userGroupId\" : \"" + USER_GROUP_ID_UPDATED + "\"," + "\"checkerName\" : \"" + CHECKER_NAME_UPDATED + "\"," + "\"threshold\" : " + THRESHOLD_UPDATED + "," + @@ -179,12 +185,12 @@ public class AlarmControllerTest { .andExpect(jsonPath("$.result").value("SUCCESS")) .andReturn(); -// this.mockMvc.perform(delete("/alarmRule.pinpoint").contentType(MediaType.APPLICATION_JSON).content("{\"ruleId\" : \"" + resultMap.get("ruleId") + "\"}")) -// .andExpect(status().isOk()) -// .andExpect(content().contentType("application/json;charset=UTF-8")) -// .andExpect(jsonPath("$", hasKey("result"))) -// .andExpect(jsonPath("$.result").value("SUCCESS")) -// .andReturn(); + this.mockMvc.perform(delete("/alarmRule.pinpoint").contentType(MediaType.APPLICATION_JSON).content("{\"ruleId\" : \"" + resultMap.get("ruleId") + "\"}")) + .andExpect(status().isOk()) + .andExpect(content().contentType("application/json;charset=UTF-8")) + .andExpect(jsonPath("$", hasKey("result"))) + .andExpect(jsonPath("$.result").value("SUCCESS")) + .andReturn(); } @Test @@ -200,5 +206,4 @@ public class AlarmControllerTest { List checherList = objectMapper.readValue(content, List.class); Assert.assertNotEquals(checherList.size(), 0); } - }