eagle-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From h..@apache.org
Subject [1/2] incubator-eagle git commit: [EAGLE-762] Add AlertEmailPublisherTest and improve alert template
Date Fri, 11 Nov 2016 03:40:00 GMT
Repository: incubator-eagle
Updated Branches:
  refs/heads/master 75ab7722c -> 38ec7fc23


http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/38ec7fc2/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/test/java/org/apache/eagle/alert/engine/publisher/dedup/DefaultDedupWithoutStateTest.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/test/java/org/apache/eagle/alert/engine/publisher/dedup/DefaultDedupWithoutStateTest.java
b/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/test/java/org/apache/eagle/alert/engine/publisher/dedup/DefaultDedupWithoutStateTest.java
index 4d42c12..6e59fa2 100644
--- a/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/test/java/org/apache/eagle/alert/engine/publisher/dedup/DefaultDedupWithoutStateTest.java
+++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/test/java/org/apache/eagle/alert/engine/publisher/dedup/DefaultDedupWithoutStateTest.java
@@ -16,168 +16,100 @@
  */
 package org.apache.eagle.alert.engine.publisher.dedup;
 
-import java.util.Arrays;
-import java.util.List;
-import java.util.Random;
-import java.util.concurrent.ConcurrentLinkedDeque;
-
+import com.google.common.base.Joiner;
+import com.typesafe.config.Config;
+import com.typesafe.config.ConfigFactory;
 import org.apache.eagle.alert.engine.coordinator.PolicyDefinition;
-import org.apache.eagle.alert.engine.coordinator.StreamColumn;
 import org.apache.eagle.alert.engine.coordinator.StreamDefinition;
-import org.apache.eagle.alert.engine.coordinator.StreamPartition;
 import org.apache.eagle.alert.engine.model.AlertStreamEvent;
 import org.apache.eagle.alert.engine.publisher.impl.DefaultDeduplicator;
 import org.junit.Assert;
 import org.junit.Test;
 
