eagle-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From h..@apache.org
Subject incubator-eagle git commit: [EAGLE-418] Fix unstable unit test case org.apache.eagle.alert.cep.TestSiddhiEvaluator
Date Fri, 05 Aug 2016 08:54:10 GMT
Repository: incubator-eagle
Updated Branches:
  refs/heads/develop c0b902472 -> 2115d0ad5


[EAGLE-418] Fix unstable unit test case org.apache.eagle.alert.cep.TestSiddhiEvaluator

Author: Hao Chen <hao@apache.org>

Closes #306 from haoch/travis.


Project: http://git-wip-us.apache.org/repos/asf/incubator-eagle/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-eagle/commit/2115d0ad
Tree: http://git-wip-us.apache.org/repos/asf/incubator-eagle/tree/2115d0ad
Diff: http://git-wip-us.apache.org/repos/asf/incubator-eagle/diff/2115d0ad

Branch: refs/heads/develop
Commit: 2115d0ad59d675fedfbeb581c62c7e20cc284d31
Parents: c0b9024
Author: Hao Chen <hao@apache.org>
Authored: Fri Aug 5 16:53:52 2016 +0800
Committer: Hao Chen <hao@apache.org>
Committed: Fri Aug 5 16:53:52 2016 +0800

----------------------------------------------------------------------
 .travis.yml                                     | 19 +++++++++++++
 .../eagle/alert/cep/TestSiddhiEvaluator.java    | 30 +++++++++++---------
 2 files changed, 36 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/2115d0ad/.travis.yml
----------------------------------------------------------------------
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..cfe5014
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,19 @@
+# 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.
+
+language: java
+script: mvn clean test
+jdk:
+  - oraclejdk8
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/2115d0ad/eagle-core/eagle-alert-parent/eagle-alert-process/src/test/java/org/apache/eagle/alert/cep/TestSiddhiEvaluator.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-alert-parent/eagle-alert-process/src/test/java/org/apache/eagle/alert/cep/TestSiddhiEvaluator.java
b/eagle-core/eagle-alert-parent/eagle-alert-process/src/test/java/org/apache/eagle/alert/cep/TestSiddhiEvaluator.java
index 036708f..20afc95 100644
--- a/eagle-core/eagle-alert-parent/eagle-alert-process/src/test/java/org/apache/eagle/alert/cep/TestSiddhiEvaluator.java
+++ b/eagle-core/eagle-alert-parent/eagle-alert-process/src/test/java/org/apache/eagle/alert/cep/TestSiddhiEvaluator.java
@@ -34,16 +34,15 @@ import org.apache.eagle.policy.siddhi.SiddhiPolicyEvaluator;
 import org.apache.eagle.policy.siddhi.StreamMetadataManager;
 import org.apache.eagle.service.client.EagleServiceConnector;
 import org.junit.Assert;
+import org.junit.Before;
 import org.junit.Test;
 import scala.Tuple2;
 
 import java.util.*;
+import java.util.concurrent.Semaphore;
 
 public class TestSiddhiEvaluator {
-
-	int alertCount = 0;
-
-	public AlertStreamSchemaEntity createStreamMetaEntity(String attrName, String type) {
+	private AlertStreamSchemaEntity createStreamMetaEntity(String attrName, String type) {
 		AlertStreamSchemaEntity entity = new AlertStreamSchemaEntity();
 		Map<String, String> tags = new HashMap<String, String>();
 		tags.put("application", "hdfsAuditLog");
@@ -54,9 +53,17 @@ public class TestSiddhiEvaluator {
 		return entity;
 	}
 
+	private int alertCount;
+	private Semaphore semaphore;
+	@Before
+	public void before(){
+		alertCount = 0;
+		semaphore = new Semaphore(0);
+	}
+
 	@Test
 	public void test() throws Exception{
-        Config config = ConfigFactory.load("unittest.conf");
+		Config config = ConfigFactory.load("unittest.conf");
 		AlertStreamSchemaDAO streamDao = new AlertStreamSchemaDAOImpl(null, null) {
 			@Override
 			public List<AlertStreamSchemaEntity> findAlertStreamSchemaByApplication(String dataSource)
throws Exception {
@@ -108,7 +115,7 @@ public class TestSiddhiEvaluator {
 		AlertExecutor alertExecutor = new AlertExecutor("alertExecutorId", null, 3, 1, alertDao,
new String[]{"hdfsAuditLogEventStream"}) {
 			@Override
 			protected Map<String, String> getDimensions(String policyId) {
-				return new HashMap<String, String>();
+				return new HashMap<>();
 			}
 		};
 		alertExecutor.prepareConfig(config);
@@ -118,18 +125,15 @@ public class TestSiddhiEvaluator {
 		context.alertExecutor = alertExecutor;
 		context.policyId = "testPolicy";
 		context.resultRender = new SiddhiAlertAPIEntityRender();
-		context.outputCollector = new Collector<Tuple2<String, AlertAPIEntity>> ()
{
-			@Override
-			public void collect(Tuple2<String, AlertAPIEntity> stringAlertAPIEntityTuple2) {
-				alertCount++;
-			}
+		context.outputCollector = (Collector<Tuple2<String, AlertAPIEntity>>) (stringAlertAPIEntityTuple2)
-> {
+			alertCount++;
+			semaphore.release();
 		};
-
 		SiddhiPolicyEvaluator<AlertDefinitionAPIEntity, AlertAPIEntity> evaluator =
 				new SiddhiPolicyEvaluator<>(config, context, policyDef, new String[]{"hdfsAuditLogEventStream"},
false);
-
 		evaluator.evaluate(new ValuesArray(context.outputCollector, "hdfsAuditLogEventStream",
data1));
 		Thread.sleep(2 * 1000);
+		semaphore.acquire();
 		Assert.assertEquals(alertCount, 1);
 	}
 }


Mime
View raw message