You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@helix.apache.org by zz...@apache.org on 2014/05/21 00:48:59 UTC
[2/6] [HELIX-395] Remove old Helix alert/stat modules
http://git-wip-us.apache.org/repos/asf/helix/blob/77cc6516/helix-core/src/test/java/org/apache/helix/alerts/TestOperators.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/alerts/TestOperators.java b/helix-core/src/test/java/org/apache/helix/alerts/TestOperators.java
deleted file mode 100644
index 2d54a27..0000000
--- a/helix-core/src/test/java/org/apache/helix/alerts/TestOperators.java
+++ /dev/null
@@ -1,329 +0,0 @@
-package org.apache.helix.alerts;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.helix.alerts.SumEachOperator;
-import org.apache.helix.alerts.SumOperator;
-import org.apache.helix.alerts.Tuple;
-import org.testng.AssertJUnit;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-public class TestOperators {
-
- SumOperator _sumOp;
- SumEachOperator _sumEachOp;
-
- @BeforeMethod(groups = {
- "unitTest"
- })
- public void setup() {
- _sumOp = new SumOperator();
- _sumEachOp = new SumEachOperator();
- }
-
- @Test(groups = {
- "unitTest"
- })
- public void testTwoNulls() {
- Tuple<String> tup1 = null;
- Tuple<String> tup2 = null;
- List<Tuple<String>> tup1List = new ArrayList<Tuple<String>>();
- List<Tuple<String>> tup2List = new ArrayList<Tuple<String>>();
- tup1List.add(tup1);
- tup2List.add(tup2);
- List<Iterator<Tuple<String>>> tupsList = new ArrayList<Iterator<Tuple<String>>>();
- tupsList.add(tup1List.iterator());
- tupsList.add(tup2List.iterator());
- List<Iterator<Tuple<String>>> result = _sumOp.execute(tupsList);
- AssertJUnit.assertEquals(1, result.size()); // should be just 1 iter
- Iterator<Tuple<String>> resultIter = result.get(0);
- AssertJUnit.assertTrue(resultIter.hasNext());
- Tuple<String> resultTup = resultIter.next();
- AssertJUnit.assertEquals(null, resultTup);
- }
-
- @Test(groups = {
- "unitTest"
- })
- public void testOneNullLeft() {
- Tuple<String> tup1 = null;
- Tuple<String> tup2 = new Tuple<String>();
- tup2.add("1.0");
- List<Tuple<String>> tup1List = new ArrayList<Tuple<String>>();
- List<Tuple<String>> tup2List = new ArrayList<Tuple<String>>();
- tup1List.add(tup1);
- tup2List.add(tup2);
- List<Iterator<Tuple<String>>> tupsList = new ArrayList<Iterator<Tuple<String>>>();
- tupsList.add(tup1List.iterator());
- tupsList.add(tup2List.iterator());
- List<Iterator<Tuple<String>>> result = _sumOp.execute(tupsList);
- AssertJUnit.assertEquals(1, result.size()); // should be just 1 iter
- Iterator<Tuple<String>> resultIter = result.get(0);
- AssertJUnit.assertTrue(resultIter.hasNext());
- Tuple<String> resultTup = resultIter.next();
- AssertJUnit.assertEquals("1.0", resultTup.toString());
- }
-
- @Test(groups = {
- "unitTest"
- })
- public void testOneNullRight() {
- Tuple<String> tup1 = new Tuple<String>();
- Tuple<String> tup2 = null;
- tup1.add("1.0");
- List<Tuple<String>> tup1List = new ArrayList<Tuple<String>>();
- List<Tuple<String>> tup2List = new ArrayList<Tuple<String>>();
- tup1List.add(tup1);
- tup2List.add(tup2);
- List<Iterator<Tuple<String>>> tupsList = new ArrayList<Iterator<Tuple<String>>>();
- tupsList.add(tup1List.iterator());
- tupsList.add(tup2List.iterator());
- List<Iterator<Tuple<String>>> result = _sumOp.execute(tupsList);
- AssertJUnit.assertEquals(1, result.size()); // should be just 1 iter
- Iterator<Tuple<String>> resultIter = result.get(0);
- AssertJUnit.assertTrue(resultIter.hasNext());
- Tuple<String> resultTup = resultIter.next();
- AssertJUnit.assertEquals("1.0", resultTup.toString());
- }
-
- @Test(groups = {
- "unitTest"
- })
- public void testTwoSingeltons() {
- Tuple<String> tup1 = new Tuple<String>();
- Tuple<String> tup2 = new Tuple<String>();
- tup1.add("1.0");
- tup2.add("2.0");
- List<Tuple<String>> tup1List = new ArrayList<Tuple<String>>();
- List<Tuple<String>> tup2List = new ArrayList<Tuple<String>>();
- tup1List.add(tup1);
- tup2List.add(tup2);
- List<Iterator<Tuple<String>>> tupsList = new ArrayList<Iterator<Tuple<String>>>();
- tupsList.add(tup1List.iterator());
- tupsList.add(tup2List.iterator());
- List<Iterator<Tuple<String>>> result = _sumOp.execute(tupsList);
- AssertJUnit.assertEquals(1, result.size()); // should be just 1 iter
- Iterator<Tuple<String>> resultIter = result.get(0);
- AssertJUnit.assertTrue(resultIter.hasNext());
- Tuple<String> resultTup = resultIter.next();
- AssertJUnit.assertEquals("3.0", resultTup.toString());
- }
-
- @Test(groups = {
- "unitTest"
- })
- public void testThreeSingeltons() {
- Tuple<String> tup1 = new Tuple<String>();
- Tuple<String> tup2 = new Tuple<String>();
- Tuple<String> tup3 = new Tuple<String>();
- tup1.add("1.0");
- tup2.add("2.0");
- tup3.add("3.0");
- List<Tuple<String>> tup1List = new ArrayList<Tuple<String>>();
- List<Tuple<String>> tup2List = new ArrayList<Tuple<String>>();
- List<Tuple<String>> tup3List = new ArrayList<Tuple<String>>();
- tup1List.add(tup1);
- tup2List.add(tup2);
- tup3List.add(tup3);
- List<Iterator<Tuple<String>>> tupsList = new ArrayList<Iterator<Tuple<String>>>();
- tupsList.add(tup1List.iterator());
- tupsList.add(tup2List.iterator());
- tupsList.add(tup3List.iterator());
- List<Iterator<Tuple<String>>> result = _sumOp.execute(tupsList);
- AssertJUnit.assertEquals(1, result.size()); // should be just 1 iter
- Iterator<Tuple<String>> resultIter = result.get(0);
- AssertJUnit.assertTrue(resultIter.hasNext());
- Tuple<String> resultTup = resultIter.next();
- AssertJUnit.assertEquals("6.0", resultTup.toString());
- }
-
- @Test(groups = {
- "unitTest"
- })
- public void testThreeTriples() {
- Tuple<String> tup1 = new Tuple<String>();
- Tuple<String> tup2 = new Tuple<String>();
- Tuple<String> tup3 = new Tuple<String>();
- tup1.add("1.0");
- tup1.add("2.0");
- tup1.add("3.0");
- tup2.add("4.0");
- tup2.add("5.0");
- tup2.add("6.0");
- tup3.add("7.0");
- tup3.add("8.0");
- tup3.add("9.0");
- List<Tuple<String>> tup1List = new ArrayList<Tuple<String>>();
- List<Tuple<String>> tup2List = new ArrayList<Tuple<String>>();
- List<Tuple<String>> tup3List = new ArrayList<Tuple<String>>();
- tup1List.add(tup1);
- tup2List.add(tup2);
- tup3List.add(tup3);
- List<Iterator<Tuple<String>>> tupsList = new ArrayList<Iterator<Tuple<String>>>();
- tupsList.add(tup1List.iterator());
- tupsList.add(tup2List.iterator());
- tupsList.add(tup3List.iterator());
- List<Iterator<Tuple<String>>> result = _sumOp.execute(tupsList);
- AssertJUnit.assertEquals(1, result.size()); // should be just 1 iter
- Iterator<Tuple<String>> resultIter = result.get(0);
- AssertJUnit.assertTrue(resultIter.hasNext());
- Tuple<String> resultTup = resultIter.next();
- AssertJUnit.assertEquals("12.0,15.0,18.0", resultTup.toString());
- }
-
- @Test(groups = {
- "unitTest"
- })
- public void testThreeTriplesOneMissing() {
- Tuple<String> tup1 = new Tuple<String>();
- Tuple<String> tup2 = new Tuple<String>();
- Tuple<String> tup3 = new Tuple<String>();
- tup1.add("1.0");
- tup1.add("2.0");
- tup1.add("3.0");
- tup2.add("5.0");
- tup2.add("6.0");
- tup3.add("7.0");
- tup3.add("8.0");
- tup3.add("9.0");
- List<Tuple<String>> tup1List = new ArrayList<Tuple<String>>();
- List<Tuple<String>> tup2List = new ArrayList<Tuple<String>>();
- List<Tuple<String>> tup3List = new ArrayList<Tuple<String>>();
- tup1List.add(tup1);
- tup2List.add(tup2);
- tup3List.add(tup3);
- List<Iterator<Tuple<String>>> tupsList = new ArrayList<Iterator<Tuple<String>>>();
- tupsList.add(tup1List.iterator());
- tupsList.add(tup2List.iterator());
- tupsList.add(tup3List.iterator());
- List<Iterator<Tuple<String>>> result = _sumOp.execute(tupsList);
- AssertJUnit.assertEquals(1, result.size()); // should be just 1 iter
- Iterator<Tuple<String>> resultIter = result.get(0);
- AssertJUnit.assertTrue(resultIter.hasNext());
- Tuple<String> resultTup = resultIter.next();
- // tuple 2 missing 1 entry, other 2 get bumped to right
- AssertJUnit.assertEquals("8.0,15.0,18.0", resultTup.toString());
- }
-
- // test multiple rows
- @Test(groups = {
- "unitTest"
- })
- public void testThreeTriplesOneMissingTwoRows() {
- Tuple<String> tup1Dot1 = new Tuple<String>();
- Tuple<String> tup2Dot1 = new Tuple<String>();
- Tuple<String> tup3Dot1 = new Tuple<String>();
- Tuple<String> tup1Dot2 = new Tuple<String>();
- Tuple<String> tup2Dot2 = new Tuple<String>();
- Tuple<String> tup3Dot2 = new Tuple<String>();
- tup1Dot1.add("1.0");
- tup1Dot1.add("2.0");
- tup1Dot1.add("3.0");
- tup2Dot1.add("5.0");
- tup2Dot1.add("6.0");
- tup3Dot1.add("7.0");
- tup3Dot1.add("8.0");
- tup3Dot1.add("9.0");
- tup1Dot2.add("10.0");
- tup1Dot2.add("11.0");
- tup1Dot2.add("12.0");
- tup2Dot2.add("13.0");
- tup2Dot2.add("14.0");
- tup2Dot2.add("15.0");
- tup3Dot2.add("16.0");
- tup3Dot2.add("17.0");
- tup3Dot2.add("18.0");
- List<Tuple<String>> tup1List = new ArrayList<Tuple<String>>();
- List<Tuple<String>> tup2List = new ArrayList<Tuple<String>>();
- List<Tuple<String>> tup3List = new ArrayList<Tuple<String>>();
- tup1List.add(tup1Dot1);
- tup2List.add(tup2Dot1);
- tup3List.add(tup3Dot1);
- tup1List.add(tup1Dot2);
- tup2List.add(tup2Dot2);
- tup3List.add(tup3Dot2);
- List<Iterator<Tuple<String>>> tupsList = new ArrayList<Iterator<Tuple<String>>>();
- tupsList.add(tup1List.iterator());
- tupsList.add(tup2List.iterator());
- tupsList.add(tup3List.iterator());
- List<Iterator<Tuple<String>>> result = _sumOp.execute(tupsList);
- AssertJUnit.assertEquals(1, result.size()); // should be just 1 iter
- Iterator<Tuple<String>> resultIter = result.get(0);
- AssertJUnit.assertTrue(resultIter.hasNext());
- Tuple<String> resultTup1 = resultIter.next();
- // tuple 2 missing 1 entry, other 2 get bumped to right
- AssertJUnit.assertEquals("8.0,15.0,18.0", resultTup1.toString());
- AssertJUnit.assertTrue(resultIter.hasNext());
- Tuple<String> resultTup2 = resultIter.next();
- AssertJUnit.assertEquals("39.0,42.0,45.0", resultTup2.toString());
- }
-
- @Test(groups = {
- "unitTest"
- })
- public void testSumAll() {
- Tuple<String> tup1 = new Tuple<String>();
- Tuple<String> tup2 = new Tuple<String>();
- Tuple<String> tup3 = new Tuple<String>();
- Tuple<String> tup4 = new Tuple<String>();
- Tuple<String> tup5 = new Tuple<String>();
- Tuple<String> tup6 = new Tuple<String>();
- tup1.add("1.0");
- tup2.add("2.0");
- tup3.add("3.0");
- tup4.add("4.0");
- tup5.add("5.0");
- tup6.add("6.0");
- List<Tuple<String>> list1 = new ArrayList<Tuple<String>>();
- List<Tuple<String>> list2 = new ArrayList<Tuple<String>>();
- List<Tuple<String>> list3 = new ArrayList<Tuple<String>>();
- list1.add(tup1);
- list1.add(tup4);
- list2.add(tup2);
- list2.add(tup5);
- list3.add(tup3);
- list3.add(tup6);
-
- List<Iterator<Tuple<String>>> tupsList = new ArrayList<Iterator<Tuple<String>>>();
- tupsList.add(list1.iterator());
- tupsList.add(list2.iterator());
- tupsList.add(list3.iterator());
- List<Iterator<Tuple<String>>> result = _sumEachOp.execute(tupsList);
- AssertJUnit.assertEquals(3, result.size()); // should be just 1 iter
- Iterator<Tuple<String>> resultIter = result.get(0);
- AssertJUnit.assertTrue(resultIter.hasNext());
- Tuple<String> resultTup1 = resultIter.next();
- AssertJUnit.assertEquals("5.0", resultTup1.toString());
- resultIter = result.get(1);
- AssertJUnit.assertTrue(resultIter.hasNext());
- resultTup1 = resultIter.next();
- AssertJUnit.assertEquals("7.0", resultTup1.toString());
- resultIter = result.get(2);
- AssertJUnit.assertTrue(resultIter.hasNext());
- resultTup1 = resultIter.next();
- AssertJUnit.assertEquals("9.0", resultTup1.toString());
- }
-}
http://git-wip-us.apache.org/repos/asf/helix/blob/77cc6516/helix-core/src/test/java/org/apache/helix/alerts/TestStatsMatch.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/alerts/TestStatsMatch.java b/helix-core/src/test/java/org/apache/helix/alerts/TestStatsMatch.java
deleted file mode 100644
index 094f347..0000000
--- a/helix-core/src/test/java/org/apache/helix/alerts/TestStatsMatch.java
+++ /dev/null
@@ -1,107 +0,0 @@
-package org.apache.helix.alerts;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-import org.apache.helix.HelixException;
-import org.apache.helix.alerts.ExpressionParser;
-import org.testng.annotations.Test;
-import org.testng.AssertJUnit;
-import org.testng.Assert;
-import org.testng.annotations.Test;
-
-@Test
-public class TestStatsMatch {
-
- @Test
- public void testExactMatch() {
-
- String persistedStatName = "window(5)(dbFoo.partition10.latency)";
- String incomingStatName = "dbFoo.partition10.latency";
- AssertJUnit.assertTrue(ExpressionParser.isIncomingStatExactMatch(persistedStatName,
- incomingStatName));
- }
-
- @Test
- public void testSingleWildcardMatch() {
-
- String persistedStatName = "window(5)(dbFoo.partition*.latency)";
- String incomingStatName = "dbFoo.partition10.latency";
- AssertJUnit.assertTrue(ExpressionParser.isIncomingStatWildcardMatch(persistedStatName,
- incomingStatName));
- }
-
- @Test
- public void testDoubleWildcardMatch() {
-
- String persistedStatName = "window(5)(db*.partition*.latency)";
- String incomingStatName = "dbFoo.partition10.latency";
- AssertJUnit.assertTrue(ExpressionParser.isIncomingStatWildcardMatch(persistedStatName,
- incomingStatName));
- }
-
- @Test
- public void testWildcardMatchNoWildcard() {
-
- String persistedStatName = "window(5)(dbFoo.partition10.latency)";
- String incomingStatName = "dbFoo.partition10.latency";
- AssertJUnit.assertFalse(ExpressionParser.isIncomingStatWildcardMatch(persistedStatName,
- incomingStatName));
- }
-
- @Test
- public void testWildcardMatchTooManyFields() {
-
- String persistedStatName = "window(5)(dbFoo.partition*.latency)";
- String incomingStatName = "dbFoo.tableBar.partition10.latency";
- AssertJUnit.assertFalse(ExpressionParser.isIncomingStatWildcardMatch(persistedStatName,
- incomingStatName));
- }
-
- @Test
- public void testWildcardMatchTooFewFields() {
-
- String persistedStatName = "window(5)(dbFoo.partition*.latency)";
- String incomingStatName = "dbFoo.latency";
- AssertJUnit.assertFalse(ExpressionParser.isIncomingStatWildcardMatch(persistedStatName,
- incomingStatName));
- }
-
- @Test
- public void testBadWildcardRepeated() {
-
- String persistedStatName = "window(5)(dbFoo.partition**4.latency)";
- String incomingStatName = "dbFoo.partition10.latency";
- boolean match =
- ExpressionParser.isIncomingStatWildcardMatch(persistedStatName, incomingStatName);
-
- AssertJUnit.assertFalse(match);
- }
-
- @Test
- public void testBadWildcardNotAtEnd() {
-
- String persistedStatName = "window(5)(dbFoo.*partition.latency)";
- String incomingStatName = "dbFoo.partition10.latency";
- boolean match =
- ExpressionParser.isIncomingStatWildcardMatch(persistedStatName, incomingStatName);
-
- AssertJUnit.assertFalse(match);
- }
-}
http://git-wip-us.apache.org/repos/asf/helix/blob/77cc6516/helix-core/src/test/java/org/apache/helix/controller/stages/DummyClusterManager.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/controller/stages/DummyClusterManager.java b/helix-core/src/test/java/org/apache/helix/controller/stages/DummyClusterManager.java
index fc9b7d5..73ba122 100644
--- a/helix-core/src/test/java/org/apache/helix/controller/stages/DummyClusterManager.java
+++ b/helix-core/src/test/java/org/apache/helix/controller/stages/DummyClusterManager.java
@@ -25,7 +25,6 @@ import org.apache.helix.ConfigChangeListener;
import org.apache.helix.ControllerChangeListener;
import org.apache.helix.CurrentStateChangeListener;
import org.apache.helix.ExternalViewChangeListener;
-import org.apache.helix.HealthStateChangeListener;
import org.apache.helix.HelixAdmin;
import org.apache.helix.HelixDataAccessor;
import org.apache.helix.HelixManager;
@@ -40,7 +39,6 @@ import org.apache.helix.PreConnectCallback;
import org.apache.helix.PropertyKey;
import org.apache.helix.ScopedConfigChangeListener;
import org.apache.helix.ZNRecord;
-import org.apache.helix.healthcheck.ParticipantHealthReportCollector;
import org.apache.helix.model.HelixConfigScope.ConfigScopeProperty;
import org.apache.helix.participant.StateMachineEngine;
import org.apache.helix.store.zk.ZkHelixPropertyStore;
@@ -158,12 +156,6 @@ public class DummyClusterManager implements HelixManager {
}
@Override
- public ParticipantHealthReportCollector getHealthReportCollector() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
public InstanceType getInstanceType() {
// TODO Auto-generated method stub
return null;
@@ -176,13 +168,6 @@ public class DummyClusterManager implements HelixManager {
}
@Override
- public void addHealthStateChangeListener(HealthStateChangeListener listener, String instanceName)
- throws Exception {
- // TODO Auto-generated method stub
-
- }
-
- @Override
public StateMachineEngine getStateMachineEngine() {
// TODO Auto-generated method stub
return null;
http://git-wip-us.apache.org/repos/asf/helix/blob/77cc6516/helix-core/src/test/java/org/apache/helix/controller/stages/TestParseInfoFromAlert.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/controller/stages/TestParseInfoFromAlert.java b/helix-core/src/test/java/org/apache/helix/controller/stages/TestParseInfoFromAlert.java
deleted file mode 100644
index eb2f6fe..0000000
--- a/helix-core/src/test/java/org/apache/helix/controller/stages/TestParseInfoFromAlert.java
+++ /dev/null
@@ -1,56 +0,0 @@
-package org.apache.helix.controller.stages;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-import org.apache.helix.HelixManager;
-import org.apache.helix.controller.stages.StatsAggregationStage;
-import org.apache.helix.integration.ZkStandAloneCMTestBase;
-import org.testng.Assert;
-import org.testng.annotations.Test;
-
-public class TestParseInfoFromAlert extends ZkStandAloneCMTestBase {
- @Test
- public void TestParse() {
- HelixManager manager = _controller;
-
- String instanceName =
- StatsAggregationStage.parseInstanceName("localhost_12918.TestStat@DB=123.latency", manager);
- Assert.assertTrue(instanceName.equals("localhost_12918"));
-
- instanceName =
- StatsAggregationStage.parseInstanceName("localhost_12955.TestStat@DB=123.latency", manager);
- Assert.assertTrue(instanceName == null);
-
- instanceName =
- StatsAggregationStage.parseInstanceName("localhost_12922.TestStat@DB=123.latency", manager);
- Assert.assertTrue(instanceName.equals("localhost_12922"));
-
- String resourceName =
- StatsAggregationStage.parseResourceName("localhost_12918.TestStat@DB=TestDB.latency",
- manager);
- Assert.assertTrue(resourceName.equals("TestDB"));
-
- String partitionName =
- StatsAggregationStage.parsePartitionName(
- "localhost_12918.TestStat@DB=TestDB;Partition=TestDB_22.latency",
- manager);
- Assert.assertTrue(partitionName.equals("TestDB_22"));
- }
-}
http://git-wip-us.apache.org/repos/asf/helix/blob/77cc6516/helix-core/src/test/java/org/apache/helix/healthcheck/TestAddDropAlert.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/healthcheck/TestAddDropAlert.java b/helix-core/src/test/java/org/apache/helix/healthcheck/TestAddDropAlert.java
deleted file mode 100644
index 8e0b04f..0000000
--- a/helix-core/src/test/java/org/apache/helix/healthcheck/TestAddDropAlert.java
+++ /dev/null
@@ -1,171 +0,0 @@
-package org.apache.helix.healthcheck;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-import java.util.Date;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.helix.HelixDataAccessor;
-import org.apache.helix.HelixManager;
-import org.apache.helix.NotificationContext;
-import org.apache.helix.TestHelper;
-import org.apache.helix.ZNRecord;
-import org.apache.helix.PropertyKey.Builder;
-import org.apache.helix.healthcheck.ParticipantHealthReportCollectorImpl;
-import org.apache.helix.integration.ZkIntegrationTestBase;
-import org.apache.helix.integration.manager.ClusterControllerManager;
-import org.apache.helix.integration.manager.MockParticipantManager;
-import org.apache.helix.manager.zk.ZKHelixDataAccessor;
-import org.apache.helix.manager.zk.ZkBaseDataAccessor;
-import org.apache.helix.mock.participant.MockEspressoHealthReportProvider;
-import org.apache.helix.mock.participant.MockTransition;
-import org.apache.helix.model.Message;
-import org.apache.helix.tools.ClusterSetup;
-import org.apache.helix.tools.ClusterStateVerifier;
-import org.testng.Assert;
-import org.testng.annotations.AfterClass;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Test;
-
-public class TestAddDropAlert extends ZkIntegrationTestBase {
- protected ClusterSetup _setupTool = null;
- protected final String _alertStr =
- "EXP(accumulate()(localhost_12918.RestQueryStats@DBName=TestDB0.latency))CMP(GREATER)CON(10)";
- protected final String _alertStatusStr = _alertStr; // +" : (*)";
- protected final String _dbName = "TestDB0";
-
- @BeforeClass()
- public void beforeClass() throws Exception {
- _setupTool = new ClusterSetup(_gZkClient);
- }
-
- @AfterClass
- public void afterClass() {
- }
-
- public class AddDropAlertTransition extends MockTransition {
- @Override
- public void doTransition(Message message, NotificationContext context) {
- HelixManager manager = context.getManager();
- HelixDataAccessor accessor = manager.getHelixDataAccessor();
- String fromState = message.getFromState();
- String toState = message.getToState();
- String instance = message.getTgtName();
- String partition = message.getPartitionName();
-
- if (fromState.equalsIgnoreCase("SLAVE") && toState.equalsIgnoreCase("MASTER")) {
-
- // add a stat and report to ZK
- // perhaps should keep reporter per instance...
- ParticipantHealthReportCollectorImpl reporter =
- new ParticipantHealthReportCollectorImpl(manager, instance);
- MockEspressoHealthReportProvider provider = new MockEspressoHealthReportProvider();
- reporter.addHealthReportProvider(provider);
- String statName = "latency";
- provider.setStat(_dbName, statName, "15");
- reporter.transmitHealthReports();
-
- // sleep long enough for first set of alerts to report and alert to get deleted
- // then change reported data
- try {
- Thread.sleep(10000);
- } catch (InterruptedException e) {
- System.err.println("Error sleeping");
- }
- provider.setStat(_dbName, statName, "1");
- reporter.transmitHealthReports();
-
- /*
- * for (int i = 0; i < 5; i++) { accessor.setProperty(PropertyType.HEALTHREPORT,
- * new ZNRecord("mockAlerts" + i), instance, "mockAlerts"); try {
- * Thread.sleep(1000); } catch (InterruptedException e) { // TODO Auto-generated
- * catch block e.printStackTrace(); } }
- */
- }
- }
- }
-
- @Test()
- public void testAddDropAlert() throws Exception {
- String clusterName = getShortClassName();
- MockParticipantManager[] participants = new MockParticipantManager[5];
-
- System.out.println("START TestAddDropAlert at " + new Date(System.currentTimeMillis()));
-
- TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, // participant start port
- "localhost", // participant name prefix
- "TestDB", // resource name prefix
- 1, // resources
- 10, // partitions per resource group
- 5, // number of nodes //change back to 5!!!
- 1, // replicas //change back to 3!!!
- "MasterSlave", true); // do rebalance
- // enableHealthCheck(clusterName);
-
- _setupTool.getClusterManagementTool().addAlert(clusterName, _alertStr);
-
- ClusterControllerManager controller =
- new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
- controller.syncStart();
-
- // start participants
- for (int i = 0; i < 5; i++) // !!!change back to 5
- {
- String instanceName = "localhost_" + (12918 + i);
-
- participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
- participants[i].setTransition(new AddDropAlertTransition());
- participants[i].syncStart();
- }
-
- boolean result =
- ClusterStateVerifier.verifyByPolling(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(
- ZK_ADDR, clusterName));
- Assert.assertTrue(result);
-
- // drop alert soon after adding, but leave enough time for alert to fire once
- // Thread.sleep(3000);
- ZKHelixDataAccessor accessor =
- new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
- Builder keyBuilder = accessor.keyBuilder();
-
- new HealthStatsAggregator(controller).aggregate();
- String instance = "localhost_12918";
- ZNRecord record = accessor.getProperty(keyBuilder.alertStatus()).getRecord();
- Map<String, Map<String, String>> recMap = record.getMapFields();
- Set<String> keySet = recMap.keySet();
- Assert.assertTrue(keySet.size() > 0);
-
- _setupTool.getClusterManagementTool().dropAlert(clusterName, _alertStr);
- new HealthStatsAggregator(controller).aggregate();
- // other verifications go here
- // for (int i = 0; i < 1; i++) //change 1 back to 5
- // {
- // String instance = "localhost_" + (12918 + i);
- record = accessor.getProperty(keyBuilder.alertStatus()).getRecord();
- recMap = record.getMapFields();
- keySet = recMap.keySet();
- Assert.assertEquals(keySet.size(), 0);
- // }
-
- System.out.println("END TestAddDropAlert at " + new Date(System.currentTimeMillis()));
- }
-}
http://git-wip-us.apache.org/repos/asf/helix/blob/77cc6516/helix-core/src/test/java/org/apache/helix/healthcheck/TestAlertActionTriggering.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/healthcheck/TestAlertActionTriggering.java b/helix-core/src/test/java/org/apache/helix/healthcheck/TestAlertActionTriggering.java
deleted file mode 100644
index b00e26c..0000000
--- a/helix-core/src/test/java/org/apache/helix/healthcheck/TestAlertActionTriggering.java
+++ /dev/null
@@ -1,226 +0,0 @@
-package org.apache.helix.healthcheck;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.helix.ConfigAccessor;
-import org.apache.helix.model.ConfigScope;
-import org.apache.helix.model.builder.ConfigScopeBuilder;
-import org.apache.helix.model.builder.HelixConfigScopeBuilder;
-import org.apache.helix.HelixDataAccessor;
-import org.apache.helix.HelixManager;
-import org.apache.helix.ZNRecord;
-import org.apache.helix.PropertyKey.Builder;
-import org.apache.helix.integration.ZkStandAloneCMTestBaseWithPropertyServerCheck;
-import org.apache.helix.model.ExternalView;
-import org.apache.helix.model.HealthStat;
-import org.apache.helix.model.HelixConfigScope;
-import org.apache.helix.model.HelixConfigScope.ConfigScopeProperty;
-import org.apache.helix.model.InstanceConfig;
-import org.apache.helix.model.InstanceConfig.InstanceConfigProperty;
-import org.apache.helix.tools.ClusterStateVerifier;
-import org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier;
-import org.apache.log4j.Logger;
-import org.testng.Assert;
-import org.testng.annotations.Test;
-
-public class TestAlertActionTriggering extends ZkStandAloneCMTestBaseWithPropertyServerCheck {
- private static Logger LOG = Logger.getLogger(TestAlertActionTriggering.class);
-
- String _statName = "TestStat@DB=db1";
- String _stat = "TestStat";
- String metricName1 = "TestMetric1";
- String metricName2 = "TestMetric2";
-
- void setHealthData(int[] val1, int[] val2) {
- for (int i = 0; i < NODE_NR; i++) {
- HelixManager manager = _participants[i];
- ZNRecord record = new ZNRecord(_stat);
- Map<String, String> valMap = new HashMap<String, String>();
- valMap.put(metricName1, val1[i] + "");
- valMap.put(metricName2, val2[i] + "");
- record.setSimpleField("TimeStamp", new Date().getTime() + "");
- record.setMapField(_statName, valMap);
- HelixDataAccessor helixDataAccessor = manager.getHelixDataAccessor();
- Builder keyBuilder = helixDataAccessor.keyBuilder();
- helixDataAccessor.setProperty(
- keyBuilder.healthReport(manager.getInstanceName(), record.getId()),
- new HealthStat(record));
- }
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- LOG.error("sleep interrupted", e);
- }
- }
-
- void setHealthData2(int[] val1) {
- for (int i = 0; i < NODE_NR; i++) {
- HelixManager manager = _participants[i];
- ZNRecord record = new ZNRecord(_stat);
- Map<String, String> valMap = new HashMap<String, String>();
- valMap.put(metricName2, val1[i] + "");
- record.setSimpleField("TimeStamp", new Date().getTime() + "");
- record.setMapField("TestStat@DB=TestDB;Partition=TestDB_3", valMap);
- HelixDataAccessor helixDataAccessor = manager.getHelixDataAccessor();
- Builder keyBuilder = helixDataAccessor.keyBuilder();
- helixDataAccessor.setProperty(
- keyBuilder.healthReport(manager.getInstanceName(), record.getId()),
- new HealthStat(record));
- }
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- LOG.error("sleep interrupted", e);
- }
- }
-
- @Test
- public void testAlertActionDisableNode() throws InterruptedException {
- // ConfigScope scope = new ConfigScopeBuilder().forCluster(CLUSTER_NAME).build();
- HelixConfigScope scope =
- new HelixConfigScopeBuilder(ConfigScopeProperty.CLUSTER).forCluster(CLUSTER_NAME).build();
- Map<String, String> properties = new HashMap<String, String>();
- properties.put("healthChange.enabled", "true");
- _setupTool.getClusterManagementTool().setConfig(scope, properties);
-
- String alertStr1 =
- "EXP(decay(1.0)(localhost_*.TestStat@DB=db1.TestMetric1))CMP(GREATER)CON(20)ACTION(DISABLE_INSTANCE)";
- String alertStr2 =
- "EXP(decay(1.0)(localhost_*.TestStat@DB=db1.TestMetric2))CMP(GREATER)CON(120)ACTION(DISABLE_INSTANCE)";
- String alertStr3 =
- "EXP(decay(1.0)(localhost_*.TestStat@DB=TestDB;Partition=*.TestMetric2))CMP(GREATER)CON(160)ACTION(DISABLE_PARTITION)";
-
- _setupTool.getClusterManagementTool().addAlert(CLUSTER_NAME, alertStr1);
- _setupTool.getClusterManagementTool().addAlert(CLUSTER_NAME, alertStr2);
- _setupTool.getClusterManagementTool().addAlert(CLUSTER_NAME, alertStr3);
-
- int[] metrics1 = {
- 10, 15, 22, 12, 16
- };
- int[] metrics2 = {
- 22, 115, 22, 163, 16
- };
- int[] metrics3 = {
- 0, 0, 0, 0, 0
- };
- setHealthData(metrics1, metrics2);
-
- HelixManager manager = _controller;
-
- HealthStatsAggregator task = new HealthStatsAggregator(manager);
- task.aggregate();
- Thread.sleep(4000);
- HelixDataAccessor helixDataAccessor = manager.getHelixDataAccessor();
- Builder keyBuilder = helixDataAccessor.keyBuilder();
-
- boolean result =
- ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR,
- CLUSTER_NAME));
- Assert.assertTrue(result);
-
- Builder kb = manager.getHelixDataAccessor().keyBuilder();
- ExternalView externalView =
- manager.getHelixDataAccessor().getProperty(kb.externalView("TestDB"));
- // Test the DISABLE_INSTANCE alerts
- String participant1 = "localhost_" + (START_PORT + 3);
- String participant2 = "localhost_" + (START_PORT + 2);
- ConfigAccessor configAccessor = manager.getConfigAccessor();
- // scope = new
- // ConfigScopeBuilder().forCluster(manager.getClusterName()).forParticipant(participant1).build();
- scope =
- new HelixConfigScopeBuilder(ConfigScopeProperty.PARTICIPANT)
- .forCluster(manager.getClusterName()).forParticipant(participant1).build();
- String isEnabled = configAccessor.get(scope, "HELIX_ENABLED");
- Assert.assertFalse(Boolean.parseBoolean(isEnabled));
-
- // scope = new
- // ConfigScopeBuilder().forCluster(manager.getClusterName()).forParticipant(participant2).build();
- scope =
- new HelixConfigScopeBuilder(ConfigScopeProperty.PARTICIPANT)
- .forCluster(manager.getClusterName()).forParticipant(participant2).build();
- isEnabled = configAccessor.get(scope, "HELIX_ENABLED");
- Assert.assertFalse(Boolean.parseBoolean(isEnabled));
-
- for (String partitionName : externalView.getRecord().getMapFields().keySet()) {
- for (String hostName : externalView.getRecord().getMapField(partitionName).keySet()) {
- if (hostName.equals(participant1) || hostName.equals(participant2)) {
- Assert.assertEquals(externalView.getRecord().getMapField(partitionName).get(hostName),
- "OFFLINE");
- }
- }
- }
-
- // enable the disabled instances
- setHealthData(metrics3, metrics3);
- task.aggregate();
- Thread.sleep(1000);
-
- manager.getClusterManagmentTool().enableInstance(manager.getClusterName(), participant2, true);
- manager.getClusterManagmentTool().enableInstance(manager.getClusterName(), participant1, true);
-
- result =
- ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR,
- CLUSTER_NAME));
- Assert.assertTrue(result);
-
- // Test the DISABLE_PARTITION case
- int[] metrics4 = {
- 22, 115, 22, 16, 163
- };
- setHealthData2(metrics4);
- task.aggregate();
-
- // scope = new
- // ConfigScopeBuilder().forCluster(manager.getClusterName()).forParticipant(participant1).build();
- scope =
- new HelixConfigScopeBuilder(ConfigScopeProperty.PARTICIPANT)
- .forCluster(manager.getClusterName()).forParticipant(participant1).build();
- isEnabled = configAccessor.get(scope, "HELIX_ENABLED");
- Assert.assertTrue(Boolean.parseBoolean(isEnabled));
-
- // scope = new
- // ConfigScopeBuilder().forCluster(manager.getClusterName()).forParticipant(participant2).build();
- scope =
- new HelixConfigScopeBuilder(ConfigScopeProperty.PARTICIPANT)
- .forCluster(manager.getClusterName()).forParticipant(participant2).build();
- isEnabled = configAccessor.get(scope, "HELIX_ENABLED");
- Assert.assertTrue(Boolean.parseBoolean(isEnabled));
-
- result =
- ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR,
- CLUSTER_NAME));
- Assert.assertTrue(result);
- String participant3 = "localhost_" + (START_PORT + 4);
- externalView = manager.getHelixDataAccessor().getProperty(kb.externalView("TestDB"));
- Assert.assertTrue(externalView.getRecord().getMapField("TestDB_3").get(participant3)
- .equalsIgnoreCase("OFFLINE"));
-
- InstanceConfig nodeConfig =
- helixDataAccessor.getProperty(keyBuilder.instanceConfig(participant3));
- Assert.assertTrue(nodeConfig.getRecord()
- .getListField(InstanceConfigProperty.HELIX_DISABLED_PARTITION.toString())
- .contains("TestDB_3"));
-
- }
-}
http://git-wip-us.apache.org/repos/asf/helix/blob/77cc6516/helix-core/src/test/java/org/apache/helix/healthcheck/TestAlertFireHistory.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/healthcheck/TestAlertFireHistory.java b/helix-core/src/test/java/org/apache/helix/healthcheck/TestAlertFireHistory.java
deleted file mode 100644
index c18b643..0000000
--- a/helix-core/src/test/java/org/apache/helix/healthcheck/TestAlertFireHistory.java
+++ /dev/null
@@ -1,426 +0,0 @@
-package org.apache.helix.healthcheck;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.TreeMap;
-
-import org.apache.helix.model.ConfigScope;
-import org.apache.helix.model.HelixConfigScope.ConfigScopeProperty;
-import org.apache.helix.model.builder.ConfigScopeBuilder;
-import org.apache.helix.model.builder.HelixConfigScopeBuilder;
-import org.apache.helix.HelixDataAccessor;
-import org.apache.helix.HelixManager;
-import org.apache.helix.HelixProperty;
-import org.apache.helix.HelixTimerTask;
-import org.apache.helix.TestHelper;
-import org.apache.helix.ZNRecord;
-import org.apache.helix.PropertyKey.Builder;
-import org.apache.helix.integration.ZkStandAloneCMTestBaseWithPropertyServerCheck;
-import org.apache.helix.model.AlertHistory;
-import org.apache.helix.model.HealthStat;
-import org.apache.helix.model.HelixConfigScope;
-import org.apache.log4j.Logger;
-import org.testng.Assert;
-import org.testng.annotations.Test;
-
-/**
- * setup a storage cluster and start a zk-based cluster controller in stand-alone mode
- * start 5 dummy participants verify the current states at end
- */
-
-public class TestAlertFireHistory extends ZkStandAloneCMTestBaseWithPropertyServerCheck {
- private final static Logger LOG = Logger.getLogger(TestAlertFireHistory.class);
-
- String _statName = "TestStat@DB=db1";
- String _stat = "TestStat";
- String metricName1 = "TestMetric1";
- String metricName2 = "TestMetric2";
-
- String _alertStr1 = "EXP(decay(1.0)(localhost_*.TestStat@DB=db1.TestMetric1))CMP(GREATER)CON(20)";
- String _alertStr2 =
- "EXP(decay(1.0)(localhost_*.TestStat@DB=db1.TestMetric2))CMP(GREATER)CON(100)";
-
- void setHealthData(int[] val1, int[] val2) {
- for (int i = 0; i < NODE_NR; i++) {
- HelixManager manager = _participants[i];
- ZNRecord record = new ZNRecord(_stat);
- Map<String, String> valMap = new HashMap<String, String>();
- valMap.put(metricName1, val1[i] + "");
- valMap.put(metricName2, val2[i] + "");
- record.setSimpleField("TimeStamp", new Date().getTime() + "");
- record.setMapField(_statName, valMap);
- HelixDataAccessor helixDataAccessor = manager.getHelixDataAccessor();
- Builder keyBuilder = helixDataAccessor.keyBuilder();
- helixDataAccessor.setProperty(
- keyBuilder.healthReport(manager.getInstanceName(), record.getId()),
- new HealthStat(record));
- }
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- LOG.error("Interrupted sleep", e);
- }
- }
-
- @Test
- public void testAlertDisable() throws InterruptedException {
-
- int[] metrics1 = {
- 10, 15, 22, 24, 16
- };
- int[] metrics2 = {
- 22, 115, 22, 141, 16
- };
- setHealthData(metrics1, metrics2);
-
- HelixManager manager = _controller;
- manager.startTimerTasks();
-
- _setupTool.getClusterManagementTool().addAlert(CLUSTER_NAME, _alertStr1);
- _setupTool.getClusterManagementTool().addAlert(CLUSTER_NAME, _alertStr2);
-
- HelixConfigScope scope =
- new HelixConfigScopeBuilder(ConfigScopeProperty.CLUSTER).forCluster(CLUSTER_NAME).build();
- Map<String, String> properties = new HashMap<String, String>();
- properties.put("healthChange.enabled", "false");
- _setupTool.getClusterManagementTool().setConfig(scope, properties);
-
- HealthStatsAggregator task = new HealthStatsAggregator(_controller);
-
- task.aggregate();
- Thread.sleep(100);
- HelixDataAccessor helixDataAccessor = manager.getHelixDataAccessor();
- Builder keyBuilder = helixDataAccessor.keyBuilder();
-
- AlertHistory history = manager.getHelixDataAccessor().getProperty(keyBuilder.alertHistory());
-
- Assert.assertEquals(history, null);
-
- properties.put("healthChange.enabled", "true");
- _setupTool.getClusterManagementTool().setConfig(scope, properties);
-
- task.aggregate();
- Thread.sleep(100);
-
- history = manager.getHelixDataAccessor().getProperty(keyBuilder.alertHistory());
- //
- Assert.assertNotNull(history);
- Assert.assertEquals(history.getRecord().getMapFields().size(), 1);
- }
-
- @Test
- public void testAlertHistory() throws InterruptedException {
- int[] metrics1 = {
- 10, 15, 22, 24, 16
- };
- int[] metrics2 = {
- 22, 115, 22, 141, 16
- };
- setHealthData(metrics1, metrics2);
-
- HelixManager manager = _controller;
- for (HelixTimerTask task : _controller.getControllerTimerTasks()) {
- task.stop();
- }
-
- _setupTool.getClusterManagementTool().addAlert(CLUSTER_NAME, _alertStr1);
- _setupTool.getClusterManagementTool().addAlert(CLUSTER_NAME, _alertStr2);
-
- int historySize = 0;
- HelixDataAccessor helixDataAccessor = manager.getHelixDataAccessor();
- Builder keyBuilder = helixDataAccessor.keyBuilder();
- HelixProperty property = helixDataAccessor.getProperty(keyBuilder.alertHistory());
- ZNRecord history = null;
- if (property != null) {
- history = property.getRecord();
- historySize = property.getRecord().getMapFields().size();
- }
-
- HealthStatsAggregator task = new HealthStatsAggregator(_controller);
-
- task.aggregate();
- Thread.sleep(100);
-
- history = helixDataAccessor.getProperty(keyBuilder.alertHistory()).getRecord();
- //
- Assert.assertEquals(history.getMapFields().size(), 1 + historySize);
- TreeMap<String, Map<String, String>> recordMap = new TreeMap<String, Map<String, String>>();
- recordMap.putAll(history.getMapFields());
- Map<String, String> lastRecord = recordMap.firstEntry().getValue();
- Assert.assertTrue(lastRecord.size() == 4);
- Assert.assertTrue(lastRecord.get("(localhost_12920.TestStat@DB#db1.TestMetric1)GREATER(20)")
- .equals("ON"));
- Assert.assertTrue(lastRecord.get("(localhost_12919.TestStat@DB#db1.TestMetric2)GREATER(100)")
- .equals("ON"));
- Assert.assertTrue(lastRecord.get("(localhost_12921.TestStat@DB#db1.TestMetric1)GREATER(20)")
- .equals("ON"));
- Assert.assertTrue(lastRecord.get("(localhost_12921.TestStat@DB#db1.TestMetric2)GREATER(100)")
- .equals("ON"));
-
- setHealthData(metrics1, metrics2);
- task.aggregate();
- Thread.sleep(100);
- history = helixDataAccessor.getProperty(keyBuilder.alertHistory()).getRecord();
- // no change
- Assert.assertEquals(history.getMapFields().size(), 1 + historySize);
- recordMap = new TreeMap<String, Map<String, String>>();
- recordMap.putAll(history.getMapFields());
- lastRecord = recordMap.firstEntry().getValue();
- Assert.assertTrue(lastRecord.size() == 4);
- Assert.assertTrue(lastRecord.get("(localhost_12920.TestStat@DB#db1.TestMetric1)GREATER(20)")
- .equals("ON"));
- Assert.assertTrue(lastRecord.get("(localhost_12919.TestStat@DB#db1.TestMetric2)GREATER(100)")
- .equals("ON"));
- Assert.assertTrue(lastRecord.get("(localhost_12921.TestStat@DB#db1.TestMetric1)GREATER(20)")
- .equals("ON"));
- Assert.assertTrue(lastRecord.get("(localhost_12921.TestStat@DB#db1.TestMetric2)GREATER(100)")
- .equals("ON"));
-
- int[] metrics3 = {
- 21, 44, 22, 14, 16
- };
- int[] metrics4 = {
- 122, 115, 222, 41, 16
- };
- setHealthData(metrics3, metrics4);
- task.aggregate();
- Thread.sleep(100);
- history = helixDataAccessor.getProperty(keyBuilder.alertHistory()).getRecord();
- // new delta should be recorded
- Assert.assertEquals(history.getMapFields().size(), 2 + historySize);
- recordMap = new TreeMap<String, Map<String, String>>();
- recordMap.putAll(history.getMapFields());
- lastRecord = recordMap.lastEntry().getValue();
- Assert.assertEquals(lastRecord.size(), 6);
- Assert.assertTrue(lastRecord.get("(localhost_12918.TestStat@DB#db1.TestMetric1)GREATER(20)")
- .equals("ON"));
- Assert.assertTrue(lastRecord.get("(localhost_12921.TestStat@DB#db1.TestMetric1)GREATER(20)")
- .equals("OFF"));
- Assert.assertTrue(lastRecord.get("(localhost_12920.TestStat@DB#db1.TestMetric2)GREATER(100)")
- .equals("ON"));
- Assert.assertTrue(lastRecord.get("(localhost_12921.TestStat@DB#db1.TestMetric2)GREATER(100)")
- .equals("OFF"));
- Assert.assertTrue(lastRecord.get("(localhost_12918.TestStat@DB#db1.TestMetric2)GREATER(100)")
- .equals("ON"));
- Assert.assertTrue(lastRecord.get("(localhost_12919.TestStat@DB#db1.TestMetric1)GREATER(20)")
- .equals("ON"));
-
- int[] metrics5 = {
- 0, 0, 0, 0, 0
- };
- int[] metrics6 = {
- 0, 0, 0, 0, 0
- };
- setHealthData(metrics5, metrics6);
- task.aggregate();
-
- for (int i = 0; i < 10; i++) {
- Thread.sleep(500);
- history = helixDataAccessor.getProperty(keyBuilder.alertHistory()).getRecord();
- recordMap = new TreeMap<String, Map<String, String>>();
- recordMap.putAll(history.getMapFields());
- lastRecord = recordMap.lastEntry().getValue();
-
- if (history.getMapFields().size() == 3 + historySize && lastRecord.size() == 6) {
- break;
- }
- }
-
- // reset everything
- Assert.assertEquals(history.getMapFields().size(), 3 + historySize,
- "expect history-map-field size is " + (3 + historySize) + ", but was " + history);
- Assert
- .assertTrue(lastRecord.size() == 6, "expect last-record size is 6, but was " + lastRecord);
-
- Assert.assertTrue(lastRecord.get("(localhost_12918.TestStat@DB#db1.TestMetric1)GREATER(20)")
- .equals("OFF"));
- Assert.assertTrue(lastRecord.get("(localhost_12920.TestStat@DB#db1.TestMetric1)GREATER(20)")
- .equals("OFF"));
- Assert.assertTrue(lastRecord.get("(localhost_12920.TestStat@DB#db1.TestMetric2)GREATER(100)")
- .equals("OFF"));
- Assert.assertTrue(lastRecord.get("(localhost_12919.TestStat@DB#db1.TestMetric2)GREATER(100)")
- .equals("OFF"));
- Assert.assertTrue(lastRecord.get("(localhost_12918.TestStat@DB#db1.TestMetric2)GREATER(100)")
- .equals("OFF"));
- Assert.assertTrue(lastRecord.get("(localhost_12919.TestStat@DB#db1.TestMetric1)GREATER(20)")
- .equals("OFF"));
-
- // Size of the history should be 30
- for (int i = 0; i < 27; i++) {
- int x = i % 2;
- int y = (i + 1) % 2;
- int[] metricsx = {
- 19 + 3 * x, 19 + 3 * y, 19 + 4 * x, 18 + 4 * y, 17 + 5 * y
- };
- int[] metricsy = {
- 99 + 3 * x, 99 + 3 * y, 98 + 4 * x, 98 + 4 * y, 97 + 5 * y
- };
-
- setHealthData(metricsx, metricsy);
- task.aggregate();
- Thread.sleep(100);
- history = helixDataAccessor.getProperty(keyBuilder.alertHistory()).getRecord();
-
- Assert.assertEquals(history.getMapFields().size(), Math.min(3 + i + 1 + historySize, 30));
- recordMap = new TreeMap<String, Map<String, String>>();
- recordMap.putAll(history.getMapFields());
- lastRecord = recordMap.lastEntry().getValue();
- if (i == 0) {
- Assert.assertTrue(lastRecord.size() == 6);
- Assert.assertTrue(lastRecord
- .get("(localhost_12922.TestStat@DB#db1.TestMetric1)GREATER(20)").equals("ON"));
- Assert.assertTrue(lastRecord.get(
- "(localhost_12922.TestStat@DB#db1.TestMetric2)GREATER(100)").equals("ON"));
- Assert.assertTrue(lastRecord.get(
- "(localhost_12919.TestStat@DB#db1.TestMetric2)GREATER(100)").equals("ON"));
- Assert.assertTrue(lastRecord
- .get("(localhost_12921.TestStat@DB#db1.TestMetric1)GREATER(20)").equals("ON"));
- Assert.assertTrue(lastRecord.get(
- "(localhost_12921.TestStat@DB#db1.TestMetric2)GREATER(100)").equals("ON"));
- Assert.assertTrue(lastRecord
- .get("(localhost_12919.TestStat@DB#db1.TestMetric1)GREATER(20)").equals("ON"));
- } else {
- System.out.println(lastRecord.size());
- Assert.assertEquals(lastRecord.size(), 10);
- if (x == 0) {
- Assert.assertTrue(lastRecord.get(
- "(localhost_12922.TestStat@DB#db1.TestMetric2)GREATER(100)").equals("ON"));
- Assert.assertTrue(lastRecord.get(
- "(localhost_12922.TestStat@DB#db1.TestMetric1)GREATER(20)").equals("ON"));
- Assert.assertTrue(lastRecord.get(
- "(localhost_12920.TestStat@DB#db1.TestMetric1)GREATER(20)").equals("OFF"));
- Assert.assertTrue(lastRecord.get(
- "(localhost_12918.TestStat@DB#db1.TestMetric1)GREATER(20)").equals("OFF"));
- Assert.assertTrue(lastRecord.get(
- "(localhost_12919.TestStat@DB#db1.TestMetric2)GREATER(100)").equals("ON"));
- Assert.assertTrue(lastRecord.get(
- "(localhost_12921.TestStat@DB#db1.TestMetric1)GREATER(20)").equals("ON"));
- Assert.assertTrue(lastRecord.get(
- "(localhost_12920.TestStat@DB#db1.TestMetric2)GREATER(100)").equals("OFF"));
- Assert.assertTrue(lastRecord.get(
- "(localhost_12921.TestStat@DB#db1.TestMetric2)GREATER(100)").equals("ON"));
- Assert.assertTrue(lastRecord.get(
- "(localhost_12918.TestStat@DB#db1.TestMetric2)GREATER(100)").equals("OFF"));
- Assert.assertTrue(lastRecord.get(
- "(localhost_12919.TestStat@DB#db1.TestMetric1)GREATER(20)").equals("ON"));
- } else {
- Assert.assertTrue(lastRecord.get(
- "(localhost_12922.TestStat@DB#db1.TestMetric2)GREATER(100)").equals("OFF"));
- Assert.assertTrue(lastRecord.get(
- "(localhost_12922.TestStat@DB#db1.TestMetric1)GREATER(20)").equals("OFF"));
- Assert.assertTrue(lastRecord.get(
- "(localhost_12920.TestStat@DB#db1.TestMetric1)GREATER(20)").equals("ON"));
- Assert.assertTrue(lastRecord.get(
- "(localhost_12918.TestStat@DB#db1.TestMetric1)GREATER(20)").equals("ON"));
- Assert.assertTrue(lastRecord.get(
- "(localhost_12919.TestStat@DB#db1.TestMetric2)GREATER(100)").equals("OFF"));
- Assert.assertTrue(lastRecord.get(
- "(localhost_12921.TestStat@DB#db1.TestMetric1)GREATER(20)").equals("OFF"));
- Assert.assertTrue(lastRecord.get(
- "(localhost_12920.TestStat@DB#db1.TestMetric2)GREATER(100)").equals("ON"));
- Assert.assertTrue(lastRecord.get(
- "(localhost_12921.TestStat@DB#db1.TestMetric2)GREATER(100)").equals("OFF"));
- Assert.assertTrue(lastRecord.get(
- "(localhost_12918.TestStat@DB#db1.TestMetric2)GREATER(100)").equals("ON"));
- Assert.assertTrue(lastRecord.get(
- "(localhost_12919.TestStat@DB#db1.TestMetric1)GREATER(20)").equals("OFF"));
- }
- }
- }
- // size limit is 30
- for (int i = 0; i < 10; i++) {
- int x = i % 2;
- int y = (i + 1) % 2;
- int[] metricsx = {
- 19 + 3 * x, 19 + 3 * y, 19 + 4 * x, 18 + 4 * y, 17 + 5 * y
- };
- int[] metricsy = {
- 99 + 3 * x, 99 + 3 * y, 98 + 4 * x, 98 + 4 * y, 97 + 5 * y
- };
-
- setHealthData(metricsx, metricsy);
- task.aggregate();
- for (int j = 0; j < 10; j++) {
- Thread.sleep(100);
- history = helixDataAccessor.getProperty(keyBuilder.alertHistory()).getRecord();
- recordMap = new TreeMap<String, Map<String, String>>();
- recordMap.putAll(history.getMapFields());
- lastRecord = recordMap.lastEntry().getValue();
-
- if (history.getMapFields().size() == 30 && lastRecord.size() == 10)
- break;
- }
- Assert.assertEquals(history.getMapFields().size(), 30,
- "expect history.map-field size is 30, but was " + history);
- Assert.assertEquals(lastRecord.size(), 10, "expect last-record size is 10, but was "
- + lastRecord);
-
- if (x == 0) {
- Assert.assertTrue(lastRecord.get(
- "(localhost_12922.TestStat@DB#db1.TestMetric2)GREATER(100)").equals("ON"));
- Assert.assertTrue(lastRecord
- .get("(localhost_12922.TestStat@DB#db1.TestMetric1)GREATER(20)").equals("ON"));
- Assert.assertTrue(lastRecord
- .get("(localhost_12920.TestStat@DB#db1.TestMetric1)GREATER(20)").equals("OFF"));
- Assert.assertTrue(lastRecord
- .get("(localhost_12918.TestStat@DB#db1.TestMetric1)GREATER(20)").equals("OFF"));
- Assert.assertTrue(lastRecord.get(
- "(localhost_12919.TestStat@DB#db1.TestMetric2)GREATER(100)").equals("ON"));
- Assert.assertTrue(lastRecord
- .get("(localhost_12921.TestStat@DB#db1.TestMetric1)GREATER(20)").equals("ON"));
- Assert.assertTrue(lastRecord.get(
- "(localhost_12920.TestStat@DB#db1.TestMetric2)GREATER(100)").equals("OFF"));
- Assert.assertTrue(lastRecord.get(
- "(localhost_12921.TestStat@DB#db1.TestMetric2)GREATER(100)").equals("ON"));
- Assert.assertTrue(lastRecord.get(
- "(localhost_12918.TestStat@DB#db1.TestMetric2)GREATER(100)").equals("OFF"));
- Assert.assertTrue(lastRecord
- .get("(localhost_12919.TestStat@DB#db1.TestMetric1)GREATER(20)").equals("ON"));
- } else {
- Assert.assertTrue(lastRecord.get(
- "(localhost_12922.TestStat@DB#db1.TestMetric2)GREATER(100)").equals("OFF"));
- Assert.assertTrue(lastRecord
- .get("(localhost_12922.TestStat@DB#db1.TestMetric1)GREATER(20)").equals("OFF"));
- Assert.assertTrue(lastRecord
- .get("(localhost_12920.TestStat@DB#db1.TestMetric1)GREATER(20)").equals("ON"));
- Assert.assertTrue(lastRecord
- .get("(localhost_12918.TestStat@DB#db1.TestMetric1)GREATER(20)").equals("ON"));
- Assert.assertTrue(lastRecord.get(
- "(localhost_12919.TestStat@DB#db1.TestMetric2)GREATER(100)").equals("OFF"));
- Assert.assertTrue(lastRecord
- .get("(localhost_12921.TestStat@DB#db1.TestMetric1)GREATER(20)").equals("OFF"));
- Assert.assertTrue(lastRecord.get(
- "(localhost_12920.TestStat@DB#db1.TestMetric2)GREATER(100)").equals("ON"));
- Assert.assertTrue(lastRecord.get(
- "(localhost_12921.TestStat@DB#db1.TestMetric2)GREATER(100)").equals("OFF"));
- Assert.assertTrue(lastRecord.get(
- "(localhost_12918.TestStat@DB#db1.TestMetric2)GREATER(100)").equals("ON"));
- Assert.assertTrue(lastRecord
- .get("(localhost_12919.TestStat@DB#db1.TestMetric1)GREATER(20)").equals("OFF"));
- }
- }
-
- }
-
-}
-
http://git-wip-us.apache.org/repos/asf/helix/blob/77cc6516/helix-core/src/test/java/org/apache/helix/healthcheck/TestDummyAlerts.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/healthcheck/TestDummyAlerts.java b/helix-core/src/test/java/org/apache/helix/healthcheck/TestDummyAlerts.java
deleted file mode 100644
index b8bd634..0000000
--- a/helix-core/src/test/java/org/apache/helix/healthcheck/TestDummyAlerts.java
+++ /dev/null
@@ -1,148 +0,0 @@
-package org.apache.helix.healthcheck;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-import java.util.Date;
-import java.util.concurrent.atomic.AtomicBoolean;
-
-import org.apache.helix.HelixDataAccessor;
-import org.apache.helix.HelixManager;
-import org.apache.helix.NotificationContext;
-import org.apache.helix.TestHelper;
-import org.apache.helix.ZNRecord;
-import org.apache.helix.PropertyKey.Builder;
-import org.apache.helix.integration.ZkIntegrationTestBase;
-import org.apache.helix.integration.manager.ClusterControllerManager;
-import org.apache.helix.integration.manager.MockParticipantManager;
-import org.apache.helix.manager.zk.ZKHelixDataAccessor;
-import org.apache.helix.manager.zk.ZkBaseDataAccessor;
-import org.apache.helix.mock.participant.MockTransition;
-import org.apache.helix.model.HealthStat;
-import org.apache.helix.model.Message;
-import org.apache.helix.tools.ClusterSetup;
-import org.apache.helix.tools.ClusterStateVerifier;
-import org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier;
-import org.apache.helix.tools.ClusterStateVerifier.MasterNbInExtViewVerifier;
-import org.testng.Assert;
-import org.testng.annotations.Test;
-
-public class TestDummyAlerts extends ZkIntegrationTestBase {
- public class DummyAlertsTransition extends MockTransition {
- private final AtomicBoolean _done = new AtomicBoolean(false);
-
- @Override
- public void doTransition(Message message, NotificationContext context) {
- HelixManager manager = context.getManager();
- HelixDataAccessor accessor = manager.getHelixDataAccessor();
- Builder keyBuilder = accessor.keyBuilder();
-
- String instance = message.getTgtName();
- if (_done.getAndSet(true) == false) {
- for (int i = 0; i < 5; i++) {
- // System.out.println(instance + " sets healthReport: " + "mockAlerts" + i);
- accessor.setProperty(keyBuilder.healthReport(instance, "mockAlerts"), new HealthStat(
- new ZNRecord("mockAlerts" + i)));
- }
- }
- }
-
- }
-
- @Test()
- public void testDummyAlerts() throws Exception {
- // Logger.getRootLogger().setLevel(Level.INFO);
- String className = TestHelper.getTestClassName();
- String methodName = TestHelper.getTestMethodName();
- String clusterName = className + "_" + methodName;
- final int n = 5;
-
- MockParticipantManager[] participants = new MockParticipantManager[n];
-
- System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
-
- TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, // participant start
- // port
- "localhost", // participant name prefix
- "TestDB", // resource name prefix
- 1, // resources
- 10, // partitions per resource
- n, // number of nodes
- 3, // replicas
- "MasterSlave", true); // do rebalance
-
- ClusterSetup setupTool = new ClusterSetup(ZK_ADDR);
- enableHealthCheck(clusterName);
- setupTool
- .getClusterManagementTool()
- .addAlert(clusterName,
- "EXP(decay(1.0)(*.defaultPerfCounters@defaultPerfCounters.availableCPUs))CMP(GREATER)CON(2)");
-
- // start controller
- ClusterControllerManager controller =
- new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
- controller.syncStart();
-
- // start participants
- for (int i = 0; i < n; i++) {
- String instanceName = "localhost_" + (12918 + i);
-
- participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
- participants[i].setTransition(new DummyAlertsTransition());
- participants[i].syncStart();
- }
-
- boolean result =
- ClusterStateVerifier
- .verifyByZkCallback(new MasterNbInExtViewVerifier(ZK_ADDR, clusterName));
- Assert.assertTrue(result);
-
- result =
- ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR,
- clusterName));
- Assert.assertTrue(result);
-
- // other verifications go here
- ZKHelixDataAccessor accessor =
- new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
- Builder keyBuilder = accessor.keyBuilder();
-
- for (int i = 0; i < n; i++) {
- String instance = "localhost_" + (12918 + i);
- ZNRecord record = null;
- for (int j = 0; j < 10; j++) {
- record = accessor.getProperty(keyBuilder.healthReport(instance, "mockAlerts")).getRecord();
- if (record.getId().equals("mockAlerts4")) {
- break;
- } else {
- Thread.sleep(500);
- }
- }
- Assert.assertEquals(record.getId(), "mockAlerts4");
- }
-
- // clean up
- controller.syncStop();
- for (int i = 0; i < 5; i++) {
- participants[i].syncStop();
- }
-
- System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
- }
-}
http://git-wip-us.apache.org/repos/asf/helix/blob/77cc6516/helix-core/src/test/java/org/apache/helix/healthcheck/TestExpandAlert.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/healthcheck/TestExpandAlert.java b/helix-core/src/test/java/org/apache/helix/healthcheck/TestExpandAlert.java
deleted file mode 100644
index 69b52e7..0000000
--- a/helix-core/src/test/java/org/apache/helix/healthcheck/TestExpandAlert.java
+++ /dev/null
@@ -1,186 +0,0 @@
-package org.apache.helix.healthcheck;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-import java.util.Date;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.helix.HelixDataAccessor;
-import org.apache.helix.HelixManager;
-import org.apache.helix.NotificationContext;
-import org.apache.helix.TestHelper;
-import org.apache.helix.ZNRecord;
-import org.apache.helix.PropertyKey.Builder;
-import org.apache.helix.alerts.AlertValueAndStatus;
-import org.apache.helix.healthcheck.ParticipantHealthReportCollectorImpl;
-import org.apache.helix.integration.ZkIntegrationTestBase;
-import org.apache.helix.integration.manager.ClusterControllerManager;
-import org.apache.helix.integration.manager.MockParticipantManager;
-import org.apache.helix.manager.zk.ZKHelixDataAccessor;
-import org.apache.helix.manager.zk.ZkBaseDataAccessor;
-import org.apache.helix.mock.participant.MockEspressoHealthReportProvider;
-import org.apache.helix.mock.participant.MockTransition;
-import org.apache.helix.model.Message;
-import org.apache.helix.tools.ClusterSetup;
-import org.apache.helix.tools.ClusterStateVerifier;
-import org.testng.Assert;
-import org.testng.annotations.AfterClass;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Test;
-
-public class TestExpandAlert extends ZkIntegrationTestBase {
- protected ClusterSetup _setupTool = null;
- protected final String _alertStr =
- "EXP(decay(1.0)(localhost_*.RestQueryStats@DBName=TestDB0.latency))CMP(GREATER)CON(16)";
- protected final String _alertStatusStr = _alertStr
- + " : (localhost_12918.RestQueryStats@DBName=TestDB0.latency)";
- protected final String _dbName = "TestDB0";
-
- @BeforeClass()
- public void beforeClass() throws Exception {
-
- _setupTool = new ClusterSetup(_gZkClient);
- }
-
- @AfterClass
- public void afterClass() {
- }
-
- public class ExpandAlertTransition extends MockTransition {
- @Override
- public void doTransition(Message message, NotificationContext context) {
- HelixManager manager = context.getManager();
- HelixDataAccessor accessor = manager.getHelixDataAccessor();
- String fromState = message.getFromState();
- String toState = message.getToState();
- String instance = message.getTgtName();
- String partition = message.getPartitionName();
-
- if (fromState.equalsIgnoreCase("SLAVE") && toState.equalsIgnoreCase("MASTER")) {
-
- // add a stat and report to ZK
- // perhaps should keep reporter per instance...
- ParticipantHealthReportCollectorImpl reporter =
- new ParticipantHealthReportCollectorImpl(manager, instance);
- MockEspressoHealthReportProvider provider = new MockEspressoHealthReportProvider();
- reporter.addHealthReportProvider(provider);
- String statName = "latency";
- provider.setStat(_dbName, statName, "15");
- reporter.transmitHealthReports();
-
- /*
- * for (int i = 0; i < 5; i++)
- * {
- * accessor.setProperty(PropertyType.HEALTHREPORT,
- * new ZNRecord("mockAlerts" + i),
- * instance,
- * "mockAlerts");
- * try
- * {
- * Thread.sleep(1000);
- * }
- * catch (InterruptedException e)
- * {
- * // TODO Auto-generated catch block
- * e.printStackTrace();
- * }
- * }
- */
- }
- }
-
- }
-
- @Test()
- public void testExpandAlert() throws Exception {
- String clusterName = getShortClassName();
- MockParticipantManager[] participants = new MockParticipantManager[5];
-
- System.out.println("START TestExpandAlert at " + new Date(System.currentTimeMillis()));
-
- TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, // participant start port
- "localhost", // participant name prefix
- "TestDB", // resource name prefix
- 1, // resources
- 10, // partitions per resource
- 5, // number of nodes //change back to 5!!!
- 3, // replicas //change back to 3!!!
- "MasterSlave", true); // do rebalance
- // enableHealthCheck(clusterName);
-
- _setupTool.getClusterManagementTool().addAlert(clusterName, _alertStr);
-
- ClusterControllerManager controller =
- new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
- controller.syncStart();
-
- // start participants
- for (int i = 0; i < 5; i++) // !!!change back to 5
- {
- String instanceName = "localhost_" + (12918 + i);
-
- participants[i] =
- new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
- participants[i].setTransition(new ExpandAlertTransition());
- participants[i].syncStart();
- }
-
- boolean result =
- ClusterStateVerifier.verifyByPolling(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(
- ZK_ADDR, clusterName));
- Assert.assertTrue(result);
-
- Thread.sleep(1000);
- // HealthAggregationTask is supposed to run by a timer every 30s
- // To make sure HealthAggregationTask is run, we invoke it explicitly for this test
- // new HealthStatsAggregator(cmResult._manager).aggregate();
- new HealthStatsAggregator(controller).aggregate();
- // sleep for a few seconds to give stats stage time to trigger
- Thread.sleep(3000);
-
- // other verifications go here
- ZKHelixDataAccessor accessor =
- new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
- Builder keyBuilder = accessor.keyBuilder();
-
- // for (int i = 0; i < 1; i++) //change 1 back to 5
- // {
- // String instance = "localhost_" + (12918 + i);
- // String instance = "localhost_12918";
- ZNRecord record = accessor.getProperty(keyBuilder.alertStatus()).getRecord();
- Map<String, Map<String, String>> recMap = record.getMapFields();
- Set<String> keySet = recMap.keySet();
- Map<String, String> alertStatusMap = recMap.get(_alertStatusStr);
- String val = alertStatusMap.get(AlertValueAndStatus.VALUE_NAME);
- boolean fired = Boolean.parseBoolean(alertStatusMap.get(AlertValueAndStatus.FIRED_NAME));
- Assert.assertEquals(Double.parseDouble(val), Double.parseDouble("15.0"));
- Assert.assertFalse(fired);
- // }
-
- // clean up
- controller.syncStop();
- for (int i = 0; i < 5; i++) {
- participants[i].syncStop();
-
- }
- System.out.println("END TestExpandAlert at " + new Date(System.currentTimeMillis()));
- }
-}
http://git-wip-us.apache.org/repos/asf/helix/blob/77cc6516/helix-core/src/test/java/org/apache/helix/healthcheck/TestSimpleAlert.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/healthcheck/TestSimpleAlert.java b/helix-core/src/test/java/org/apache/helix/healthcheck/TestSimpleAlert.java
deleted file mode 100644
index ccc0a79..0000000
--- a/helix-core/src/test/java/org/apache/helix/healthcheck/TestSimpleAlert.java
+++ /dev/null
@@ -1,200 +0,0 @@
-package org.apache.helix.healthcheck;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-import java.util.Date;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.helix.HelixDataAccessor;
-import org.apache.helix.HelixManager;
-import org.apache.helix.NotificationContext;
-import org.apache.helix.TestHelper;
-import org.apache.helix.ZNRecord;
-import org.apache.helix.PropertyKey.Builder;
-import org.apache.helix.alerts.AlertValueAndStatus;
-import org.apache.helix.healthcheck.ParticipantHealthReportCollectorImpl;
-import org.apache.helix.integration.ZkIntegrationTestBase;
-import org.apache.helix.integration.manager.ClusterControllerManager;
-import org.apache.helix.integration.manager.MockParticipantManager;
-import org.apache.helix.manager.zk.ZKHelixDataAccessor;
-import org.apache.helix.manager.zk.ZkBaseDataAccessor;
-import org.apache.helix.mock.participant.MockEspressoHealthReportProvider;
-import org.apache.helix.mock.participant.MockTransition;
-import org.apache.helix.model.Message;
-import org.apache.helix.tools.ClusterSetup;
-import org.apache.helix.tools.ClusterStateVerifier;
-import org.testng.Assert;
-import org.testng.annotations.AfterClass;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Test;
-
-public class TestSimpleAlert extends ZkIntegrationTestBase {
- protected ClusterSetup _setupTool = null;
- protected final String _alertStr =
- "EXP(decay(1.0)(localhost_12918.RestQueryStats@DBName=TestDB0.latency))CMP(GREATER)CON(10)";
- protected final String _alertStatusStr = _alertStr; // +" : (*)";
- protected final String _dbName = "TestDB0";
-
- @BeforeClass()
- public void beforeClass() throws Exception {
- _setupTool = new ClusterSetup(_gZkClient);
- }
-
- @AfterClass
- public void afterClass() {
- }
-
- public class SimpleAlertTransition extends MockTransition {
- int _alertValue;
-
- public SimpleAlertTransition(int value) {
- _alertValue = value;
- }
-
- @Override
- public void doTransition(Message message, NotificationContext context) {
- HelixManager manager = context.getManager();
- HelixDataAccessor accessor = manager.getHelixDataAccessor();
- String fromState = message.getFromState();
- String toState = message.getToState();
- String instance = message.getTgtName();
- String partition = message.getPartitionName();
-
- if (fromState.equalsIgnoreCase("SLAVE") && toState.equalsIgnoreCase("MASTER")) {
-
- // add a stat and report to ZK
- // perhaps should keep reporter per instance...
- ParticipantHealthReportCollectorImpl reporter =
- new ParticipantHealthReportCollectorImpl(manager, instance);
- MockEspressoHealthReportProvider provider = new MockEspressoHealthReportProvider();
- reporter.addHealthReportProvider(provider);
- String statName = "latency";
- provider.setStat(_dbName, statName, "" + (0.1 + _alertValue));
- reporter.transmitHealthReports();
-
- /*
- * for (int i = 0; i < 5; i++)
- * {
- * accessor.setProperty(PropertyType.HEALTHREPORT,
- * new ZNRecord("mockAlerts" + i),
- * instance,
- * "mockAlerts");
- * try
- * {
- * Thread.sleep(1000);
- * }
- * catch (InterruptedException e)
- * {
- * // TODO Auto-generated catch block
- * e.printStackTrace();
- * }
- * }
- */
- }
- }
-
- }
-
- @Test()
- public void testSimpleAlert() throws Exception {
- String clusterName = getShortClassName();
- MockParticipantManager[] participants = new MockParticipantManager[5];
-
- System.out.println("START TestSimpleAlert at " + new Date(System.currentTimeMillis()));
-
- TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, // participant start port
- "localhost", // participant name prefix
- "TestDB", // resource name prefix
- 1, // resources
- 10, // partitions per resource
- 5, // number of nodes //change back to 5!!!
- 3, // replicas //change back to 3!!!
- "MasterSlave", true); // do rebalance
-
- // enableHealthCheck(clusterName);
-
- ClusterControllerManager controller =
- new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
- controller.syncStart();
- controller.startTimerTasks();
-
- _setupTool.getClusterManagementTool().addAlert(clusterName, _alertStr);
- // start participants
- for (int i = 0; i < 5; i++) // !!!change back to 5
- {
- String instanceName = "localhost_" + (12918 + i);
-
- participants[i] =
- new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
- participants[i].setTransition(new SimpleAlertTransition(15));
- participants[i].syncStart();
- }
-
- boolean result =
- ClusterStateVerifier.verifyByPolling(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(
- ZK_ADDR, clusterName));
- Assert.assertTrue(result);
-
- // HealthAggregationTask is supposed to run by a timer every 30s
- // To make sure HealthAggregationTask is run, we invoke it explicitly for this test
- // new HealthStatsAggregator(cmResult._manager).aggregate();
- new HealthStatsAggregator(controller).aggregate();
- // sleep for a few seconds to give stats stage time to trigger
- Thread.sleep(3000);
-
- // other verifications go here
- ZKHelixDataAccessor accessor =
- new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
- Builder keyBuilder = accessor.keyBuilder();
- // for (int i = 0; i < 1; i++) //change 1 back to 5
- // {
- // String instance = "localhost_" + (12918 + i);
- String instance = "localhost_12918";
- ZNRecord record = accessor.getProperty(keyBuilder.alertStatus()).getRecord();
- Map<String, Map<String, String>> recMap = record.getMapFields();
- Set<String> keySet = recMap.keySet();
- Map<String, String> alertStatusMap = recMap.get(_alertStatusStr);
- String val = alertStatusMap.get(AlertValueAndStatus.VALUE_NAME);
- boolean fired = Boolean.parseBoolean(alertStatusMap.get(AlertValueAndStatus.FIRED_NAME));
- Assert.assertEquals(Double.parseDouble(val), Double.parseDouble("15.1"));
- Assert.assertTrue(fired);
-
- // Verify Alert history from ZK
- ZNRecord alertHistory = accessor.getProperty(keyBuilder.alertHistory()).getRecord();
-
- String deltakey = (String) (alertHistory.getMapFields().keySet().toArray()[0]);
- Map<String, String> delta = alertHistory.getMapField(deltakey);
- Assert.assertTrue(delta.size() == 1);
- Assert
- .assertTrue(delta
- .get(
- "EXP(decay(1.0)(localhost_12918.RestQueryStats@DBName#TestDB0.latency))CMP(GREATER)CON(10)--(%)")
- .equals("ON"));
- // }
-
- // clean up
- controller.syncStop();
- for (int i = 0; i < 5; i++) {
- participants[i].syncStop();
- }
- System.out.println("END TestSimpleAlert at " + new Date(System.currentTimeMillis()));
- }
-}