-import com.google.common.base.Joiner;
-import com.typesafe.config.Config;
-import com.typesafe.config.ConfigFactory;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Random;
+import java.util.concurrent.ConcurrentLinkedDeque;
+
+import static org.apache.eagle.alert.engine.publisher.AlertPublisherTestHelper.*;
 
 public class DefaultDedupWithoutStateTest {
 
-	@Test
-	public void testNormal() throws Exception {
-		//String intervalMin, List<String> customDedupFields, String dedupStateField, String
dedupStateCloseValue
-		// assume state: OPEN, WARN, CLOSE
-		System.setProperty("config.resource", "/application-mongo-statestore.conf");
-		Config config = ConfigFactory.load();
-		DedupCache dedupCache = new DedupCache(config, "testPublishment");
-		DefaultDeduplicator deduplicator = new DefaultDeduplicator(
-				"PT10S", Arrays.asList(new String[] { "alertKey" }), null, null, dedupCache);
-		
-		StreamDefinition stream = createStream();
-		PolicyDefinition policy = createPolicy(stream.getStreamId(), "testPolicy");
-		
-		int[] hostIndex = new int[] { 1, 2, 3 };
-		String[] states = new String[] { "OPEN", "WARN", "CLOSE" };
-		Random random = new Random();
-		
-		final ConcurrentLinkedDeque<AlertStreamEvent> nonDedupResult = new ConcurrentLinkedDeque<AlertStreamEvent>();
-		
-		for (int i = 0; i < 100; i ++) {
-			new Thread(new Runnable() {
-
-				@Override
-				public void run() {
-					int index = hostIndex[random.nextInt(3)];
-					AlertStreamEvent e1 = createEvent(stream, policy, new Object[] {
-							System.currentTimeMillis(), "host" + index, 
-							String.format("testPolicy-host%s-01", index), 
-							states[random.nextInt(3)], 0, 0
-					});
-					List<AlertStreamEvent> result = deduplicator.dedup(e1);
-					if (result != null) {
-						System.out.println(">>>" + Joiner.on(",").join(result));
-						nonDedupResult.addAll(result);
-					} else {
-						System.out.println(">>>" + result);
-					}
-				}
-				
-			}).start();
-		}
-		
-		Thread.sleep(1000);
-		
-		System.out.println("old size: " + nonDedupResult.size());
-		Assert.assertTrue(nonDedupResult.size() > 0 && nonDedupResult.size() <= 3);
-		
-		Thread.sleep(15000);
-		
-		for (int i = 0; i < 100; i ++) {
-			new Thread(new Runnable() {
-
-				@Override
-				public void run() {
-					int index = hostIndex[random.nextInt(3)];
-					AlertStreamEvent e1 = createEvent(stream, policy, new Object[] {
-							System.currentTimeMillis(), "host" + index, 
-							String.format("testPolicy-host%s-01", index), 
-							states[random.nextInt(3)], 0, 0
-					});
-					List<AlertStreamEvent> result = deduplicator.dedup(e1);
-					if (result != null) {
-						System.out.println(">>>" + Joiner.on(",").join(result));
-						nonDedupResult.addAll(result);
-					} else {
-						System.out.println(">>>" + result);
-					}
-				}
-				
-			}).start();
-		}
-		
-		Thread.sleep(1000);
-		
-		System.out.println("new size: " + nonDedupResult.size());
-		Assert.assertTrue(nonDedupResult.size() > 3 && nonDedupResult.size() <= 6);
-	}
-	
-	private AlertStreamEvent createEvent(StreamDefinition stream, PolicyDefinition policy, Object[]
data) {
-		AlertStreamEvent event = new AlertStreamEvent();
-		event.setPolicyId(policy.getName());
-		event.setSchema(stream);
-		event.setStreamId(stream.getStreamId());
-		event.setTimestamp(System.currentTimeMillis());
-		event.setCreatedTime(System.currentTimeMillis());
-		event.setData(data);
-		return event;
-	}
-	
-	private StreamDefinition createStream() {
-		StreamDefinition sd = new StreamDefinition();
-		StreamColumn tsColumn = new StreamColumn();
-		tsColumn.setName("timestamp");
-		tsColumn.setType(StreamColumn.Type.LONG);
-		
-		StreamColumn hostColumn = new StreamColumn();
-		hostColumn.setName("host");
-		hostColumn.setType(StreamColumn.Type.STRING);
-		
-		StreamColumn alertKeyColumn = new StreamColumn();
-		alertKeyColumn.setName("alertKey");
-		alertKeyColumn.setType(StreamColumn.Type.STRING);
-
-		StreamColumn stateColumn = new StreamColumn();
-		stateColumn.setName("state");
-		stateColumn.setType(StreamColumn.Type.STRING);
-		
-		// dedupCount, dedupFirstOccurrence
-		
-		StreamColumn dedupCountColumn = new StreamColumn();
-		dedupCountColumn.setName("dedupCount");
-		dedupCountColumn.setType(StreamColumn.Type.LONG);
-		
-		StreamColumn dedupFirstOccurrenceColumn = new StreamColumn();
-		dedupFirstOccurrenceColumn.setName(DedupCache.DEDUP_FIRST_OCCURRENCE);
-		dedupFirstOccurrenceColumn.setType(StreamColumn.Type.LONG);
-		
-		sd.setColumns(Arrays.asList(tsColumn, hostColumn, alertKeyColumn, stateColumn, dedupCountColumn,
dedupFirstOccurrenceColumn));
-		sd.setDataSource("testDatasource");
-		sd.setStreamId("testStream");
-		sd.setDescription("test stream");
-		return sd;
-	}
-	
-	private PolicyDefinition createPolicy(String streamName, String policyName) {
-		PolicyDefinition pd = new PolicyDefinition();
-		PolicyDefinition.Definition def = new PolicyDefinition.Definition();
-		//expression, something like "PT5S,dynamic,1,host"
-		def.setValue("test");
-		def.setType("siddhi");
-		pd.setDefinition(def);
-		pd.setInputStreams(Arrays.asList("inputStream"));
-		pd.setOutputStreams(Arrays.asList("outputStream"));
-		pd.setName(policyName);
-		pd.setDescription(String.format("Test policy for stream %s", streamName));
-		
-		StreamPartition sp = new StreamPartition();
-		sp.setStreamId(streamName);
-		sp.setColumns(Arrays.asList("host"));
-		sp.setType(StreamPartition.Type.GROUPBY);
-		pd.addPartition(sp);
-		return pd;
-	}
-	
+    @Test
+    public void testNormal() throws Exception {
+        //String intervalMin, List<String> customDedupFields, String dedupStateField,
String dedupStateCloseValue
+        // assume state: OPEN, WARN, CLOSE
+        System.setProperty("config.resource", "/application-mongo-statestore.conf");
+        Config config = ConfigFactory.load();
+        DedupCache dedupCache = new DedupCache(config, "testPublishment");
+        DefaultDeduplicator deduplicator = new DefaultDeduplicator(
+            "PT10S", Arrays.asList(new String[] {"alertKey"}), null, null, dedupCache);
+
+        StreamDefinition stream = createStream();
+        PolicyDefinition policy = createPolicy(stream.getStreamId(), "testPolicy");
+
+        int[] hostIndex = new int[] {1, 2, 3};
+        String[] states = new String[] {"OPEN", "WARN", "CLOSE"};
+        Random random = new Random();
+
+        final ConcurrentLinkedDeque<AlertStreamEvent> nonDedupResult = new ConcurrentLinkedDeque<AlertStreamEvent>();
+
+        for (int i = 0; i < 100; i++) {
+            new Thread(new Runnable() {
+
+                @Override
+                public void run() {
+                    int index = hostIndex[random.nextInt(3)];
+                    AlertStreamEvent e1 = createEvent(stream, policy, new Object[] {
+                        System.currentTimeMillis(), "host" + index,
+                        String.format("testPolicy-host%s-01", index),
+                        states[random.nextInt(3)], 0, 0
+                    });
+                    List<AlertStreamEvent> result = deduplicator.dedup(e1);
+                    if (result != null) {
+                        System.out.println(">>>" + Joiner.on(",").join(result));
+                        nonDedupResult.addAll(result);
+                    } else {
+                        System.out.println(">>>" + result);
+                    }
+                }
+
+            }).start();
+        }
+
+        Thread.sleep(1000);
+
+        System.out.println("old size: " + nonDedupResult.size());
+        Assert.assertTrue(nonDedupResult.size() > 0 && nonDedupResult.size() <=
3);
+
+        Thread.sleep(15000);
+
+        for (int i = 0; i < 100; i++) {
+            new Thread(new Runnable() {
+
+                @Override
+                public void run() {
+                    int index = hostIndex[random.nextInt(3)];
+                    AlertStreamEvent e1 = createEvent(stream, policy, new Object[] {
+                        System.currentTimeMillis(), "host" + index,
+                        String.format("testPolicy-host%s-01", index),
+                        states[random.nextInt(3)], 0, 0
+                    });
+                    List<AlertStreamEvent> result = deduplicator.dedup(e1);
+                    if (result != null) {
+                        System.out.println(">>>" + Joiner.on(",").join(result));
+                        nonDedupResult.addAll(result);
+                    } else {
+                        System.out.println(">>>" + result);
+                    }
+                }
+
+            }).start();
+        }
+
+        Thread.sleep(1000);
+
+        System.out.println("new size: " + nonDedupResult.size());
+        Assert.assertTrue(nonDedupResult.size() > 3 && nonDedupResult.size() <=
6);
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/38ec7fc2/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/test/java/org/apache/eagle/alert/engine/publisher/dedup/DefaultDeduplicatorTest.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/test/java/org/apache/eagle/alert/engine/publisher/dedup/DefaultDeduplicatorTest.java
b/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/test/java/org/apache/eagle/alert/engine/publisher/dedup/DefaultDeduplicatorTest.java
index e6cbe6c..700e3ee 100644
--- a/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/test/java/org/apache/eagle/alert/engine/publisher/dedup/DefaultDeduplicatorTest.java
+++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/test/java/org/apache/eagle/alert/engine/publisher/dedup/DefaultDeduplicatorTest.java
@@ -20,9 +20,7 @@ import com.typesafe.config.Config;
 import com.typesafe.config.ConfigFactory;
 import org.apache.commons.lang.builder.ToStringBuilder;
 import org.apache.eagle.alert.engine.coordinator.PolicyDefinition;
-import org.apache.eagle.alert.engine.coordinator.StreamColumn;
 import org.apache.eagle.alert.engine.coordinator.StreamDefinition;
-import org.apache.eagle.alert.engine.coordinator.StreamPartition;
 import org.apache.eagle.alert.engine.model.AlertStreamEvent;
 import org.apache.eagle.alert.engine.publisher.impl.DefaultDeduplicator;
 import org.junit.Assert;
@@ -32,6 +30,8 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 
+import static org.apache.eagle.alert.engine.publisher.AlertPublisherTestHelper.*;
+
 public class DefaultDeduplicatorTest {
 
     @Test
@@ -173,71 +173,4 @@ public class DefaultDeduplicatorTest {
         }
 
     }
-
-    private AlertStreamEvent createEvent(StreamDefinition stream, PolicyDefinition policy,
Object[] data) {
-        AlertStreamEvent event = new AlertStreamEvent();
-        event.setPolicyId(policy.getName());
-        event.setSchema(stream);
-        event.setStreamId(stream.getStreamId());
-        event.setTimestamp(System.currentTimeMillis());
-        event.setCreatedTime(System.currentTimeMillis());
-        event.setData(data);
-        return event;
-    }
-
-    private StreamDefinition createStream() {
-        StreamDefinition sd = new StreamDefinition();
-        StreamColumn tsColumn = new StreamColumn();
-        tsColumn.setName("timestamp");
-        tsColumn.setType(StreamColumn.Type.LONG);
-
-        StreamColumn hostColumn = new StreamColumn();
-        hostColumn.setName("host");
-        hostColumn.setType(StreamColumn.Type.STRING);
-
-        StreamColumn alertKeyColumn = new StreamColumn();
-        alertKeyColumn.setName("alertKey");
-        alertKeyColumn.setType(StreamColumn.Type.STRING);
-
-        StreamColumn stateColumn = new StreamColumn();
-        stateColumn.setName("state");
-        stateColumn.setType(StreamColumn.Type.STRING);
-
-        // dedupCount, dedupFirstOccurrence
-
-        StreamColumn dedupCountColumn = new StreamColumn();
-        dedupCountColumn.setName("dedupCount");
-        dedupCountColumn.setType(StreamColumn.Type.LONG);
-
-        StreamColumn dedupFirstOccurrenceColumn = new StreamColumn();
-        dedupFirstOccurrenceColumn.setName(DedupCache.DEDUP_FIRST_OCCURRENCE);
-        dedupFirstOccurrenceColumn.setType(StreamColumn.Type.LONG);
-
-        sd.setColumns(Arrays.asList(tsColumn, hostColumn, alertKeyColumn, stateColumn, dedupCountColumn,
dedupFirstOccurrenceColumn));
-        sd.setDataSource("testDatasource");
-        sd.setStreamId("testStream");
-        sd.setDescription("test stream");
-        return sd;
-    }
-
-    private PolicyDefinition createPolicy(String streamName, String policyName) {
-        PolicyDefinition pd = new PolicyDefinition();
-        PolicyDefinition.Definition def = new PolicyDefinition.Definition();
-        //expression, something like "PT5S,dynamic,1,host"
-        def.setValue("test");
-        def.setType("siddhi");
-        pd.setDefinition(def);
-        pd.setInputStreams(Arrays.asList("inputStream"));
-        pd.setOutputStreams(Arrays.asList("outputStream"));
-        pd.setName(policyName);
-        pd.setDescription(String.format("Test policy for stream %s", streamName));
-
-        StreamPartition sp = new StreamPartition();
-        sp.setStreamId(streamName);
-        sp.setColumns(Arrays.asList("host"));
-        sp.setType(StreamPartition.Type.GROUPBY);
-        pd.addPartition(sp);
-        return pd;
-    }
-
 }

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/38ec7fc2/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 0108df4..2479727 100755
--- a/pom.xml
+++ b/pom.xml
@@ -312,7 +312,7 @@
         <metrics-elasticsearch-reporter.version>2.2.0</metrics-elasticsearch-reporter.version>
 
         <common.cli.version>1.3.1</common.cli.version>
-	      <ullink.slack.version>0.6.0</ullink.slack.version>
+        <ullink.slack.version>0.6.0</ullink.slack.version>
         <javax-ws-rs.rs-api.version>2.0.1</javax-ws-rs.rs-api.version>
 
         <!-- dropwizard -->
@@ -1365,4 +1365,4 @@
             <url>http://scala-tools.org/repo-releases</url>
         </pluginRepository>
     </pluginRepositories>
-</project>
+</project>
\ No newline at end of file


Mime
View raw message