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 2013/08/21 22:43:31 UTC
[18/51] [partial] [HELIX-198] Unify helix code style, rb=13710
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/f414aad4/helix-core/src/test/java/org/apache/helix/ZkUnitTestBase.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/ZkUnitTestBase.java b/helix-core/src/test/java/org/apache/helix/ZkUnitTestBase.java
index c61a4ac..abf75be 100644
--- a/helix-core/src/test/java/org/apache/helix/ZkUnitTestBase.java
+++ b/helix-core/src/test/java/org/apache/helix/ZkUnitTestBase.java
@@ -58,10 +58,8 @@ import org.testng.AssertJUnit;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
-
// TODO merge code with ZkIntegrationTestBase
-public class ZkUnitTestBase
-{
+public class ZkUnitTestBase {
private static Logger LOG = Logger.getLogger(ZkUnitTestBase.class);
protected static ZkServer _zkServer = null;
protected static ZkClient _gZkClient;
@@ -71,8 +69,7 @@ public class ZkUnitTestBase
protected static final String CONTROLLER_CLUSTER_PREFIX = "CONTROLLER_CLUSTER";
@BeforeSuite(alwaysRun = true)
- public void beforeSuite() throws Exception
- {
+ public void beforeSuite() throws Exception {
_zkServer = TestHelper.startZkServer(ZK_ADDR);
AssertJUnit.assertTrue(_zkServer != null);
@@ -84,8 +81,7 @@ public class ZkUnitTestBase
}
@AfterSuite(alwaysRun = true)
- public void afterTest()
- {
+ public void afterTest() {
_gZkClient.close();
TestHelper.stopZkServer(_zkServer);
_zkServer = null;
@@ -95,19 +91,15 @@ public class ZkUnitTestBase
}
- protected String getShortClassName()
- {
+ protected String getShortClassName() {
String className = this.getClass().getName();
return className.substring(className.lastIndexOf('.') + 1);
}
- protected String getCurrentLeader(ZkClient zkClient, String clusterName)
- {
- String leaderPath =
- HelixUtil.getControllerPropertyPath(clusterName, PropertyType.LEADER);
+ protected String getCurrentLeader(ZkClient zkClient, String clusterName) {
+ String leaderPath = HelixUtil.getControllerPropertyPath(clusterName, PropertyType.LEADER);
ZNRecord leaderRecord = zkClient.<ZNRecord> readData(leaderPath);
- if (leaderRecord == null)
- {
+ if (leaderRecord == null) {
return null;
}
@@ -115,11 +107,8 @@ public class ZkUnitTestBase
return leader;
}
- protected void stopCurrentLeader(ZkClient zkClient,
- String clusterName,
- Map<String, Thread> threadMap,
- Map<String, HelixManager> managerMap)
- {
+ protected void stopCurrentLeader(ZkClient zkClient, String clusterName,
+ Map<String, Thread> threadMap, Map<String, HelixManager> managerMap) {
String leader = getCurrentLeader(zkClient, clusterName);
Assert.assertTrue(leader != null);
System.out.println("stop leader:" + leader + " in " + clusterName);
@@ -134,62 +123,46 @@ public class ZkUnitTestBase
thread.interrupt();
boolean isNewLeaderElected = false;
- try
- {
+ try {
// Thread.sleep(2000);
- for (int i = 0; i < 5; i++)
- {
+ for (int i = 0; i < 5; i++) {
Thread.sleep(1000);
String newLeader = getCurrentLeader(zkClient, clusterName);
- if (!newLeader.equals(leader))
- {
+ if (!newLeader.equals(leader)) {
isNewLeaderElected = true;
System.out.println("new leader elected: " + newLeader + " in " + clusterName);
break;
}
}
- }
- catch (InterruptedException e)
- {
+ } catch (InterruptedException e) {
e.printStackTrace();
}
- if (isNewLeaderElected == false)
- {
+ if (isNewLeaderElected == false) {
System.out.println("fail to elect a new leader elected in " + clusterName);
}
AssertJUnit.assertTrue(isNewLeaderElected);
}
- public void verifyInstance(ZkClient zkClient,
- String clusterName,
- String instance,
- boolean wantExists)
- {
+ public void verifyInstance(ZkClient zkClient, String clusterName, String instance,
+ boolean wantExists) {
// String instanceConfigsPath = HelixUtil.getConfigPath(clusterName);
String instanceConfigsPath =
- PropertyPathConfig.getPath(PropertyType.CONFIGS,
- clusterName,
- ConfigScopeProperty.PARTICIPANT.toString());
+ PropertyPathConfig.getPath(PropertyType.CONFIGS, clusterName,
+ ConfigScopeProperty.PARTICIPANT.toString());
String instanceConfigPath = instanceConfigsPath + "/" + instance;
String instancePath = HelixUtil.getInstancePath(clusterName, instance);
AssertJUnit.assertEquals(wantExists, zkClient.exists(instanceConfigPath));
AssertJUnit.assertEquals(wantExists, zkClient.exists(instancePath));
}
- public void verifyResource(ZkClient zkClient,
- String clusterName,
- String resource,
- boolean wantExists)
- {
+ public void verifyResource(ZkClient zkClient, String clusterName, String resource,
+ boolean wantExists) {
String resourcePath = HelixUtil.getIdealStatePath(clusterName) + "/" + resource;
AssertJUnit.assertEquals(wantExists, zkClient.exists(resourcePath));
}
- public void verifyEnabled(ZkClient zkClient,
- String clusterName,
- String instance,
- boolean wantEnabled)
- {
+ public void verifyEnabled(ZkClient zkClient, String clusterName, String instance,
+ boolean wantEnabled) {
ZKHelixDataAccessor accessor =
new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor(zkClient));
Builder keyBuilder = accessor.keyBuilder();
@@ -198,51 +171,36 @@ public class ZkUnitTestBase
AssertJUnit.assertEquals(wantEnabled, config.getInstanceEnabled());
}
- public void verifyReplication(ZkClient zkClient,
- String clusterName,
- String resource,
- int repl)
- {
+ public void verifyReplication(ZkClient zkClient, String clusterName, String resource, int repl) {
ZKHelixDataAccessor accessor =
new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor(zkClient));
Builder keyBuilder = accessor.keyBuilder();
IdealState idealState = accessor.getProperty(keyBuilder.idealStates(resource));
- for (String partitionName : idealState.getPartitionSet())
- {
- if (idealState.getRebalanceMode() == RebalanceMode.SEMI_AUTO)
- {
+ for (String partitionName : idealState.getPartitionSet()) {
+ if (idealState.getRebalanceMode() == RebalanceMode.SEMI_AUTO) {
AssertJUnit.assertEquals(repl, idealState.getPreferenceList(partitionName).size());
- }
- else if (idealState.getRebalanceMode() == RebalanceMode.CUSTOMIZED)
- {
- AssertJUnit.assertEquals(repl, idealState.getInstanceStateMap(partitionName)
- .size());
+ } else if (idealState.getRebalanceMode() == RebalanceMode.CUSTOMIZED) {
+ AssertJUnit.assertEquals(repl, idealState.getInstanceStateMap(partitionName).size());
}
}
}
protected void simulateSessionExpiry(ZkConnection zkConnection) throws IOException,
- InterruptedException
- {
+ InterruptedException {
ZooKeeper oldZookeeper = zkConnection.getZookeeper();
LOG.info("Old sessionId = " + oldZookeeper.getSessionId());
- Watcher watcher = new Watcher()
- {
+ Watcher watcher = new Watcher() {
@Override
- public void process(WatchedEvent event)
- {
+ public void process(WatchedEvent event) {
LOG.info("In New connection, process event:" + event);
}
};
ZooKeeper newZookeeper =
- new ZooKeeper(zkConnection.getServers(),
- oldZookeeper.getSessionTimeout(),
- watcher,
- oldZookeeper.getSessionId(),
- oldZookeeper.getSessionPasswd());
+ new ZooKeeper(zkConnection.getServers(), oldZookeeper.getSessionTimeout(), watcher,
+ oldZookeeper.getSessionId(), oldZookeeper.getSessionPasswd());
LOG.info("New sessionId = " + newZookeeper.getSessionId());
// Thread.sleep(3000);
newZookeeper.close();
@@ -251,20 +209,15 @@ public class ZkUnitTestBase
LOG.info("After session expiry sessionId = " + oldZookeeper.getSessionId());
}
- protected void simulateSessionExpiry(ZkClient zkClient) throws IOException,
- InterruptedException
- {
- IZkStateListener listener = new IZkStateListener()
- {
+ protected void simulateSessionExpiry(ZkClient zkClient) throws IOException, InterruptedException {
+ IZkStateListener listener = new IZkStateListener() {
@Override
- public void handleStateChanged(KeeperState state) throws Exception
- {
+ public void handleStateChanged(KeeperState state) throws Exception {
LOG.info("In Old connection, state changed:" + state);
}
@Override
- public void handleNewSession() throws Exception
- {
+ public void handleNewSession() throws Exception {
LOG.info("In Old connection, new session");
}
};
@@ -273,21 +226,16 @@ public class ZkUnitTestBase
ZooKeeper oldZookeeper = connection.getZookeeper();
LOG.info("Old sessionId = " + oldZookeeper.getSessionId());
- Watcher watcher = new Watcher()
- {
+ Watcher watcher = new Watcher() {
@Override
- public void process(WatchedEvent event)
- {
+ public void process(WatchedEvent event) {
LOG.info("In New connection, process event:" + event);
}
};
ZooKeeper newZookeeper =
- new ZooKeeper(connection.getServers(),
- oldZookeeper.getSessionTimeout(),
- watcher,
- oldZookeeper.getSessionId(),
- oldZookeeper.getSessionPasswd());
+ new ZooKeeper(connection.getServers(), oldZookeeper.getSessionTimeout(), watcher,
+ oldZookeeper.getSessionId(), oldZookeeper.getSessionPasswd());
LOG.info("New sessionId = " + newZookeeper.getSessionId());
// Thread.sleep(3000);
newZookeeper.close();
@@ -297,8 +245,7 @@ public class ZkUnitTestBase
LOG.info("After session expiry sessionId = " + oldZookeeper.getSessionId());
}
- protected void setupStateModel(String clusterName)
- {
+ protected void setupStateModel(String clusterName) {
ZKHelixDataAccessor accessor =
new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor(_gZkClient));
Builder keyBuilder = accessor.keyBuilder();
@@ -318,31 +265,23 @@ public class ZkUnitTestBase
}
- protected List<IdealState> setupIdealState(String clusterName,
- int[] nodes,
- String[] resources,
- int partitions,
- int replicas)
- {
+ protected List<IdealState> setupIdealState(String clusterName, int[] nodes, String[] resources,
+ int partitions, int replicas) {
ZKHelixDataAccessor accessor =
new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor(_gZkClient));
Builder keyBuilder = accessor.keyBuilder();
List<IdealState> idealStates = new ArrayList<IdealState>();
List<String> instances = new ArrayList<String>();
- for (int i : nodes)
- {
+ for (int i : nodes) {
instances.add("localhost_" + i);
}
- for (String resourceName : resources)
- {
+ for (String resourceName : resources) {
IdealState idealState = new IdealState(resourceName);
- for (int p = 0; p < partitions; p++)
- {
+ for (int p = 0; p < partitions; p++) {
List<String> value = new ArrayList<String>();
- for (int r = 0; r < replicas; r++)
- {
+ for (int r = 0; r < replicas; r++) {
int n = nodes[(p + r) % nodes.length];
value.add("localhost_" + n);
}
@@ -361,14 +300,12 @@ public class ZkUnitTestBase
return idealStates;
}
- protected void setupLiveInstances(String clusterName, int[] liveInstances)
- {
+ protected void setupLiveInstances(String clusterName, int[] liveInstances) {
ZKHelixDataAccessor accessor =
new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor(_gZkClient));
Builder keyBuilder = accessor.keyBuilder();
- for (int i = 0; i < liveInstances.length; i++)
- {
+ for (int i = 0; i < liveInstances.length; i++) {
String instance = "localhost_" + liveInstances[i];
LiveInstance liveInstance = new LiveInstance(instance);
liveInstance.setSessionId("session_" + liveInstances[i]);
@@ -377,11 +314,9 @@ public class ZkUnitTestBase
}
}
- protected void setupInstances(String clusterName, int[] instances)
- {
+ protected void setupInstances(String clusterName, int[] instances) {
HelixAdmin admin = new ZKHelixAdmin(_gZkClient);
- for (int i = 0; i < instances.length; i++)
- {
+ for (int i = 0; i < instances.length; i++) {
String instance = "localhost_" + instances[i];
InstanceConfig instanceConfig = new InstanceConfig(instance);
instanceConfig.setHostName("localhost");
@@ -391,22 +326,17 @@ public class ZkUnitTestBase
}
}
- protected void runPipeline(ClusterEvent event, Pipeline pipeline)
- {
- try
- {
+ protected void runPipeline(ClusterEvent event, Pipeline pipeline) {
+ try {
pipeline.handle(event);
pipeline.finish();
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
LOG.error("Exception while executing pipeline:" + pipeline
+ ". Will not continue to next pipeline", e);
}
}
- protected void runStage(ClusterEvent event, Stage stage) throws Exception
- {
+ protected void runStage(ClusterEvent event, Stage stage) throws Exception {
StageContext context = new StageContext();
stage.init(context);
stage.preProcess();
@@ -414,13 +344,8 @@ public class ZkUnitTestBase
stage.postProcess();
}
- protected Message createMessage(MessageType type,
- String msgId,
- String fromState,
- String toState,
- String resourceName,
- String tgtName)
- {
+ protected Message createMessage(MessageType type, String msgId, String fromState, String toState,
+ String resourceName, String tgtName) {
Message msg = new Message(type.toString(), msgId);
msg.setFromState(fromState);
msg.setToState(toState);
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/f414aad4/helix-core/src/test/java/org/apache/helix/alerts/TestAddAlerts.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/alerts/TestAddAlerts.java b/helix-core/src/test/java/org/apache/helix/alerts/TestAddAlerts.java
index f41f8a1..4263ddc 100644
--- a/helix-core/src/test/java/org/apache/helix/alerts/TestAddAlerts.java
+++ b/helix-core/src/test/java/org/apache/helix/alerts/TestAddAlerts.java
@@ -32,44 +32,37 @@ import org.testng.AssertJUnit;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
-
-public class TestAddAlerts
-{
+public class TestAddAlerts {
protected static final String CLUSTER_NAME = "TestCluster";
- MockManager _helixManager;
- AlertsHolder _alertsHolder;
+ MockManager _helixManager;
+ AlertsHolder _alertsHolder;
- public final String EXP = AlertParser.EXPRESSION_NAME;
- public final String CMP = AlertParser.COMPARATOR_NAME;
- public final String CON = AlertParser.CONSTANT_NAME;
+ public final String EXP = AlertParser.EXPRESSION_NAME;
+ public final String CMP = AlertParser.COMPARATOR_NAME;
+ public final String CON = AlertParser.CONSTANT_NAME;
@BeforeMethod()
- public void setup()
- {
+ public void setup() {
_helixManager = new MockManager(CLUSTER_NAME);
_alertsHolder = new AlertsHolder(_helixManager, new HealthDataCache());
}
- public boolean alertRecordContains(ZNRecord rec, String alertName)
- {
+ public boolean alertRecordContains(ZNRecord rec, String alertName) {
Map<String, Map<String, String>> alerts = rec.getMapFields();
return alerts.containsKey(alertName);
}
- public int alertsSize(ZNRecord rec)
- {
+ public int alertsSize(ZNRecord rec) {
Map<String, Map<String, String>> alerts = rec.getMapFields();
return alerts.size();
}
@Test()
- public void testAddAlert() throws Exception
- {
+ public void testAddAlert() throws Exception {
String alert =
- EXP + "(accumulate()(dbFoo.partition10.latency))" + CMP + "(GREATER)" + CON
- + "(10)";
+ EXP + "(accumulate()(dbFoo.partition10.latency))" + CMP + "(GREATER)" + CON + "(10)";
_alertsHolder.addAlert(alert);
HelixDataAccessor accessor = _helixManager.getHelixDataAccessor();
Builder keyBuilder = accessor.keyBuilder();
@@ -82,14 +75,11 @@ public class TestAddAlerts
}
@Test()
- public void testAddTwoAlerts() throws Exception
- {
+ public void testAddTwoAlerts() throws Exception {
String alert1 =
- EXP + "(accumulate()(dbFoo.partition10.latency))" + CMP + "(GREATER)" + CON
- + "(10)";
+ EXP + "(accumulate()(dbFoo.partition10.latency))" + CMP + "(GREATER)" + CON + "(10)";
String alert2 =
- EXP + "(accumulate()(dbFoo.partition10.latency))" + CMP + "(GREATER)" + CON
- + "(100)";
+ EXP + "(accumulate()(dbFoo.partition10.latency))" + CMP + "(GREATER)" + CON + "(100)";
_alertsHolder.addAlert(alert1);
_alertsHolder.addAlert(alert2);
@@ -104,13 +94,14 @@ public class TestAddAlerts
AssertJUnit.assertEquals(2, alertsSize(rec));
}
- @Test(groups = { "unitTest" })
- public void testAddTwoWildcardAlert() throws Exception
- {
+ @Test(groups = {
+ "unitTest"
+ })
+ public void testAddTwoWildcardAlert() throws Exception {
String alert1 =
EXP + "(accumulate()(dbFoo.partition*.put*))" + CMP + "(GREATER)" + CON + "(10)";
_alertsHolder.addAlert(alert1);
-
+
HelixDataAccessor accessor = _helixManager.getHelixDataAccessor();
Builder keyBuilder = accessor.keyBuilder();
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/f414aad4/helix-core/src/test/java/org/apache/helix/alerts/TestAddPersistentStats.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/alerts/TestAddPersistentStats.java b/helix-core/src/test/java/org/apache/helix/alerts/TestAddPersistentStats.java
index 8e98479..e9e5e32 100644
--- a/helix-core/src/test/java/org/apache/helix/alerts/TestAddPersistentStats.java
+++ b/helix-core/src/test/java/org/apache/helix/alerts/TestAddPersistentStats.java
@@ -32,37 +32,35 @@ import org.testng.AssertJUnit;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
-
-public class TestAddPersistentStats
-{
+public class TestAddPersistentStats {
protected static final String CLUSTER_NAME = "TestCluster";
- MockManager _helixManager;
- StatsHolder _statsHolder;
+ MockManager _helixManager;
+ StatsHolder _statsHolder;
- @BeforeMethod(groups = { "unitTest" })
- public void setup()
- {
+ @BeforeMethod(groups = {
+ "unitTest"
+ })
+ public void setup() {
_helixManager = new MockManager(CLUSTER_NAME);
_statsHolder = new StatsHolder(_helixManager, new HealthDataCache());
}
- public boolean statRecordContains(ZNRecord rec, String statName)
- {
+ public boolean statRecordContains(ZNRecord rec, String statName) {
Map<String, Map<String, String>> stats = rec.getMapFields();
return stats.containsKey(statName);
}
- public int statsSize(ZNRecord rec)
- {
+ public int statsSize(ZNRecord rec) {
Map<String, Map<String, String>> stats = rec.getMapFields();
return stats.size();
}
- @Test(groups = { "unitTest" })
- public void testAddStat() throws Exception
- {
+ @Test(groups = {
+ "unitTest"
+ })
+ public void testAddStat() throws Exception {
String stat = "window(5)(dbFoo.partition10.latency)";
_statsHolder.addStat(stat);
_statsHolder.persistStats();
@@ -76,9 +74,10 @@ public class TestAddPersistentStats
AssertJUnit.assertEquals(1, statsSize(rec));
}
- @Test(groups = { "unitTest" })
- public void testAddTwoStats() throws Exception
- {
+ @Test(groups = {
+ "unitTest"
+ })
+ public void testAddTwoStats() throws Exception {
String stat1 = "window(5)(dbFoo.partition10.latency)";
_statsHolder.addStat(stat1);
_statsHolder.persistStats();
@@ -97,9 +96,10 @@ public class TestAddPersistentStats
AssertJUnit.assertEquals(2, statsSize(rec));
}
- @Test(groups = { "unitTest" })
- public void testAddDuplicateStat() throws Exception
- {
+ @Test(groups = {
+ "unitTest"
+ })
+ public void testAddDuplicateStat() throws Exception {
String stat = "window(5)(dbFoo.partition10.latency)";
_statsHolder.addStat(stat);
_statsHolder.addStat(stat);
@@ -115,9 +115,10 @@ public class TestAddPersistentStats
AssertJUnit.assertEquals(1, statsSize(rec));
}
- @Test(groups = { "unitTest" })
- public void testAddPairOfStats() throws Exception
- {
+ @Test(groups = {
+ "unitTest"
+ })
+ public void testAddPairOfStats() throws Exception {
String exp = "accumulate()(dbFoo.partition10.latency, dbFoo.partition10.count)";
_statsHolder.addStat(exp);
_statsHolder.persistStats();
@@ -127,16 +128,15 @@ public class TestAddPersistentStats
ZNRecord rec = accessor.getProperty(keyBuilder.persistantStat()).getRecord();
System.out.println("rec: " + rec.toString());
- AssertJUnit.assertTrue(statRecordContains(rec,
- "accumulate()(dbFoo.partition10.latency)"));
- AssertJUnit.assertTrue(statRecordContains(rec,
- "accumulate()(dbFoo.partition10.count)"));
+ AssertJUnit.assertTrue(statRecordContains(rec, "accumulate()(dbFoo.partition10.latency)"));
+ AssertJUnit.assertTrue(statRecordContains(rec, "accumulate()(dbFoo.partition10.count)"));
AssertJUnit.assertEquals(2, statsSize(rec));
}
- @Test(groups = { "unitTest" })
- public void testAddStatsWithOperators() throws Exception
- {
+ @Test(groups = {
+ "unitTest"
+ })
+ public void testAddStatsWithOperators() throws Exception {
String exp =
"accumulate()(dbFoo.partition10.latency, dbFoo.partition10.count)|EACH|ACCUMULATE|DIVIDE";
_statsHolder.addStat(exp);
@@ -148,72 +148,62 @@ public class TestAddPersistentStats
ZNRecord rec = accessor.getProperty(keyBuilder.persistantStat()).getRecord();
System.out.println("rec: " + rec.toString());
- AssertJUnit.assertTrue(statRecordContains(rec,
- "accumulate()(dbFoo.partition10.latency)"));
- AssertJUnit.assertTrue(statRecordContains(rec,
- "accumulate()(dbFoo.partition10.count)"));
+ AssertJUnit.assertTrue(statRecordContains(rec, "accumulate()(dbFoo.partition10.latency)"));
+ AssertJUnit.assertTrue(statRecordContains(rec, "accumulate()(dbFoo.partition10.count)"));
AssertJUnit.assertEquals(2, statsSize(rec));
}
- @Test(groups = { "unitTest" })
- public void testAddNonExistentAggregator() throws Exception
- {
+ @Test(groups = {
+ "unitTest"
+ })
+ public void testAddNonExistentAggregator() throws Exception {
String exp = "fakeagg()(dbFoo.partition10.latency)";
boolean caughtException = false;
- try
- {
+ try {
_statsHolder.addStat(exp);
- }
- catch (HelixException e)
- {
+ } catch (HelixException e) {
caughtException = true;
}
AssertJUnit.assertTrue(caughtException);
}
- @Test(groups = { "unitTest" })
- public void testGoodAggregatorBadArgs() throws Exception
- {
+ @Test(groups = {
+ "unitTest"
+ })
+ public void testGoodAggregatorBadArgs() throws Exception {
String exp = "accumulate(10)(dbFoo.partition10.latency)";
boolean caughtException = false;
- try
- {
+ try {
_statsHolder.addStat(exp);
- }
- catch (HelixException e)
- {
+ } catch (HelixException e) {
caughtException = true;
}
AssertJUnit.assertTrue(caughtException);
}
- @Test(groups = { "unitTest" })
- public void testAddBadNestingStat1() throws Exception
- {
+ @Test(groups = {
+ "unitTest"
+ })
+ public void testAddBadNestingStat1() throws Exception {
String exp = "window((5)(dbFoo.partition10.latency)";
boolean caughtException = false;
- try
- {
+ try {
_statsHolder.addStat(exp);
- }
- catch (HelixException e)
- {
+ } catch (HelixException e) {
caughtException = true;
}
AssertJUnit.assertTrue(caughtException);
}
- @Test(groups = { "unitTest" })
- public void testAddBadNestingStat2() throws Exception
- {
+ @Test(groups = {
+ "unitTest"
+ })
+ public void testAddBadNestingStat2() throws Exception {
String exp = "window(5)(dbFoo.partition10.latency))";
boolean caughtException = false;
- try
- {
+ try {
_statsHolder.addStat(exp);
- }
- catch (HelixException e)
- {
+ } catch (HelixException e) {
caughtException = true;
}
AssertJUnit.assertTrue(caughtException);
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/f414aad4/helix-core/src/test/java/org/apache/helix/alerts/TestAlertValidation.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/alerts/TestAlertValidation.java b/helix-core/src/test/java/org/apache/helix/alerts/TestAlertValidation.java
index d198855..09a9d93 100644
--- a/helix-core/src/test/java/org/apache/helix/alerts/TestAlertValidation.java
+++ b/helix-core/src/test/java/org/apache/helix/alerts/TestAlertValidation.java
@@ -26,144 +26,144 @@ import org.testng.AssertJUnit;
import org.testng.Assert;
import org.testng.annotations.Test;
-
@Test
public class TestAlertValidation {
- public final String EXP = AlertParser.EXPRESSION_NAME;
- public final String CMP = AlertParser.COMPARATOR_NAME;
- public final String CON = AlertParser.CONSTANT_NAME;
+ public final String EXP = AlertParser.EXPRESSION_NAME;
+ public final String CMP = AlertParser.COMPARATOR_NAME;
+ public final String CON = AlertParser.CONSTANT_NAME;
+
+ @Test
+ public void testSimple() {
+ String alertName =
+ EXP + "(accumulate()(dbFoo.partition10.latency)) " + CMP + "(GREATER) " + CON + "(10)";
+ boolean caughtException = false;
+ try {
+ AlertParser.validateAlert(alertName);
+ } catch (HelixException e) {
+ caughtException = true;
+ e.printStackTrace();
+ }
+ AssertJUnit.assertFalse(caughtException);
+ }
- @Test
- public void testSimple() {
- String alertName = EXP + "(accumulate()(dbFoo.partition10.latency)) "
- + CMP + "(GREATER) " + CON + "(10)";
- boolean caughtException = false;
- try {
- AlertParser.validateAlert(alertName);
- } catch (HelixException e) {
- caughtException = true;
- e.printStackTrace();
- }
- AssertJUnit.assertFalse(caughtException);
- }
-
- @Test
- public void testSingleInSingleOut() {
- String alertName = EXP
- + "(accumulate()(dbFoo.partition10.latency)|EXPAND) " + CMP
- + "(GREATER) " + CON + "(10)";
- boolean caughtException = false;
- try {
- AlertParser.validateAlert(alertName);
- } catch (HelixException e) {
- caughtException = true;
- e.printStackTrace();
- }
- AssertJUnit.assertFalse(caughtException);
- }
+ @Test
+ public void testSingleInSingleOut() {
+ String alertName =
+ EXP + "(accumulate()(dbFoo.partition10.latency)|EXPAND) " + CMP + "(GREATER) " + CON
+ + "(10)";
+ boolean caughtException = false;
+ try {
+ AlertParser.validateAlert(alertName);
+ } catch (HelixException e) {
+ caughtException = true;
+ e.printStackTrace();
+ }
+ AssertJUnit.assertFalse(caughtException);
+ }
- @Test
- public void testDoubleInDoubleOut() {
- String alertName = EXP
- + "(accumulate()(dbFoo.partition10.latency, dbFoo.partition11.latency)|EXPAND) "
- + CMP + "(GREATER) " + CON + "(10)";
- boolean caughtException = false;
- try {
- AlertParser.validateAlert(alertName);
- } catch (HelixException e) {
- caughtException = true;
- e.printStackTrace();
- }
- AssertJUnit.assertTrue(caughtException);
- }
+ @Test
+ public void testDoubleInDoubleOut() {
+ String alertName =
+ EXP + "(accumulate()(dbFoo.partition10.latency, dbFoo.partition11.latency)|EXPAND) " + CMP
+ + "(GREATER) " + CON + "(10)";
+ boolean caughtException = false;
+ try {
+ AlertParser.validateAlert(alertName);
+ } catch (HelixException e) {
+ caughtException = true;
+ e.printStackTrace();
+ }
+ AssertJUnit.assertTrue(caughtException);
+ }
- @Test
- public void testTwoStageOps() {
- String alertName = EXP
- + "(accumulate()(dbFoo.partition*.latency, dbFoo.partition*.count)|EXPAND|DIVIDE) "
- + CMP + "(GREATER) " + CON + "(10)";
- boolean caughtException = false;
- try {
- AlertParser.validateAlert(alertName);
- } catch (HelixException e) {
- caughtException = true;
- e.printStackTrace();
- }
- AssertJUnit.assertFalse(caughtException);
- }
+ @Test
+ public void testTwoStageOps() {
+ String alertName =
+ EXP + "(accumulate()(dbFoo.partition*.latency, dbFoo.partition*.count)|EXPAND|DIVIDE) "
+ + CMP + "(GREATER) " + CON + "(10)";
+ boolean caughtException = false;
+ try {
+ AlertParser.validateAlert(alertName);
+ } catch (HelixException e) {
+ caughtException = true;
+ e.printStackTrace();
+ }
+ AssertJUnit.assertFalse(caughtException);
+ }
- @Test
- public void testTwoListsIntoOne() {
- String alertName = EXP
- + "(accumulate()(dbFoo.partition10.latency, dbFoo.partition11.count)|SUM) "
- + CMP + "(GREATER) " + CON + "(10)";
- boolean caughtException = false;
- try {
- AlertParser.validateAlert(alertName);
- } catch (HelixException e) {
- caughtException = true;
- e.printStackTrace();
- }
- AssertJUnit.assertFalse(caughtException);
- }
+ @Test
+ public void testTwoListsIntoOne() {
+ String alertName =
+ EXP + "(accumulate()(dbFoo.partition10.latency, dbFoo.partition11.count)|SUM) " + CMP
+ + "(GREATER) " + CON + "(10)";
+ boolean caughtException = false;
+ try {
+ AlertParser.validateAlert(alertName);
+ } catch (HelixException e) {
+ caughtException = true;
+ e.printStackTrace();
+ }
+ AssertJUnit.assertFalse(caughtException);
+ }
- @Test
- public void testSumEach() {
- String alertName = EXP
- + "(accumulate()(dbFoo.partition*.latency, dbFoo.partition*.count)|EXPAND|SUMEACH|DIVIDE) "
- + CMP + "(GREATER) " + CON + "(10)";
- boolean caughtException = false;
- try {
- AlertParser.validateAlert(alertName);
- } catch (HelixException e) {
- caughtException = true;
- e.printStackTrace();
- }
- AssertJUnit.assertFalse(caughtException);
- }
+ @Test
+ public void testSumEach() {
+ String alertName =
+ EXP
+ + "(accumulate()(dbFoo.partition*.latency, dbFoo.partition*.count)|EXPAND|SUMEACH|DIVIDE) "
+ + CMP + "(GREATER) " + CON + "(10)";
+ boolean caughtException = false;
+ try {
+ AlertParser.validateAlert(alertName);
+ } catch (HelixException e) {
+ caughtException = true;
+ e.printStackTrace();
+ }
+ AssertJUnit.assertFalse(caughtException);
+ }
- @Test
- public void testNeedTwoTuplesGetOne() {
- String alertName = EXP
- + "(accumulate()(dbFoo.partition*.latency)|EXPAND|DIVIDE) "
- + CMP + "(GREATER) " + CON + "(10)";
- boolean caughtException = false;
- try {
- AlertParser.validateAlert(alertName);
- } catch (HelixException e) {
- caughtException = true;
- e.printStackTrace();
- }
- AssertJUnit.assertTrue(caughtException);
- }
+ @Test
+ public void testNeedTwoTuplesGetOne() {
+ String alertName =
+ EXP + "(accumulate()(dbFoo.partition*.latency)|EXPAND|DIVIDE) " + CMP + "(GREATER) " + CON
+ + "(10)";
+ boolean caughtException = false;
+ try {
+ AlertParser.validateAlert(alertName);
+ } catch (HelixException e) {
+ caughtException = true;
+ e.printStackTrace();
+ }
+ AssertJUnit.assertTrue(caughtException);
+ }
- @Test
- public void testExtraPipe() {
- String alertName = EXP + "(accumulate()(dbFoo.partition10.latency)|) "
- + CMP + "(GREATER) " + CON + "(10)";
- boolean caughtException = false;
- try {
- AlertParser.validateAlert(alertName);
- } catch (HelixException e) {
- caughtException = true;
- e.printStackTrace();
- }
- AssertJUnit.assertTrue(caughtException);
- }
+ @Test
+ public void testExtraPipe() {
+ String alertName =
+ EXP + "(accumulate()(dbFoo.partition10.latency)|) " + CMP + "(GREATER) " + CON + "(10)";
+ boolean caughtException = false;
+ try {
+ AlertParser.validateAlert(alertName);
+ } catch (HelixException e) {
+ caughtException = true;
+ e.printStackTrace();
+ }
+ AssertJUnit.assertTrue(caughtException);
+ }
- @Test
- public void testAlertUnknownOp() {
- String alertName = EXP
- + "(accumulate()(dbFoo.partition10.latency)|BADOP) " + CMP
- + "(GREATER) " + CON + "(10)";
- boolean caughtException = false;
- try {
- AlertParser.validateAlert(alertName);
- } catch (HelixException e) {
- caughtException = true;
- e.printStackTrace();
- }
- AssertJUnit.assertTrue(caughtException);
- }
+ @Test
+ public void testAlertUnknownOp() {
+ String alertName =
+ EXP + "(accumulate()(dbFoo.partition10.latency)|BADOP) " + CMP + "(GREATER) " + CON
+ + "(10)";
+ boolean caughtException = false;
+ try {
+ AlertParser.validateAlert(alertName);
+ } catch (HelixException e) {
+ caughtException = true;
+ e.printStackTrace();
+ }
+ AssertJUnit.assertTrue(caughtException);
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/f414aad4/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
index d4b43b2..848ef5a 100644
--- a/helix-core/src/test/java/org/apache/helix/alerts/TestArrivingParticipantStats.java
+++ b/helix-core/src/test/java/org/apache/helix/alerts/TestArrivingParticipantStats.java
@@ -33,53 +33,49 @@ import org.testng.AssertJUnit;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
-
-public class TestArrivingParticipantStats
-{
+public class TestArrivingParticipantStats {
protected static final String CLUSTER_NAME = "TestCluster";
- MockManager _helixManager;
- StatsHolder _statsHolder;
+ MockManager _helixManager;
+ StatsHolder _statsHolder;
- @BeforeMethod(groups = { "unitTest" })
- public void setup()
- {
+ @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)
- {
+ 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)
- {
+ 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)
- {
+ 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)
- {
+ 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
- {
+ @Test(groups = {
+ "unitTest"
+ })
+ public void testAddFirstParticipantStat() throws Exception {
// add a persistent stat
String persistentStat = "accumulate()(dbFoo.partition10.latency)";
_statsHolder.addStat(persistentStat);
@@ -102,9 +98,10 @@ public class TestArrivingParticipantStats
}
// Exact matching persistent stat, but has no values yet
- @Test(groups = { "unitTest" })
- public void testAddRepeatParticipantStat() throws Exception
- {
+ @Test(groups = {
+ "unitTest"
+ })
+ public void testAddRepeatParticipantStat() throws Exception {
// add a persistent stat
String persistentStat = "accumulate()(dbFoo.partition10.latency)";
_statsHolder.addStat(persistentStat);
@@ -130,9 +127,10 @@ public class TestArrivingParticipantStats
}
// test to ensure backdated stats not applied
- @Test(groups = { "unitTest" })
- public void testBackdatedParticipantStat() throws Exception
- {
+ @Test(groups = {
+ "unitTest"
+ })
+ public void testBackdatedParticipantStat() throws Exception {
// add a persistent stat
String persistentStat = "accumulate()(dbFoo.partition10.latency)";
_statsHolder.addStat(persistentStat);
@@ -162,9 +160,10 @@ public class TestArrivingParticipantStats
}
// Exact matching persistent stat, but has no values yet
- @Test(groups = { "unitTest" })
- public void testAddFirstParticipantStatToWildCard() throws Exception
- {
+ @Test(groups = {
+ "unitTest"
+ })
+ public void testAddFirstParticipantStatToWildCard() throws Exception {
// add a persistent stat
String persistentWildcardStat = "accumulate()(dbFoo.partition*.latency)";
_statsHolder.addStat(persistentWildcardStat);
@@ -188,9 +187,10 @@ public class TestArrivingParticipantStats
}
// test to add 2nd report to same stat
- @Test(groups = { "unitTest" })
- public void testAddSecondParticipantStatToWildCard() throws Exception
- {
+ @Test(groups = {
+ "unitTest"
+ })
+ public void testAddSecondParticipantStatToWildCard() throws Exception {
// add a persistent stat
String persistentWildcardStat = "accumulate()(dbFoo.partition*.latency)";
_statsHolder.addStat(persistentWildcardStat);
@@ -216,9 +216,10 @@ public class TestArrivingParticipantStats
}
// Exact matching persistent stat, but has no values yet
- @Test(groups = { "unitTest" })
- public void testAddParticipantStatToDoubleWildCard() throws Exception
- {
+ @Test(groups = {
+ "unitTest"
+ })
+ public void testAddParticipantStatToDoubleWildCard() throws Exception {
// add a persistent stat
String persistentWildcardStat = "accumulate()(db*.partition*.latency)";
_statsHolder.addStat(persistentWildcardStat);
@@ -241,9 +242,10 @@ public class TestArrivingParticipantStats
AssertJUnit.assertTrue(statRecordHasTimestamp(rec, persistentStat, "0.0"));
}
- @Test(groups = { "unitTest" })
- public void testAddWildcardInFirstStatToken() throws Exception
- {
+ @Test(groups = {
+ "unitTest"
+ })
+ public void testAddWildcardInFirstStatToken() throws Exception {
String persistentWildcardStat = "accumulate()(instance*.reportingage)";
_statsHolder.addStat(persistentWildcardStat);
@@ -267,9 +269,10 @@ public class TestArrivingParticipantStats
}
// test to add report to same wildcard stat, different actual stat
- @Test(groups = { "unitTest" })
- public void testAddTwoDistinctParticipantStatsToSameWildCard() throws Exception
- {
+ @Test(groups = {
+ "unitTest"
+ })
+ public void testAddTwoDistinctParticipantStatsToSameWildCard() throws Exception {
// add a persistent stat
String persistentWildcardStat = "accumulate()(dbFoo.partition*.latency)";
_statsHolder.addStat(persistentWildcardStat);
@@ -299,9 +302,10 @@ public class TestArrivingParticipantStats
}
// Exact matching persistent stat, but has no values yet
- @Test(groups = { "unitTest" })
- public void testWindowStat() throws Exception
- {
+ @Test(groups = {
+ "unitTest"
+ })
+ public void testWindowStat() throws Exception {
// add a persistent stat
String persistentWildcardStat = "window(3)(dbFoo.partition*.latency)";
_statsHolder.addStat(persistentWildcardStat);
@@ -338,7 +342,7 @@ public class TestArrivingParticipantStats
statFields = getStatFields("20", "2");
_statsHolder.applyStat(incomingStatName, statFields);
_statsHolder.persistStats();
-
+
rec = accessor.getProperty(keyBuilder.persistantStat()).getRecord();
System.out.println("rec: " + rec.toString());
@@ -347,9 +351,10 @@ public class TestArrivingParticipantStats
}
- @Test(groups = { "unitTest" })
- public void testWindowStatExpiration() throws Exception
- {
+ @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
@@ -370,9 +375,10 @@ public class TestArrivingParticipantStats
AssertJUnit.assertTrue(statRecordHasTimestamp(rec, persistentStat, "1.0,2.0,3.0"));
}
- @Test(groups = { "unitTest" })
- public void testWindowStatStale() throws Exception
- {
+ @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
@@ -395,9 +401,10 @@ public class TestArrivingParticipantStats
// 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
- {
+ @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)";
@@ -426,9 +433,10 @@ public class TestArrivingParticipantStats
}
// test merging 2 window stats, new is applied
- @Test(groups = { "unitTest" })
- public void testMergeTwoWindowsYesMerge() throws Exception
- {
+ @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";
@@ -442,8 +450,7 @@ public class TestArrivingParticipantStats
valTuple.add("40.0");
timeTuple.add("3.0");
timeTuple.add("4.0");
- Map<String, String> statFields =
- getStatFields(valTuple.toString(), timeTuple.toString());
+ Map<String, String> statFields = getStatFields(valTuple.toString(), timeTuple.toString());
_statsHolder.applyStat(incomingStatName, statFields);
_statsHolder.persistStats();
@@ -458,9 +465,10 @@ public class TestArrivingParticipantStats
}
// test merging 2 window stats, new is ignored
- @Test(groups = { "unitTest" })
- public void testMergeTwoWindowsNoMerge() throws Exception
- {
+ @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";
@@ -474,8 +482,7 @@ public class TestArrivingParticipantStats
valTuple.add("40.0");
timeTuple.add("0.0");
timeTuple.add("4.0");
- Map<String, String> statFields =
- getStatFields(valTuple.toString(), timeTuple.toString());
+ Map<String, String> statFields = getStatFields(valTuple.toString(), timeTuple.toString());
_statsHolder.applyStat(incomingStatName, statFields);
_statsHolder.persistStats();
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/f414aad4/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
index 326b752..5183182 100644
--- a/helix-core/src/test/java/org/apache/helix/alerts/TestBaseStatsValidation.java
+++ b/helix-core/src/test/java/org/apache/helix/alerts/TestBaseStatsValidation.java
@@ -27,159 +27,147 @@ import org.testng.AssertJUnit;
import org.testng.Assert;
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]);
- }
-
+
+ @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/incubator-helix/blob/f414aad4/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
index 8606958..403dfdb 100644
--- a/helix-core/src/test/java/org/apache/helix/alerts/TestEvaluateAlerts.java
+++ b/helix-core/src/test/java/org/apache/helix/alerts/TestEvaluateAlerts.java
@@ -34,7 +34,6 @@ import org.testng.AssertJUnit;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
-
public class TestEvaluateAlerts {
protected static final String CLUSTER_NAME = "TestCluster";
@@ -46,350 +45,349 @@ public class TestEvaluateAlerts {
public final String CMP = AlertParser.COMPARATOR_NAME;
public final String CON = AlertParser.CONSTANT_NAME;
- @BeforeMethod (groups = {"unitTest"})
- public void setup()
- {
+ @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>();
+ 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
- {
+ public String getSimpleStat() throws HelixException {
String stat = "accumulate()(dbFoo.partition10.latency)";
- //_statsHolder.addStat(stat);
+ // _statsHolder.addStat(stat);
return stat;
}
- public String addPairOfStats() throws HelixException
- {
+ 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
- {
+ public String getWildcardStat() throws HelixException {
String stat = "accumulate()(dbFoo.partition*.latency)";
- //_statsHolder.addStat(stat);
+ // _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 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 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 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 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 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 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 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 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
- {
+ public String addArrivingSimpleStat() throws HelixException {
_statsHolder.refreshStats();
String incomingStatName = "dbFoo.partition10.latency";
- Map<String, String> statFields = getStatFields("110","0");
+ Map<String, String> statFields = getStatFields("110", "0");
_statsHolder.applyStat(incomingStatName, statFields);
_statsHolder.persistStats();
return incomingStatName;
}
- public String addArrivingPairOfStats() throws HelixException
- {
+ public String addArrivingPairOfStats() throws HelixException {
_statsHolder.refreshStats();
String incomingStatName1 = "dbFoo.partition10.latency";
String incomingStatName2 = "dbFoo.partition11.latency";
- Map<String, String> statFields = getStatFields("50","0");
+ Map<String, String> statFields = getStatFields("50", "0");
_statsHolder.applyStat(incomingStatName1, statFields);
- statFields = getStatFields("51","0");
+ statFields = getStatFields("51", "0");
_statsHolder.applyStat(incomingStatName2, statFields);
_statsHolder.persistStats();
return null;
}
- @Test (groups = {"unitTest"})
- public void testSimpleAlertFires()
- {
+ @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
+ _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());
+ Map<String, Map<String, AlertValueAndStatus>> alertResult =
+ AlertProcessor.executeAllAlerts(_alertsHolder.getAlertList(), _statsHolder.getStatsList());
boolean alertFired = alertResult.get(alert).get(AlertProcessor.noWildcardAlertKey).isFired();
- AssertJUnit.assertTrue(alertFired);
+ AssertJUnit.assertTrue(alertFired);
}
- @Test (groups = {"unitTest"})
- public void testSimpleAlertNoStatArrivesFires()
- {
+ @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());
+ 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()
- {
+ @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());
+ 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()
- {
+ @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());
+ 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()
- {
+ @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());
+ 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);
- }
+ /**
+ * 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();
- //@Test (groups = {"unitTest"})
- public void testTwoAlerts()
- {
- //alert 1
- String alert1 = addSimpleAlert();
- String stat = AlertParser.getComponent(AlertParser.EXPRESSION_NAME, alert1);
- addArrivingSimpleStat();
+ _statsHolder.refreshStats();
+ // generate incoming stat
+ String incomingStatName = "instance10.reportingage";
+ Map<String, String> statFields = getStatFields("301", "10");
+ _statsHolder.refreshStats();
- //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);
+ _statsHolder.applyStat(incomingStatName, statFields);
+ _statsHolder.persistStats();
- //alert 2 check
- alertFired = alertResult.get(alert2).get("10").isFired(); //10 should fire
+ 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);
- 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 )
+
+ @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");
+ 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.
+ 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);
}
- */
-
- //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
-}
\ No newline at end of file
+ /*
+ * 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
+
+}