You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@helix.apache.org by ka...@apache.org on 2014/07/11 21:58:00 UTC
[05/17] [HELIX-395] Remove old Helix alert/stat modules
http://git-wip-us.apache.org/repos/asf/helix/blob/38b43965/helix-core/src/test/java/org/apache/helix/alerts/TestArrivingParticipantStats.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/alerts/TestArrivingParticipantStats.java b/helix-core/src/test/java/org/apache/helix/alerts/TestArrivingParticipantStats.java
deleted file mode 100644
index 454d410..0000000
--- a/helix-core/src/test/java/org/apache/helix/alerts/TestArrivingParticipantStats.java
+++ /dev/null
@@ -1,496 +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.HashMap;
-import java.util.Map;
-
-import org.apache.helix.HelixDataAccessor;
-import org.apache.helix.Mocks.MockManager;
-import org.apache.helix.PropertyKey.Builder;
-import org.apache.helix.ZNRecord;
-import org.apache.helix.controller.stages.HealthDataCache;
-import org.testng.AssertJUnit;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-public class TestArrivingParticipantStats {
- protected static final String CLUSTER_NAME = "TestCluster";
-
- MockManager _helixManager;
- StatsHolder _statsHolder;
-
- @BeforeMethod(groups = {
- "unitTest"
- })
- public void setup() {
- _helixManager = new MockManager(CLUSTER_NAME);
- _statsHolder = new StatsHolder(_helixManager, new HealthDataCache());
- }
-
- public Map<String, String> getStatFields(String value, String timestamp) {
- Map<String, String> statMap = new HashMap<String, String>();
- statMap.put(StatsHolder.VALUE_NAME, value);
- statMap.put(StatsHolder.TIMESTAMP_NAME, timestamp);
- return statMap;
- }
-
- public boolean statRecordContains(ZNRecord rec, String statName) {
- Map<String, Map<String, String>> stats = rec.getMapFields();
- return stats.containsKey(statName);
- }
-
- public boolean statRecordHasValue(ZNRecord rec, String statName, String value) {
- Map<String, Map<String, String>> stats = rec.getMapFields();
- Map<String, String> statFields = stats.get(statName);
- return (statFields.get(StatsHolder.VALUE_NAME).equals(value));
- }
-
- public boolean statRecordHasTimestamp(ZNRecord rec, String statName, String timestamp) {
- Map<String, Map<String, String>> stats = rec.getMapFields();
- Map<String, String> statFields = stats.get(statName);
- return (statFields.get(StatsHolder.TIMESTAMP_NAME).equals(timestamp));
- }
-
- // Exact matching persistent stat, but has no values yet
- @Test(groups = {
- "unitTest"
- })
- public void testAddFirstParticipantStat() throws Exception {
- // add a persistent stat
- String persistentStat = "accumulate()(dbFoo.partition10.latency)";
- _statsHolder.addStat(persistentStat);
-
- // generate incoming stat
- String incomingStatName = "dbFoo.partition10.latency";
- Map<String, String> statFields = getStatFields("0", "0");
- _statsHolder.applyStat(incomingStatName, statFields);
- _statsHolder.persistStats();
-
- // check persistent stats
- HelixDataAccessor accessor = _helixManager.getHelixDataAccessor();
- Builder keyBuilder = accessor.keyBuilder();
-
- ZNRecord rec = accessor.getProperty(keyBuilder.persistantStat()).getRecord();
-
- System.out.println("rec: " + rec.toString());
- AssertJUnit.assertTrue(statRecordHasValue(rec, persistentStat, "0.0"));
- AssertJUnit.assertTrue(statRecordHasTimestamp(rec, persistentStat, "0.0"));
- }
-
- // Exact matching persistent stat, but has no values yet
- @Test(groups = {
- "unitTest"
- })
- public void testAddRepeatParticipantStat() throws Exception {
- // add a persistent stat
- String persistentStat = "accumulate()(dbFoo.partition10.latency)";
- _statsHolder.addStat(persistentStat);
-
- // generate incoming stat
- String incomingStatName = "dbFoo.partition10.latency";
- // apply stat once and then again
- Map<String, String> statFields = getStatFields("0", "0");
- _statsHolder.applyStat(incomingStatName, statFields);
- statFields = getStatFields("1", "10");
- _statsHolder.applyStat(incomingStatName, statFields);
- _statsHolder.persistStats();
-
- // check persistent stats
- HelixDataAccessor accessor = _helixManager.getHelixDataAccessor();
- Builder keyBuilder = accessor.keyBuilder();
-
- ZNRecord rec = accessor.getProperty(keyBuilder.persistantStat()).getRecord();
-
- System.out.println("rec: " + rec.toString());
- AssertJUnit.assertTrue(statRecordHasValue(rec, persistentStat, "1.0"));
- AssertJUnit.assertTrue(statRecordHasTimestamp(rec, persistentStat, "10.0"));
- }
-
- // test to ensure backdated stats not applied
- @Test(groups = {
- "unitTest"
- })
- public void testBackdatedParticipantStat() throws Exception {
- // add a persistent stat
- String persistentStat = "accumulate()(dbFoo.partition10.latency)";
- _statsHolder.addStat(persistentStat);
-
- // generate incoming stat
- String incomingStatName = "dbFoo.partition10.latency";
- // apply stat once and then again
- Map<String, String> statFields = getStatFields("0", "0");
- _statsHolder.applyStat(incomingStatName, statFields);
- statFields = getStatFields("1", "10");
- _statsHolder.applyStat(incomingStatName, statFields);
- statFields = getStatFields("5", "15");
- _statsHolder.applyStat(incomingStatName, statFields);
- statFields = getStatFields("1", "10");
- _statsHolder.applyStat(incomingStatName, statFields);
- _statsHolder.persistStats();
-
- // check persistent stats
- HelixDataAccessor accessor = _helixManager.getHelixDataAccessor();
- Builder keyBuilder = accessor.keyBuilder();
-
- ZNRecord rec = accessor.getProperty(keyBuilder.persistantStat()).getRecord();
-
- System.out.println("rec: " + rec.toString());
- AssertJUnit.assertTrue(statRecordHasValue(rec, persistentStat, "6.0"));
- AssertJUnit.assertTrue(statRecordHasTimestamp(rec, persistentStat, "15.0"));
- }
-
- // Exact matching persistent stat, but has no values yet
- @Test(groups = {
- "unitTest"
- })
- public void testAddFirstParticipantStatToWildCard() throws Exception {
- // add a persistent stat
- String persistentWildcardStat = "accumulate()(dbFoo.partition*.latency)";
- _statsHolder.addStat(persistentWildcardStat);
-
- // generate incoming stat
- String incomingStatName = "dbFoo.partition10.latency";
- Map<String, String> statFields = getStatFields("0", "0");
- _statsHolder.applyStat(incomingStatName, statFields);
- _statsHolder.persistStats();
-
- // check persistent stats
- HelixDataAccessor accessor = _helixManager.getHelixDataAccessor();
- Builder keyBuilder = accessor.keyBuilder();
-
- ZNRecord rec = accessor.getProperty(keyBuilder.persistantStat()).getRecord();
-
- System.out.println("rec: " + rec.toString());
- String persistentStat = "accumulate()(dbFoo.partition10.latency)";
- AssertJUnit.assertTrue(statRecordHasValue(rec, persistentStat, "0.0"));
- AssertJUnit.assertTrue(statRecordHasTimestamp(rec, persistentStat, "0.0"));
- }
-
- // test to add 2nd report to same stat
- @Test(groups = {
- "unitTest"
- })
- public void testAddSecondParticipantStatToWildCard() throws Exception {
- // add a persistent stat
- String persistentWildcardStat = "accumulate()(dbFoo.partition*.latency)";
- _statsHolder.addStat(persistentWildcardStat);
-
- // generate incoming stat
- String incomingStatName = "dbFoo.partition10.latency";
- Map<String, String> statFields = getStatFields("1", "0");
- _statsHolder.applyStat(incomingStatName, statFields);
- statFields = getStatFields("1", "10");
- _statsHolder.applyStat(incomingStatName, statFields);
- _statsHolder.persistStats();
-
- // check persistent stats
- HelixDataAccessor accessor = _helixManager.getHelixDataAccessor();
- Builder keyBuilder = accessor.keyBuilder();
-
- ZNRecord rec = accessor.getProperty(keyBuilder.persistantStat()).getRecord();
-
- System.out.println("rec: " + rec.toString());
- String persistentStat = "accumulate()(dbFoo.partition10.latency)";
- AssertJUnit.assertTrue(statRecordHasValue(rec, persistentStat, "2.0"));
- AssertJUnit.assertTrue(statRecordHasTimestamp(rec, persistentStat, "10.0"));
- }
-
- // Exact matching persistent stat, but has no values yet
- @Test(groups = {
- "unitTest"
- })
- public void testAddParticipantStatToDoubleWildCard() throws Exception {
- // add a persistent stat
- String persistentWildcardStat = "accumulate()(db*.partition*.latency)";
- _statsHolder.addStat(persistentWildcardStat);
-
- // generate incoming stat
- String incomingStatName = "dbFoo.partition10.latency";
- Map<String, String> statFields = getStatFields("0", "0");
- _statsHolder.applyStat(incomingStatName, statFields);
- _statsHolder.persistStats();
-
- // check persistent stats
- HelixDataAccessor accessor = _helixManager.getHelixDataAccessor();
- Builder keyBuilder = accessor.keyBuilder();
-
- ZNRecord rec = accessor.getProperty(keyBuilder.persistantStat()).getRecord();
-
- System.out.println("rec: " + rec.toString());
- String persistentStat = "accumulate()(dbFoo.partition10.latency)";
- AssertJUnit.assertTrue(statRecordHasValue(rec, persistentStat, "0.0"));
- AssertJUnit.assertTrue(statRecordHasTimestamp(rec, persistentStat, "0.0"));
- }
-
- @Test(groups = {
- "unitTest"
- })
- public void testAddWildcardInFirstStatToken() throws Exception {
- String persistentWildcardStat = "accumulate()(instance*.reportingage)";
- _statsHolder.addStat(persistentWildcardStat);
-
- // generate incoming stat
- String incomingStatName = "instance10.reportingage";
- Map<String, String> statFields = getStatFields("1", "10");
- _statsHolder.applyStat(incomingStatName, statFields);
- _statsHolder.persistStats();
-
- // check persistent stats
- HelixDataAccessor accessor = _helixManager.getHelixDataAccessor();
- Builder keyBuilder = accessor.keyBuilder();
-
- ZNRecord rec = accessor.getProperty(keyBuilder.persistantStat()).getRecord();
-
- System.out.println("rec: " + rec.toString());
- String persistentStat = "accumulate()(instance10.reportingage)";
- AssertJUnit.assertTrue(statRecordHasValue(rec, persistentStat, "1.0"));
- AssertJUnit.assertTrue(statRecordHasTimestamp(rec, persistentStat, "10.0"));
-
- }
-
- // test to add report to same wildcard stat, different actual stat
- @Test(groups = {
- "unitTest"
- })
- public void testAddTwoDistinctParticipantStatsToSameWildCard() throws Exception {
- // add a persistent stat
- String persistentWildcardStat = "accumulate()(dbFoo.partition*.latency)";
- _statsHolder.addStat(persistentWildcardStat);
-
- // generate incoming stat
- String incomingStatName = "dbFoo.partition10.latency";
- Map<String, String> statFields = getStatFields("1", "10");
- _statsHolder.applyStat(incomingStatName, statFields);
- incomingStatName = "dbFoo.partition11.latency";
- statFields = getStatFields("5", "10");
- _statsHolder.applyStat(incomingStatName, statFields);
- _statsHolder.persistStats();
-
- // check persistent stats
- HelixDataAccessor accessor = _helixManager.getHelixDataAccessor();
- Builder keyBuilder = accessor.keyBuilder();
-
- ZNRecord rec = accessor.getProperty(keyBuilder.persistantStat()).getRecord();
-
- System.out.println("rec: " + rec.toString());
- String persistentStat = "accumulate()(dbFoo.partition10.latency)";
- AssertJUnit.assertTrue(statRecordHasValue(rec, persistentStat, "1.0"));
- AssertJUnit.assertTrue(statRecordHasTimestamp(rec, persistentStat, "10.0"));
- persistentStat = "accumulate()(dbFoo.partition11.latency)";
- AssertJUnit.assertTrue(statRecordHasValue(rec, persistentStat, "5.0"));
- AssertJUnit.assertTrue(statRecordHasTimestamp(rec, persistentStat, "10.0"));
- }
-
- // Exact matching persistent stat, but has no values yet
- @Test(groups = {
- "unitTest"
- })
- public void testWindowStat() throws Exception {
- // add a persistent stat
- String persistentWildcardStat = "window(3)(dbFoo.partition*.latency)";
- _statsHolder.addStat(persistentWildcardStat);
-
- // generate incoming stat
- String incomingStatName = "dbFoo.partition10.latency";
- Map<String, String> statFields = getStatFields("0", "0");
- _statsHolder.applyStat(incomingStatName, statFields);
- _statsHolder.persistStats();
-
- // check persistent stats
- HelixDataAccessor accessor = _helixManager.getHelixDataAccessor();
- Builder keyBuilder = accessor.keyBuilder();
-
- ZNRecord rec = accessor.getProperty(keyBuilder.persistantStat()).getRecord();
-
- System.out.println("rec: " + rec.toString());
- String persistentStat = "window(3)(dbFoo.partition10.latency)";
- AssertJUnit.assertTrue(statRecordHasValue(rec, persistentStat, "0.0"));
- AssertJUnit.assertTrue(statRecordHasTimestamp(rec, persistentStat, "0.0"));
-
- // add 2nd stat
- statFields = getStatFields("10", "1");
- _statsHolder.applyStat(incomingStatName, statFields);
- _statsHolder.persistStats();
-
- rec = accessor.getProperty(keyBuilder.persistantStat()).getRecord();
-
- System.out.println("rec: " + rec.toString());
- AssertJUnit.assertTrue(statRecordHasValue(rec, persistentStat, "0.0,10.0"));
- AssertJUnit.assertTrue(statRecordHasTimestamp(rec, persistentStat, "0.0,1.0"));
-
- // add 3rd stat
- statFields = getStatFields("20", "2");
- _statsHolder.applyStat(incomingStatName, statFields);
- _statsHolder.persistStats();
-
- rec = accessor.getProperty(keyBuilder.persistantStat()).getRecord();
-
- System.out.println("rec: " + rec.toString());
- AssertJUnit.assertTrue(statRecordHasValue(rec, persistentStat, "0.0,10.0,20.0"));
- AssertJUnit.assertTrue(statRecordHasTimestamp(rec, persistentStat, "0.0,1.0,2.0"));
-
- }
-
- @Test(groups = {
- "unitTest"
- })
- public void testWindowStatExpiration() throws Exception {
- String persistentWildcardStat = "window(3)(dbFoo.partition*.latency)";
- String persistentStat = "window(3)(dbFoo.partition10.latency)";
- // init with 3 elements
- testWindowStat();
-
- String incomingStatName = "dbFoo.partition10.latency";
- Map<String, String> statFields = getStatFields("30", "3");
- _statsHolder.applyStat(incomingStatName, statFields);
- _statsHolder.persistStats();
-
- HelixDataAccessor accessor = _helixManager.getHelixDataAccessor();
- Builder keyBuilder = accessor.keyBuilder();
-
- ZNRecord rec = accessor.getProperty(keyBuilder.persistantStat()).getRecord();
-
- System.out.println("rec: " + rec.toString());
- AssertJUnit.assertTrue(statRecordHasValue(rec, persistentStat, "10.0,20.0,30.0"));
- AssertJUnit.assertTrue(statRecordHasTimestamp(rec, persistentStat, "1.0,2.0,3.0"));
- }
-
- @Test(groups = {
- "unitTest"
- })
- public void testWindowStatStale() throws Exception {
- String persistentWildcardStat = "window(3)(dbFoo.partition*.latency)";
- String persistentStat = "window(3)(dbFoo.partition10.latency)";
- // init with 3 elements
- testWindowStat();
-
- String incomingStatName = "dbFoo.partition10.latency";
- Map<String, String> statFields = getStatFields("10", "1");
- _statsHolder.applyStat(incomingStatName, statFields);
- _statsHolder.persistStats();
-
- HelixDataAccessor accessor = _helixManager.getHelixDataAccessor();
- Builder keyBuilder = accessor.keyBuilder();
-
- ZNRecord rec = accessor.getProperty(keyBuilder.persistantStat()).getRecord();
-
- System.out.println("rec: " + rec.toString());
- AssertJUnit.assertTrue(statRecordHasValue(rec, persistentStat, "0.0,10.0,20.0"));
- AssertJUnit.assertTrue(statRecordHasTimestamp(rec, persistentStat, "0.0,1.0,2.0"));
- }
-
- // test that has 2 agg stats for same raw stat
- // Exact matching persistent stat, but has no values yet
- @Test(groups = {
- "unitTest"
- })
- public void testAddStatForTwoAggTypes() throws Exception {
- // add a persistent stat
- String persistentStatOne = "accumulate()(dbFoo.partition10.latency)";
- String persistentStatTwo = "window(3)(dbFoo.partition10.latency)";
- _statsHolder.addStat(persistentStatOne);
- _statsHolder.persistStats();
- _statsHolder.addStat(persistentStatTwo);
- _statsHolder.persistStats();
-
- // generate incoming stat
- String incomingStatName = "dbFoo.partition10.latency";
- Map<String, String> statFields = getStatFields("0", "0");
- _statsHolder.applyStat(incomingStatName, statFields);
- _statsHolder.persistStats();
-
- // check persistent stats
- HelixDataAccessor accessor = _helixManager.getHelixDataAccessor();
- Builder keyBuilder = accessor.keyBuilder();
-
- ZNRecord rec = accessor.getProperty(keyBuilder.persistantStat()).getRecord();
-
- System.out.println("rec: " + rec.toString());
- AssertJUnit.assertTrue(statRecordHasValue(rec, persistentStatOne, "0.0"));
- AssertJUnit.assertTrue(statRecordHasTimestamp(rec, persistentStatOne, "0.0"));
- AssertJUnit.assertTrue(statRecordHasValue(rec, persistentStatTwo, "0.0"));
- AssertJUnit.assertTrue(statRecordHasTimestamp(rec, persistentStatTwo, "0.0"));
- }
-
- // test merging 2 window stats, new is applied
- @Test(groups = {
- "unitTest"
- })
- public void testMergeTwoWindowsYesMerge() throws Exception {
- String persistentWildcardStat = "window(3)(dbFoo.partition*.latency)";
- String persistentStat = "window(3)(dbFoo.partition10.latency)";
- String incomingStatName = "dbFoo.partition10.latency";
- // init with 3 elements
- testWindowStat();
-
- // create a two tuples, value and time
- Tuple<String> valTuple = new Tuple<String>();
- Tuple<String> timeTuple = new Tuple<String>();
- valTuple.add("30.0");
- valTuple.add("40.0");
- timeTuple.add("3.0");
- timeTuple.add("4.0");
- Map<String, String> statFields = getStatFields(valTuple.toString(), timeTuple.toString());
- _statsHolder.applyStat(incomingStatName, statFields);
- _statsHolder.persistStats();
-
- // check persistent stats
- HelixDataAccessor accessor = _helixManager.getHelixDataAccessor();
- Builder keyBuilder = accessor.keyBuilder();
-
- ZNRecord rec = accessor.getProperty(keyBuilder.persistantStat()).getRecord();
- System.out.println("rec: " + rec.toString());
- AssertJUnit.assertTrue(statRecordHasValue(rec, persistentStat, "20.0,30.0,40.0"));
- AssertJUnit.assertTrue(statRecordHasTimestamp(rec, persistentStat, "2.0,3.0,4.0"));
- }
-
- // test merging 2 window stats, new is ignored
- @Test(groups = {
- "unitTest"
- })
- public void testMergeTwoWindowsNoMerge() throws Exception {
- String persistentWildcardStat = "window(3)(dbFoo.partition*.latency)";
- String persistentStat = "window(3)(dbFoo.partition10.latency)";
- String incomingStatName = "dbFoo.partition10.latency";
- // init with 3 elements
- testWindowStat();
-
- // create a two tuples, value and time
- Tuple<String> valTuple = new Tuple<String>();
- Tuple<String> timeTuple = new Tuple<String>();
- valTuple.add("0.0");
- valTuple.add("40.0");
- timeTuple.add("0.0");
- timeTuple.add("4.0");
- Map<String, String> statFields = getStatFields(valTuple.toString(), timeTuple.toString());
- _statsHolder.applyStat(incomingStatName, statFields);
- _statsHolder.persistStats();
-
- // check persistent stats
- HelixDataAccessor accessor = _helixManager.getHelixDataAccessor();
- Builder keyBuilder = accessor.keyBuilder();
-
- ZNRecord rec = accessor.getProperty(keyBuilder.persistantStat()).getRecord();
- System.out.println("rec: " + rec.toString());
- AssertJUnit.assertTrue(statRecordHasValue(rec, persistentStat, "0.0,10.0,20.0"));
- AssertJUnit.assertTrue(statRecordHasTimestamp(rec, persistentStat, "0.0,1.0,2.0"));
- }
-}
http://git-wip-us.apache.org/repos/asf/helix/blob/38b43965/helix-core/src/test/java/org/apache/helix/alerts/TestBaseStatsValidation.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/alerts/TestBaseStatsValidation.java b/helix-core/src/test/java/org/apache/helix/alerts/TestBaseStatsValidation.java
deleted file mode 100644
index d9cc86f..0000000
--- a/helix-core/src/test/java/org/apache/helix/alerts/TestBaseStatsValidation.java
+++ /dev/null
@@ -1,169 +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.testng.AssertJUnit;
-import org.testng.annotations.Test;
-
-@Test
-public class TestBaseStatsValidation {
-
- @Test
- public void testParseSingletonExpression() {
- String[] actual = null;
-
- String statName = "window(5)(dbFoo.partition10.latency)";
- try {
- actual = ExpressionParser.getBaseStats(statName);
- } catch (HelixException e) {
- e.printStackTrace();
- }
- AssertJUnit.assertEquals(statName, actual[0]);
- }
-
- @Test
- public void testExtraParen() {
- String[] actual = null;
-
- String statName = "window(5)(dbFoo.partition10.latency)()";
- boolean caughtException = false;
- try {
- actual = ExpressionParser.getBaseStats(statName);
- } catch (HelixException e) {
- caughtException = true;
- // e.printStackTrace();
- }
- AssertJUnit.assertEquals(true, caughtException);
- }
-
- @Test
- public void testParseSingletonWildcardExpression() {
- String[] actual = null;
-
- String statName = "accumulate()(dbFoo.partition*.latency)";
- try {
- actual = ExpressionParser.getBaseStats(statName);
- } catch (HelixException e) {
- e.printStackTrace();
- }
- AssertJUnit.assertEquals(statName, actual[0]);
- }
-
- @Test
- public void testParsePairOfExpressions() {
- String[] actual = null;
-
- String expression = "accumulate()(dbFoo.partition10.latency, dbFoo.partition10.count)";
- try {
- actual = ExpressionParser.getBaseStats(expression);
- } catch (HelixException e) {
- e.printStackTrace();
- }
- AssertJUnit.assertEquals("accumulate()(dbFoo.partition10.latency)", actual[0]);
- AssertJUnit.assertEquals("accumulate()(dbFoo.partition10.count)", actual[1]);
- }
-
- /*
- * SUM is not to be persisted, so pull out the pieces
- */
- @Test
- public void testSUMExpression() {
- String[] actual = null;
-
- String expression = "accumulate()(dbFoo.partition*.latency)|SUM";
- try {
- actual = ExpressionParser.getBaseStats(expression);
- } catch (HelixException e) {
- e.printStackTrace();
- }
- AssertJUnit.assertEquals("accumulate()(dbFoo.partition*.latency)", actual[0]);
- }
-
- @Test
- public void testSumPairExpression() {
- String[] actual = null;
-
- String expression = "window(5)(dbFoo.partition10.latency, dbFoo.partition11.latency)|SUM";
- try {
- actual = ExpressionParser.getBaseStats(expression);
- } catch (HelixException e) {
- e.printStackTrace();
- }
- AssertJUnit.assertEquals("window(5)(dbFoo.partition10.latency)", actual[0]);
- AssertJUnit.assertEquals("window(5)(dbFoo.partition11.latency)", actual[1]);
- }
-
- @Test
- public void testEachPairExpression() {
- String[] actual = null;
-
- String expression = "accumulate()(dbFoo.partition*.latency, dbFoo.partition*.count)|EACH";
- try {
- actual = ExpressionParser.getBaseStats(expression);
- } catch (HelixException e) {
- e.printStackTrace();
- }
- AssertJUnit.assertEquals("accumulate()(dbFoo.partition*.latency)", actual[0]);
- AssertJUnit.assertEquals("accumulate()(dbFoo.partition*.count)", actual[1]);
- }
-
- @Test
- public void testAccumulateExpression() {
- String[] actual = null;
-
- String expression = "accumulate()(dbFoo.partition10.latency)|ACCUMULATE";
- try {
- actual = ExpressionParser.getBaseStats(expression);
- } catch (HelixException e) {
- e.printStackTrace();
- }
- AssertJUnit.assertEquals("accumulate()(dbFoo.partition10.latency)", actual[0]);
- }
-
- @Test
- public void testAccumulateEachExpression() {
- String[] actual = null;
-
- String expression = "window(5)(dbFoo.partition*.latency)|EACH|ACCUMULATE";
- try {
- actual = ExpressionParser.getBaseStats(expression);
- } catch (HelixException e) {
- e.printStackTrace();
- }
- AssertJUnit.assertEquals("window(5)(dbFoo.partition*.latency)", actual[0]);
- }
-
- @Test
- public void testAccumulateEachPairExpression() {
- String[] actual = null;
-
- String expression =
- "accumulate()(dbFoo.partition*.latency, dbFoo.partition*.count)|EACH|ACCUMULATE|DIVIDE";
- try {
- actual = ExpressionParser.getBaseStats(expression);
- } catch (HelixException e) {
- e.printStackTrace();
- }
- AssertJUnit.assertEquals("accumulate()(dbFoo.partition*.latency)", actual[0]);
- AssertJUnit.assertEquals("accumulate()(dbFoo.partition*.count)", actual[1]);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/helix/blob/38b43965/helix-core/src/test/java/org/apache/helix/alerts/TestEvaluateAlerts.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/alerts/TestEvaluateAlerts.java b/helix-core/src/test/java/org/apache/helix/alerts/TestEvaluateAlerts.java
deleted file mode 100644
index 7089146..0000000
--- a/helix-core/src/test/java/org/apache/helix/alerts/TestEvaluateAlerts.java
+++ /dev/null
@@ -1,388 +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.HashMap;
-import java.util.Map;
-
-import org.apache.helix.HelixException;
-import org.apache.helix.Mocks.MockManager;
-import org.apache.helix.controller.stages.HealthDataCache;
-import org.testng.AssertJUnit;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-public class TestEvaluateAlerts {
- protected static final String CLUSTER_NAME = "TestCluster";
-
- MockManager _helixManager;
- AlertsHolder _alertsHolder;
- StatsHolder _statsHolder;
-
- public final String EXP = AlertParser.EXPRESSION_NAME;
- public final String CMP = AlertParser.COMPARATOR_NAME;
- public final String CON = AlertParser.CONSTANT_NAME;
-
- @BeforeMethod(groups = {
- "unitTest"
- })
- public void setup() {
- HealthDataCache cache = new HealthDataCache();
- _helixManager = new MockManager(CLUSTER_NAME);
- _alertsHolder = new AlertsHolder(_helixManager, cache);
- _statsHolder = _alertsHolder._statsHolder;
- }
-
- public Map<String, String> getStatFields(String value, String timestamp) {
- Map<String, String> statMap = new HashMap<String, String>();
- statMap.put(StatsHolder.VALUE_NAME, value);
- statMap.put(StatsHolder.TIMESTAMP_NAME, timestamp);
- return statMap;
- }
-
- public String getSimpleStat() throws HelixException {
- String stat = "accumulate()(dbFoo.partition10.latency)";
- // _statsHolder.addStat(stat);
- return stat;
- }
-
- public String addPairOfStats() throws HelixException {
- String stat = "accumulate()(dbFoo.partition10.latency, dbFoo.partition11.latency)";
- _statsHolder.addStat(stat);
- _statsHolder.persistStats();
- return stat;
- }
-
- public String getWildcardStat() throws HelixException {
- String stat = "accumulate()(dbFoo.partition*.latency)";
- // _statsHolder.addStat(stat);
- return stat;
- }
-
- public String addSimpleAlert() throws HelixException {
- String alert =
- EXP + "(accumulate()(dbFoo.partition10.latency))" + CMP + "(GREATER)" + CON + "(100)";
- _alertsHolder.addAlert(alert);
- return alert;
- }
-
- public String addWildcardAlert() throws HelixException {
- String alert =
- EXP + "(accumulate()(dbFoo.partition*.latency))" + CMP + "(GREATER)" + CON + "(100)";
- _alertsHolder.addAlert(alert);
- return alert;
- }
-
- public String addTwoWildcardAlert() throws HelixException {
- String alert =
- EXP + "(accumulate()(dbFoo.partition*.put*))" + CMP + "(GREATER)" + CON + "(100)";
- _alertsHolder.addAlert(alert);
- return alert;
- }
-
- public String addExpandWildcardAlert() throws HelixException {
- String alert =
- EXP + "(accumulate()(dbFoo.partition*.latency)|EXPAND)" + CMP + "(GREATER)" + CON + "(100)";
- _alertsHolder.addAlert(alert);
- return alert;
- }
-
- public String addExpandSumAlert() throws HelixException {
- String alert =
- EXP + "(accumulate()(dbFoo.partition10.latency,dbFoo.partition11.latency)|EXPAND|SUM)"
- + CMP + "(GREATER)" + CON + "(100)";
- _alertsHolder.addAlert(alert);
- return alert;
- }
-
- public String addExpandSumWildcardAlert() throws HelixException {
- String alert =
- EXP + "(accumulate()(dbFoo.partition*.success,dbFoo.partition*.failure)|EXPAND|SUM)" + CMP
- + "(GREATER)" + CON + "(100)";
- _alertsHolder.addAlert(alert);
- return alert;
- }
-
- public String addExpandSumEachWildcardAlert() throws HelixException {
- String alert =
- EXP + "(accumulate()(dbFoo.partition*.success,dbFoo.partition*.failure)|EXPAND|SUMEACH)"
- + CMP + "(GREATER)" + CON + "(100)";
- _alertsHolder.addAlert(alert);
- return alert;
- }
-
- public String addExpandSumEachSumWildcardAlert() throws HelixException {
- String alert =
- EXP
- + "(accumulate()(dbFoo.partition*.success,dbFoo.partition*.failure)|EXPAND|SUMEACH|SUM)"
- + CMP + "(GREATER)" + CON + "(100)";
- _alertsHolder.addAlert(alert);
- return alert;
- }
-
- public String addArrivingSimpleStat() throws HelixException {
- _statsHolder.refreshStats();
- String incomingStatName = "dbFoo.partition10.latency";
- Map<String, String> statFields = getStatFields("110", "0");
- _statsHolder.applyStat(incomingStatName, statFields);
- _statsHolder.persistStats();
- return incomingStatName;
- }
-
- public String addArrivingPairOfStats() throws HelixException {
- _statsHolder.refreshStats();
- String incomingStatName1 = "dbFoo.partition10.latency";
- String incomingStatName2 = "dbFoo.partition11.latency";
- Map<String, String> statFields = getStatFields("50", "0");
- _statsHolder.applyStat(incomingStatName1, statFields);
- statFields = getStatFields("51", "0");
- _statsHolder.applyStat(incomingStatName2, statFields);
- _statsHolder.persistStats();
- return null;
- }
-
- @Test(groups = {
- "unitTest"
- })
- public void testSimpleAlertFires() {
- String alert = addSimpleAlert();
- String stat = AlertParser.getComponent(AlertParser.EXPRESSION_NAME, alert);
- _statsHolder.refreshStats(); // need to refresh since not triggered by stats aggregation stage
- addArrivingSimpleStat();
- Map<String, Map<String, AlertValueAndStatus>> alertResult =
- AlertProcessor.executeAllAlerts(_alertsHolder.getAlertList(), _statsHolder.getStatsList());
- boolean alertFired = alertResult.get(alert).get(AlertProcessor.noWildcardAlertKey).isFired();
- AssertJUnit.assertTrue(alertFired);
- }
-
- @Test(groups = {
- "unitTest"
- })
- public void testSimpleAlertNoStatArrivesFires() {
- String alert = addSimpleAlert();
- String stat = AlertParser.getComponent(AlertParser.EXPRESSION_NAME, alert);
- Map<String, Map<String, AlertValueAndStatus>> alertResult =
- AlertProcessor.executeAllAlerts(_alertsHolder.getAlertList(), _statsHolder.getStatsList());
- AssertJUnit.assertEquals(null, alertResult.get(AlertProcessor.noWildcardAlertKey));
- }
-
- @Test(groups = {
- "unitTest"
- })
- public void testWildcardAlertFires() {
- String alert = addWildcardAlert();
- String stat = AlertParser.getComponent(AlertParser.EXPRESSION_NAME, alert);
- String incomingStatName = addArrivingSimpleStat();
-
- Map<String, Map<String, AlertValueAndStatus>> alertResult =
- AlertProcessor.executeAllAlerts(_alertsHolder.getAlertList(), _statsHolder.getStatsList());
- String wildcardBinding = incomingStatName;
- boolean alertFired = alertResult.get(alert).get(wildcardBinding).isFired();
- AssertJUnit.assertTrue(alertFired);
- }
-
- @Test(groups = {
- "unitTest"
- })
- public void testExpandOperatorWildcardAlertFires() {
- String alert = addExpandWildcardAlert();
- String stat = AlertParser.getComponent(AlertParser.EXPRESSION_NAME, alert);
- String incomingStatName = addArrivingSimpleStat();
- Map<String, Map<String, AlertValueAndStatus>> alertResult =
- AlertProcessor.executeAllAlerts(_alertsHolder.getAlertList(), _statsHolder.getStatsList());
- String wildcardBinding = incomingStatName;
- boolean alertFired = alertResult.get(alert).get(wildcardBinding).isFired();
- AssertJUnit.assertTrue(alertFired);
- }
-
- @Test(groups = {
- "unitTest"
- })
- public void testExpandSumOperatorAlertFires() {
- String alert = addExpandSumAlert();
- String stat = AlertParser.getComponent(AlertParser.EXPRESSION_NAME, alert);
- addArrivingPairOfStats();
- Map<String, Map<String, AlertValueAndStatus>> alertResult =
- AlertProcessor.executeAllAlerts(_alertsHolder.getAlertList(), _statsHolder.getStatsList());
- boolean alertFired = alertResult.get(alert).get(AlertProcessor.noWildcardAlertKey).isFired();
- AssertJUnit.assertTrue(alertFired);
- }
-
- /**
- * We need to re-decide how to support the feature to specify more than one stats in
- * an alert.
- * Probabaly instead of
- * "(dbFoo.partition*.success,dbFoo.partition*.failure)", use the form
- * "(dbFoo.partition*.(success, failure))" as it seems that the stat source is always the
- * same.
- *
- //@Test (groups = {"unitTest"})
- * public void testExpandSumOperatorWildcardAlert()
- * {
- * String alert = addExpandSumWildcardAlert();
- * String stat = AlertParser.getComponent(AlertParser.EXPRESSION_NAME, alert);
- * String part10SuccStat = "dbFoo.partition10.success";
- * String part10FailStat = "dbFoo.partition10.failure";
- * String part11SuccStat = "dbFoo.partition11.success";
- * String part11FailStat = "dbFoo.partition11.failure";
- * Map<String, String> statFields = getStatFields("50","0");
- * _statsHolder.applyStat(part10SuccStat, statFields);
- * statFields = getStatFields("51","0");
- * _statsHolder.applyStat(part10FailStat, statFields);
- * statFields = getStatFields("50","0");
- * _statsHolder.applyStat(part11SuccStat, statFields);
- * statFields = getStatFields("49","0");
- * _statsHolder.applyStat(part11FailStat, statFields);
- * Map<String, Map<String, AlertValueAndStatus>> alertResult =
- * AlertProcessor.executeAllAlerts(_alertsHolder.getAlertList(), _statsHolder.getStatsList());
- * boolean alertFired = alertResult.get(alert).get("10").isFired(); //10 should fire
- * AssertJUnit.assertTrue(alertFired);
- * alertFired = alertResult.get(alert).get("11").isFired(); //11 should not fire
- * AssertJUnit.assertFalse(alertFired);
- * }
- * //@Test (groups = {"unitTest"})
- * public void testExpandSumEachSumOperatorWildcardAlert()
- * {
- * String alert = addExpandSumEachSumWildcardAlert();
- * String stat = AlertParser.getComponent(AlertParser.EXPRESSION_NAME, alert);
- * String part10SuccStat = "dbFoo.partition10.success";
- * String part10FailStat = "dbFoo.partition10.failure";
- * String part11SuccStat = "dbFoo.partition11.success";
- * String part11FailStat = "dbFoo.partition11.failure";
- * Map<String, String> statFields = getStatFields("50","0");
- * _statsHolder.applyStat(part10SuccStat, statFields);
- * statFields = getStatFields("51","0");
- * _statsHolder.applyStat(part10FailStat, statFields);
- * statFields = getStatFields("50","0");
- * _statsHolder.applyStat(part11SuccStat, statFields);
- * statFields = getStatFields("49","0");
- * _statsHolder.applyStat(part11FailStat, statFields);
- * Map<String, Map<String, AlertValueAndStatus>> alertResult =
- * AlertProcessor.executeAllAlerts(_alertsHolder.getAlertList(), _statsHolder.getStatsList());
- * boolean alertFired = alertResult.get(alert).get(_statsHolder.getStatsList().get(0)).isFired();
- * //10 should fire
- * AssertJUnit.assertTrue(alertFired);
- * }
- * //@Test (groups = {"unitTest"})
- * public void testTwoAlerts()
- * {
- * //alert 1
- * String alert1 = addSimpleAlert();
- * String stat = AlertParser.getComponent(AlertParser.EXPRESSION_NAME, alert1);
- * addArrivingSimpleStat();
- * //alert 2
- * String alert2 = addExpandSumWildcardAlert();
- * stat = AlertParser.getComponent(AlertParser.EXPRESSION_NAME, alert2);
- * String part10SuccStat = "dbFoo.partition10.success";
- * String part10FailStat = "dbFoo.partition10.failure";
- * String part11SuccStat = "dbFoo.partition11.success";
- * String part11FailStat = "dbFoo.partition11.failure";
- * Map<String, String> statFields = getStatFields("50","0");
- * _statsHolder.applyStat(part10SuccStat, statFields);
- * statFields = getStatFields("51","0");
- * _statsHolder.applyStat(part10FailStat, statFields);
- * statFields = getStatFields("50","0");
- * _statsHolder.applyStat(part11SuccStat, statFields);
- * statFields = getStatFields("49","0");
- * _statsHolder.applyStat(part11FailStat, statFields);
- * Map<String, Map<String, AlertValueAndStatus>> alertResult =
- * AlertProcessor.executeAllAlerts(_alertsHolder.getAlertList(), _statsHolder.getStatsList());
- * //alert 1 check
- * boolean alertFired = alertResult.get(alert1).get(AlertProcessor.noWildcardAlertKey).isFired();
- * AssertJUnit.assertTrue(alertFired);
- * //alert 2 check
- * alertFired = alertResult.get(alert2).get("10").isFired(); //10 should fire
- * AssertJUnit.assertTrue(alertFired);
- * alertFired = alertResult.get(alert2).get("11").isFired(); //11 should not fire
- * AssertJUnit.assertFalse(alertFired);
- * }
- */
- @Test(groups = {
- "unitTest"
- })
- public void testAddWildcardInFirstStatToken() throws Exception {
- String alert = "EXP(decay(1)(instance*.reportingage))CMP(GREATER)CON(300)";
- _alertsHolder.addAlert(alert);
- _statsHolder.persistStats();
-
- _statsHolder.refreshStats();
- // generate incoming stat
- String incomingStatName = "instance10.reportingage";
- Map<String, String> statFields = getStatFields("301", "10");
- _statsHolder.refreshStats();
-
- _statsHolder.applyStat(incomingStatName, statFields);
- _statsHolder.persistStats();
-
- Map<String, Map<String, AlertValueAndStatus>> alertResult =
- AlertProcessor.executeAllAlerts(_alertsHolder.getAlertList(), _statsHolder.getStatsList());
- String wildcardBinding = incomingStatName;
- boolean alertFired = alertResult.get(alert).get(wildcardBinding).isFired();
- AssertJUnit.assertTrue(alertFired);
- }
-
- @Test(groups = {
- "unitTest"
- })
- public void testTwoWildcardAlertFires() {
- // error is with * and )
- String alert = addTwoWildcardAlert();
- String stat = AlertParser.getComponent(AlertParser.EXPRESSION_NAME, alert);
- String incomingStatName = "dbFoo.partition10.putCount";
- Map<String, String> statFields = getStatFields("110", "0");
- _statsHolder.refreshStats();
- _statsHolder.applyStat(incomingStatName, statFields);
- _statsHolder.persistStats();
- Map<String, Map<String, AlertValueAndStatus>> alertResult =
- AlertProcessor.executeAllAlerts(_alertsHolder.getAlertList(), _statsHolder.getStatsList());
- String wildcardBinding = incomingStatName; // XXX: this is not going to work...need "Count" in
- // here too.
- boolean alertFired = alertResult.get(alert).get(wildcardBinding).isFired();
- AssertJUnit.assertTrue(alertFired);
- }
-
- /*
- * only supporting wildcards at end of components right now
- * @Test (groups = {"unitTest"})
- * public void testTwoWildcardsNotAtEndFires()
- * {
- * String alert = EXP + "(accumulate()(dbFoo.partition*.*Count))"
- * + CMP + "(GREATER)" + CON + "(100)";
- * _alertsHolder.addAlert(alert);
- * String incomingStatName = "dbFoo.partition10.putCount";
- * Map<String, String> statFields = getStatFields("110","0");
- * _statsHolder.applyStat(incomingStatName, statFields);
- * Map<String, Map<String, AlertValueAndStatus>> alertResult =
- * AlertProcessor.executeAllAlerts(_alertsHolder.getAlertList(), _statsHolder.getStatsList());
- * String wildcardBinding = "10,put"; //XXX: this is not going to work...need "Count" in here too.
- * boolean alertFired = alertResult.get(alert).get(wildcardBinding).isFired();
- * AssertJUnit.assertTrue(alertFired);
- * }
- */
-
- // test using sumall
- // test using rows where some tuples are null (no stat sent)
- // test with window tuples where some windows are different lengths
- // anything else, look around at the code
-
- // next: review all older tests
- // next: actually write the fired alerts to ZK
-
-}
http://git-wip-us.apache.org/repos/asf/helix/blob/38b43965/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 4e141dc..0000000
--- a/helix-core/src/test/java/org/apache/helix/alerts/TestOperators.java
+++ /dev/null
@@ -1,325 +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 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/38b43965/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 81a2cd4..0000000
--- a/helix-core/src/test/java/org/apache/helix/alerts/TestStatsMatch.java
+++ /dev/null
@@ -1,103 +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.testng.AssertJUnit;
-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/38b43965/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/38b43965/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 2dbf5f6..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.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/38b43965/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 cadbdc7..0000000
--- a/helix-core/src/test/java/org/apache/helix/healthcheck/TestAddDropAlert.java
+++ /dev/null
@@ -1,172 +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.PropertyKey.Builder;
-import org.apache.helix.TestHelper;
-import org.apache.helix.ZNRecord;
-import org.apache.helix.api.State;
-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();
- State fromState = message.getTypedFromState();
- State toState = message.getTypedToState();
- String instance = message.getTgtName();
-
- if (fromState.toString().equalsIgnoreCase("SLAVE")
- && toState.toString().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/38b43965/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 29f4893..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.PropertyKey.Builder;
-import org.apache.helix.TestHelper;
-import org.apache.helix.ZNRecord;
-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/38b43965/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 a902158..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.PropertyKey.Builder;
-import org.apache.helix.TestHelper;
-import org.apache.helix.ZNRecord;
-import org.apache.helix.alerts.AlertValueAndStatus;
-import org.apache.helix.api.State;
-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();
- State fromState = message.getTypedFromState();
- State toState = message.getTypedToState();
- String instance = message.getTgtName();
-
- if (fromState.toString().equalsIgnoreCase("SLAVE")
- && toState.toString().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()));
- }
-}