Repository: incubator-eagle Updated Branches: refs/heads/master 1da8dc4f1 -> 2b61cef58
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/2b61cef5/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/alert/engine/coordinator/StreamPartitionTest.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/alert/engine/coordinator/StreamPartitionTest.java b/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/alert/engine/coordinator/StreamPartitionTest.java new file mode 100644 index 0000000..f7615df --- /dev/null +++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/alert/engine/coordinator/StreamPartitionTest.java @@ -0,0 +1,43 @@ +/* + * 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 + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * 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. + */ + +package org.apache.eagle.alert.engine.coordinator; + +import org.junit.Assert; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.List; + +public class StreamPartitionTest { + @Test + public void testStreamPartition() { + StreamSortSpec streamSortSpec = new StreamSortSpec(); + streamSortSpec.setWindowPeriod("PT10S"); + StreamPartition streamPartition = new StreamPartition(); + Assert.assertEquals("StreamPartition[streamId=null,type=null,columns=[],sortSpec=[null]]", streamPartition.toString()); + List<String> columns = new ArrayList<>(); + columns.add("jobId"); + streamPartition.setColumns(columns); + streamPartition.setSortSpec(streamSortSpec); + streamPartition.setStreamId("test"); + streamPartition.setType(StreamPartition.Type.GROUPBY); + Assert.assertEquals("StreamPartition[streamId=test,type=GROUPBY,columns=[jobId],sortSpec=[StreamSortSpec[windowPeriod=PT10S,windowMargin=30000]]]", streamPartition.toString()); + Assert.assertTrue(streamPartition.equals(new StreamPartition(streamPartition))); + Assert.assertTrue(streamPartition.hashCode() == new StreamPartition(streamPartition).hashCode()); + } +} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/2b61cef5/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/alert/engine/coordinator/StreamSortSpecTest.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/alert/engine/coordinator/StreamSortSpecTest.java b/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/alert/engine/coordinator/StreamSortSpecTest.java new file mode 100644 index 0000000..d8123f1 --- /dev/null +++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/alert/engine/coordinator/StreamSortSpecTest.java @@ -0,0 +1,45 @@ +/* + * 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 + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * 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. + */ + +package org.apache.eagle.alert.engine.coordinator; + +import org.joda.time.Period; +import org.junit.Assert; +import org.junit.Test; + +public class StreamSortSpecTest { + @Test + public void testStreamSortSpec() { + StreamSortSpec streamSortSpec = new StreamSortSpec(); + Assert.assertEquals(30000, streamSortSpec.getWindowMargin()); + Assert.assertEquals("", streamSortSpec.getWindowPeriod()); + Assert.assertEquals(0, streamSortSpec.getWindowPeriodMillis()); + Assert.assertEquals("StreamSortSpec[windowPeriod=,windowMargin=30000]", streamSortSpec.toString()); + streamSortSpec.setWindowPeriod("PT60S"); + Assert.assertEquals(60000, streamSortSpec.getWindowPeriodMillis()); + Assert.assertEquals("PT60S", streamSortSpec.getWindowPeriod()); + Assert.assertEquals("StreamSortSpec[windowPeriod=PT60S,windowMargin=30000]", streamSortSpec.toString()); + streamSortSpec.setWindowMargin(20); + Assert.assertEquals(20, streamSortSpec.getWindowMargin()); + streamSortSpec.setWindowPeriodMillis(50000); + Assert.assertEquals("StreamSortSpec[windowPeriod=PT50S,windowMargin=20]", streamSortSpec.toString()); + streamSortSpec.setWindowPeriod2(Period.minutes(10)); + Assert.assertEquals("StreamSortSpec[windowPeriod=PT10M,windowMargin=20]", streamSortSpec.toString()); + Assert.assertTrue(streamSortSpec.equals(new StreamSortSpec(streamSortSpec))); + Assert.assertTrue(streamSortSpec.hashCode() == new StreamSortSpec(streamSortSpec).hashCode()); + } +} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/2b61cef5/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/alert/engine/coordinator/StreamingClusterTest.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/alert/engine/coordinator/StreamingClusterTest.java b/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/alert/engine/coordinator/StreamingClusterTest.java new file mode 100644 index 0000000..2b79cf6 --- /dev/null +++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/alert/engine/coordinator/StreamingClusterTest.java @@ -0,0 +1,47 @@ +/* + * 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 + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * 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. + */ + +package org.apache.eagle.alert.engine.coordinator; + +import org.junit.Assert; +import org.junit.Test; + +import java.util.HashMap; + +public class StreamingClusterTest { + @Test + public void testStreamingCluster() { + StreamingCluster cluster = new StreamingCluster(); + cluster.setName("test"); + cluster.setDeployments(new HashMap<>()); + cluster.setDescription("setDescription"); + cluster.setType(StreamingCluster.StreamingType.STORM); + cluster.setZone("setZone"); + + StreamingCluster cluster1 = new StreamingCluster(); + cluster1.setName("test"); + cluster1.setDeployments(new HashMap<>()); + cluster1.setDescription("setDescription"); + cluster1.setType(StreamingCluster.StreamingType.STORM); + cluster1.setZone("setZone"); + + + Assert.assertFalse(cluster == cluster1); + Assert.assertFalse(cluster.equals(cluster1)); + Assert.assertFalse(cluster.hashCode() == cluster1.hashCode()); + } +} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/2b61cef5/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/alert/engine/model/AlertPublishEventTest.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/alert/engine/model/AlertPublishEventTest.java b/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/alert/engine/model/AlertPublishEventTest.java new file mode 100644 index 0000000..d534e3b --- /dev/null +++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/alert/engine/model/AlertPublishEventTest.java @@ -0,0 +1,110 @@ +/* + * 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 + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * 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. + */ + +package org.apache.eagle.alert.engine.model; + +import org.apache.eagle.alert.engine.coordinator.StreamColumn; +import org.apache.eagle.alert.engine.coordinator.StreamDefinition; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +import java.util.*; + +public class AlertPublishEventTest { + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Test + public void testAlertPublishEvent() { + thrown.expect(NullPointerException.class); + AlertStreamEvent alertStreamEvent = new AlertStreamEvent(); + AlertPublishEvent.createAlertPublishEvent(alertStreamEvent); + } + + @Test + public void testAlertPublishEvent1() { + thrown.expect(NullPointerException.class); + List<StreamColumn> streamColumns = new ArrayList<>(); + streamColumns.add(new StreamColumn.Builder().name("name").type(StreamColumn.Type.STRING).build()); + streamColumns.add(new StreamColumn.Builder().name("host").type(StreamColumn.Type.STRING).build()); + streamColumns.add(new StreamColumn.Builder().name("flag").type(StreamColumn.Type.BOOL).build()); + streamColumns.add(new StreamColumn.Builder().name("value").type(StreamColumn.Type.DOUBLE).build()); + streamColumns.add(new StreamColumn.Builder().name("data").type(StreamColumn.Type.LONG).build()); + streamColumns.add(new StreamColumn.Builder().name("salary").type(StreamColumn.Type.FLOAT).build()); + streamColumns.add(new StreamColumn.Builder().name("object").type(StreamColumn.Type.OBJECT).build()); + streamColumns.add(new StreamColumn.Builder().name("int").type(StreamColumn.Type.INT).build()); + + StreamDefinition streamDefinition = new StreamDefinition(); + streamDefinition.setColumns(streamColumns); + AlertStreamEvent alertStreamEvent = new AlertStreamEvent(); + alertStreamEvent.setSchema(streamDefinition); + AlertPublishEvent.createAlertPublishEvent(alertStreamEvent); + } + + @Test + public void testAlertPublishEvent2() { + List<StreamColumn> streamColumns = new ArrayList<>(); + streamColumns.add(new StreamColumn.Builder().name("name").type(StreamColumn.Type.STRING).build()); + streamColumns.add(new StreamColumn.Builder().name("host").type(StreamColumn.Type.STRING).build()); + streamColumns.add(new StreamColumn.Builder().name("flag").type(StreamColumn.Type.BOOL).build()); + streamColumns.add(new StreamColumn.Builder().name("value").type(StreamColumn.Type.DOUBLE).build()); + streamColumns.add(new StreamColumn.Builder().name("data").type(StreamColumn.Type.LONG).build()); + streamColumns.add(new StreamColumn.Builder().name("salary").type(StreamColumn.Type.FLOAT).build()); + streamColumns.add(new StreamColumn.Builder().name("object").type(StreamColumn.Type.OBJECT).build()); + streamColumns.add(new StreamColumn.Builder().name("int").type(StreamColumn.Type.INT).build()); + + StreamDefinition streamDefinition = new StreamDefinition(); + streamDefinition.setColumns(streamColumns); + AlertStreamEvent alertStreamEvent = new AlertStreamEvent(); + alertStreamEvent.setData(new Object[]{"namevalue", "hostvalue", "1", 10, 0.1, -0.2, "{\"name\":\"heap.COMMITTED\", \"Value\":\"175636480\"}", 1}); + alertStreamEvent.setSchema(streamDefinition); + alertStreamEvent.setPolicyId("setPolicyId"); + alertStreamEvent.setCreatedTime(1234); + AlertPublishEvent alertPublishEvent = AlertPublishEvent.createAlertPublishEvent(alertStreamEvent); + Assert.assertEquals(null, alertPublishEvent.getSiteId()); + Assert.assertTrue(alertPublishEvent.getAlertId() != null); + Assert.assertEquals("setPolicyId", alertPublishEvent.getPolicyId()); + Assert.assertEquals(null, alertPublishEvent.getPolicyValue()); + Assert.assertEquals("{flag=1, data=0.1, name=namevalue, host=hostvalue, salary=-0.2, value=10, int=1, object={\"name\":\"heap.COMMITTED\", \"Value\":\"175636480\"}}", alertPublishEvent.getAlertData().toString()); + Assert.assertEquals(1234, alertPublishEvent.getAlertTimestamp()); + Assert.assertEquals(null, alertPublishEvent.getAppIds()); + + AlertPublishEvent alertPublishEvent1 = AlertPublishEvent.createAlertPublishEvent(alertStreamEvent); + Assert.assertFalse(alertPublishEvent1 == alertPublishEvent); + Assert.assertFalse(alertPublishEvent1.equals(alertPublishEvent)); + Assert.assertFalse(alertPublishEvent1.hashCode() == alertPublishEvent.hashCode()); + + Map<String, Object> extraData = new HashMap<>(); + extraData.put(AlertPublishEvent.SITE_ID_KEY, "SITE_ID_KEY"); + extraData.put(AlertPublishEvent.POLICY_VALUE_KEY, "POLICY_VALUE_KEY"); + extraData.put(AlertPublishEvent.APP_IDS_KEY, Arrays.asList("appId1", "appId2")); + alertStreamEvent.setExtraData(extraData); + + alertPublishEvent = AlertPublishEvent.createAlertPublishEvent(alertStreamEvent); + Assert.assertEquals("SITE_ID_KEY", alertPublishEvent.getSiteId()); + Assert.assertTrue(alertPublishEvent.getAlertId() != null); + Assert.assertEquals("setPolicyId", alertPublishEvent.getPolicyId()); + Assert.assertEquals("POLICY_VALUE_KEY", alertPublishEvent.getPolicyValue()); + Assert.assertEquals("{flag=1, data=0.1, name=namevalue, host=hostvalue, salary=-0.2, value=10, int=1, object={\"name\":\"heap.COMMITTED\", \"Value\":\"175636480\"}}", alertPublishEvent.getAlertData().toString()); + Assert.assertEquals(1234, alertPublishEvent.getAlertTimestamp()); + Assert.assertEquals("appId1", alertPublishEvent.getAppIds().get(0)); + Assert.assertEquals("appId2", alertPublishEvent.getAppIds().get(1)); + + } +} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/2b61cef5/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/alert/engine/model/AlertStreamEventTest.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/alert/engine/model/AlertStreamEventTest.java b/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/alert/engine/model/AlertStreamEventTest.java new file mode 100644 index 0000000..eec3675 --- /dev/null +++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/alert/engine/model/AlertStreamEventTest.java @@ -0,0 +1,63 @@ +/* + * 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 + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * 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. + */ + +package org.apache.eagle.alert.engine.model; + +import org.apache.eagle.alert.engine.coordinator.StreamColumn; +import org.apache.eagle.alert.engine.coordinator.StreamDefinition; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class AlertStreamEventTest { + + @Test + public void testAlertStreamEvent() { + List<StreamColumn> streamColumns = new ArrayList<>(); + streamColumns.add(new StreamColumn.Builder().name("name").type(StreamColumn.Type.STRING).build()); + streamColumns.add(new StreamColumn.Builder().name("host").type(StreamColumn.Type.STRING).build()); + streamColumns.add(new StreamColumn.Builder().name("flag").type(StreamColumn.Type.BOOL).build()); + streamColumns.add(new StreamColumn.Builder().name("value").type(StreamColumn.Type.DOUBLE).build()); + streamColumns.add(new StreamColumn.Builder().name("data").type(StreamColumn.Type.LONG).build()); + streamColumns.add(new StreamColumn.Builder().name("salary").type(StreamColumn.Type.FLOAT).build()); + streamColumns.add(new StreamColumn.Builder().name("object").type(StreamColumn.Type.OBJECT).build()); + streamColumns.add(new StreamColumn.Builder().name("int").type(StreamColumn.Type.INT).build()); + + StreamDefinition streamDefinition = new StreamDefinition(); + streamDefinition.setColumns(streamColumns); + AlertStreamEvent alertStreamEvent = new AlertStreamEvent(); + alertStreamEvent.setSchema(streamDefinition); + alertStreamEvent.setData(new Object[]{"namevalue", "hostvalue", "1", 10, 0.1, -0.2, "{\"name\":\"heap.COMMITTED\", \"Value\":\"175636480\"}", 1}); + Assert.assertEquals("AlertStreamEvent[stream=NULL,timestamp=1970-01-01 00:00:00,000,data=[namevalue,hostvalue,1,10,0.1,-0.2,{\"name\":\"heap.COMMITTED\", \"Value\":\"175636480\"},1], policyId=null, createdBy=null, metaVersion=null]", alertStreamEvent.toString()); + Assert.assertEquals("{flag=1, data=0.1, name=namevalue, host=hostvalue, salary=-0.2, value=10, int=1, object={\"name\":\"heap.COMMITTED\", \"Value\":\"175636480\"}}", alertStreamEvent.getDataMap().toString()); + + AlertStreamEvent alertStreamEvent1 = new AlertStreamEvent(alertStreamEvent); + + Assert.assertEquals("AlertStreamEvent[stream=NULL,timestamp=1970-01-01 00:00:00,000,data=[namevalue,hostvalue,1,10,0.1,-0.2,{\"name\":\"heap.COMMITTED\", \"Value\":\"175636480\"},1], policyId=null, createdBy=null, metaVersion=null]", alertStreamEvent1.toString()); + Assert.assertEquals("{flag=1, data=0.1, name=namevalue, host=hostvalue, salary=-0.2, value=10, int=1, object={\"name\":\"heap.COMMITTED\", \"Value\":\"175636480\"}}", alertStreamEvent1.getDataMap().toString()); + + + Assert.assertFalse(alertStreamEvent1 == alertStreamEvent); + Assert.assertTrue(alertStreamEvent1.equals(alertStreamEvent)); + Assert.assertTrue(alertStreamEvent1.hashCode() == alertStreamEvent.hashCode()); + } +} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/2b61cef5/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/alert/engine/model/PartitionedEventTest.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/alert/engine/model/PartitionedEventTest.java b/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/alert/engine/model/PartitionedEventTest.java new file mode 100644 index 0000000..719445b --- /dev/null +++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/alert/engine/model/PartitionedEventTest.java @@ -0,0 +1,54 @@ +/* + * 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 + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * 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. + */ + +package org.apache.eagle.alert.engine.model; + +import org.apache.eagle.alert.engine.coordinator.StreamPartition; +import org.apache.eagle.alert.engine.coordinator.StreamSortSpec; +import org.junit.Assert; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.List; + +public class PartitionedEventTest { + @Test + public void testPartitionedEvent() { + PartitionedEvent partitionedEvent = new PartitionedEvent(); + Assert.assertEquals("PartitionedEvent[partition=null,event=null,key=0", partitionedEvent.toString()); + + Object[] data = new Object[]{"namevalue", "hostvalue", "1", 10, 0.1, -0.2, "{\"name\":\"heap.COMMITTED\", \"Value\":\"175636480\"}", 1}; + StreamEvent streamEvent = new StreamEvent("streamId", 1478667686971l, data); + + StreamSortSpec streamSortSpec = new StreamSortSpec(); + streamSortSpec.setWindowPeriod("PT10S"); + StreamPartition streamPartition = new StreamPartition(); + List<String> columns = new ArrayList<>(); + columns.add("jobId"); + streamPartition.setColumns(columns); + streamPartition.setSortSpec(streamSortSpec); + streamPartition.setStreamId("test"); + streamPartition.setType(StreamPartition.Type.GROUPBY); + + partitionedEvent = new PartitionedEvent(streamEvent, streamPartition, 1); + Assert.assertEquals("PartitionedEvent[partition=StreamPartition[streamId=test,type=GROUPBY,columns=[jobId],sortSpec=[StreamSortSpec[windowPeriod=PT10S,windowMargin=30000]]],event=StreamEvent[stream=STREAMID,timestamp=2016-11-09 05:01:26,971,data=[namevalue,hostvalue,1,10,0.1,-0.2,{\"name\":\"heap.COMMITTED\", \"Value\":\"175636480\"},1],metaVersion=null],key=1", partitionedEvent.toString()); + PartitionedEvent partitionedEventCopy = partitionedEvent.copy(); + Assert.assertFalse(partitionedEventCopy == partitionedEvent); + Assert.assertTrue(partitionedEventCopy.equals(partitionedEvent)); + Assert.assertTrue(partitionedEventCopy.hashCode() == partitionedEvent.hashCode()); + } +} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/2b61cef5/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/alert/engine/model/StreamEventBuilderTest.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/alert/engine/model/StreamEventBuilderTest.java b/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/alert/engine/model/StreamEventBuilderTest.java new file mode 100644 index 0000000..16c7ad2 --- /dev/null +++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/alert/engine/model/StreamEventBuilderTest.java @@ -0,0 +1,166 @@ +/* + * 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 + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * 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. + */ +package org.apache.eagle.alert.engine.model; + +import org.apache.eagle.alert.engine.coordinator.StreamColumn; +import org.apache.eagle.alert.engine.coordinator.StreamDefinition; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class StreamEventBuilderTest { + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Test + public void testStreamEventBuilder() { + + List<StreamColumn> streamColumns = new ArrayList<>(); + streamColumns.add(new StreamColumn.Builder().name("name").type(StreamColumn.Type.STRING).build()); + streamColumns.add(new StreamColumn.Builder().name("host").type(StreamColumn.Type.STRING).build()); + streamColumns.add(new StreamColumn.Builder().name("flag").type(StreamColumn.Type.BOOL).build()); + streamColumns.add(new StreamColumn.Builder().name("value").type(StreamColumn.Type.DOUBLE).build()); + streamColumns.add(new StreamColumn.Builder().name("data").type(StreamColumn.Type.LONG).build()); + streamColumns.add(new StreamColumn.Builder().name("salary").type(StreamColumn.Type.FLOAT).build()); + streamColumns.add(new StreamColumn.Builder().name("object").type(StreamColumn.Type.OBJECT).build()); + streamColumns.add(new StreamColumn.Builder().name("int").type(StreamColumn.Type.INT).build()); + StreamDefinition streamDefinition = new StreamDefinition(); + streamDefinition.setColumns(streamColumns); + + StreamEventBuilder streamEventBuilder = new StreamEventBuilder(); + StreamEvent streamEvent = streamEventBuilder.schema(streamDefinition).streamId("streamId").metaVersion("metaVersion").timestamep(1478667686971l).build(); + Assert.assertEquals("StreamEvent[stream=STREAMID,timestamp=2016-11-09 05:01:26,971,data=[],metaVersion=metaVersion]", streamEvent.toString()); + Object[] data = new Object[]{"namevalue", "hostvalue", "1", 10.0, 1, -0.2, "{\"name\":\"heap.COMMITTED\", \"Value\":\"175636480\"}", 4}; + streamEvent = streamEventBuilder.schema(streamDefinition).attributes(data).streamId("streamId").metaVersion("metaVersion").timestamep(1478667686971l).build(); + Assert.assertEquals("StreamEvent[stream=STREAMID,timestamp=2016-11-09 05:01:26,971,data=[namevalue,hostvalue,1,10.0,1,-0.2,{\"name\":\"heap.COMMITTED\", \"Value\":\"175636480\"},4],metaVersion=metaVersion]", streamEvent.toString()); + + Map<String, Object> mapdata = new HashMap<>(); + mapdata.put("name", "namevalue"); + mapdata.put("host", "hostvalue"); + mapdata.put("flag", "1"); + mapdata.put("value", 10.0); + mapdata.put("data", 1); + mapdata.put("salary", -0.2); + mapdata.put("object", "{\"name\":\"heap.COMMITTED\", \"Value\":\"175636480\"}"); + mapdata.put("int", 4); + StreamEvent streamEvent1 = streamEventBuilder.schema(streamDefinition).attributes(mapdata, streamDefinition).streamId("streamId").metaVersion("metaVersion").timestamep(1478667686971l).build(); + Assert.assertEquals("StreamEvent[stream=STREAMID,timestamp=2016-11-09 05:01:26,971,data=[namevalue,hostvalue,1,10.0,1,-0.2,{\"name\":\"heap.COMMITTED\", \"Value\":\"175636480\"},4],metaVersion=metaVersion]", streamEvent.toString()); + + Assert.assertTrue(streamEvent1 == streamEvent); + Assert.assertTrue(streamEvent1.equals(streamEvent)); + Assert.assertTrue(streamEvent1.hashCode() == streamEvent.hashCode()); + + StreamEventBuilder streamEventBuilder1 = new StreamEventBuilder(); + streamEvent1 = streamEventBuilder1.schema(streamDefinition).attributes(mapdata, streamDefinition).streamId("streamId").metaVersion("metaVersion").timestamep(1478667686971l).build(); + + Assert.assertFalse(streamEvent1 == streamEvent); + Assert.assertTrue(streamEvent1.equals(streamEvent)); + Assert.assertTrue(streamEvent1.hashCode() == streamEvent.hashCode()); + } + + @Test + public void testStreamEventBuilder1() { + thrown.expect(IllegalArgumentException.class); + StreamEventBuilder streamEventBuilder = new StreamEventBuilder(); + streamEventBuilder.metaVersion("metaVersion").timestamep(1478667686971l).build(); + } + + @Test + public void testStreamEventBuilder2() { + StreamEventBuilder streamEventBuilder = new StreamEventBuilder(); + + Map<String, Object> mapdata = new HashMap<>(); + mapdata.put("name", "namevalue"); + mapdata.put("host", "hostvalue"); + mapdata.put("flag", "1"); + mapdata.put("value", 10.0); + mapdata.put("data", 1); + mapdata.put("salary", -0.2); + mapdata.put("object", "{\"name\":\"heap.COMMITTED\", \"Value\":\"175636480\"}"); + mapdata.put("int", 4); + + List<StreamColumn> streamColumns = new ArrayList<>(); + streamColumns.add(new StreamColumn.Builder().name("name").type(StreamColumn.Type.STRING).build()); + streamColumns.add(new StreamColumn.Builder().name("host").type(StreamColumn.Type.STRING).build()); + streamColumns.add(new StreamColumn.Builder().name("int").type(StreamColumn.Type.INT).build()); + StreamDefinition streamDefinition = new StreamDefinition(); + streamDefinition.setColumns(streamColumns); + + StreamEvent streamEvent = streamEventBuilder.attributes(mapdata, streamDefinition).streamId("streamId").metaVersion("metaVersion").timestamep(1478667686971l).build(); + Assert.assertEquals("StreamEvent[stream=STREAMID,timestamp=2016-11-09 05:01:26,971,data=[namevalue,hostvalue,4],metaVersion=metaVersion]", streamEvent.toString()); + } + + @Test + public void testStreamEventBuilder3() { + StreamEventBuilder streamEventBuilder = new StreamEventBuilder(); + + Map<String, Object> mapdata = new HashMap<>(); + mapdata.put("name", "namevalue"); + mapdata.put("host", "hostvalue"); + mapdata.put("flag", "1"); + mapdata.put("value", 10.0); + mapdata.put("data", 1); + mapdata.put("salary", -0.2); + mapdata.put("object", "{\"name\":\"heap.COMMITTED\", \"Value\":\"175636480\"}"); + + List<StreamColumn> streamColumns = new ArrayList<>(); + streamColumns.add(new StreamColumn.Builder().name("name").type(StreamColumn.Type.STRING).build()); + streamColumns.add(new StreamColumn.Builder().name("host").type(StreamColumn.Type.STRING).build()); + streamColumns.add(new StreamColumn.Builder().name("flag").type(StreamColumn.Type.BOOL).build()); + streamColumns.add(new StreamColumn.Builder().name("value").type(StreamColumn.Type.DOUBLE).build()); + streamColumns.add(new StreamColumn.Builder().name("data").type(StreamColumn.Type.LONG).build()); + streamColumns.add(new StreamColumn.Builder().name("salary").type(StreamColumn.Type.FLOAT).build()); + streamColumns.add(new StreamColumn.Builder().name("object").type(StreamColumn.Type.OBJECT).build()); + StreamColumn streamColumn = new StreamColumn.Builder().name("int").type(StreamColumn.Type.INT).build(); + streamColumn.setDefaultValue(100); + streamColumns.add(streamColumn); + StreamDefinition streamDefinition = new StreamDefinition(); + streamDefinition.setColumns(streamColumns); + + StreamEvent streamEvent = streamEventBuilder.attributes(mapdata, streamDefinition).streamId("streamId").metaVersion("metaVersion").timestamep(1478667686971l).build(); + Assert.assertEquals("StreamEvent[stream=STREAMID,timestamp=2016-11-09 05:01:26,971,data=[namevalue,hostvalue,1,10.0,1,-0.2,{\"name\":\"heap.COMMITTED\", \"Value\":\"175636480\"},100],metaVersion=metaVersion]", streamEvent.toString()); + } + + @Test + public void testStreamEventBuilder4() { + StreamEventBuilder streamEventBuilder = new StreamEventBuilder(); + + Map<String, Object> mapdata = new HashMap<>(); + mapdata.put("name", "namevalue"); + mapdata.put("host1", "hostvalue"); + mapdata.put("flag", "1"); + + List<StreamColumn> streamColumns = new ArrayList<>(); + streamColumns.add(new StreamColumn.Builder().name("name").type(StreamColumn.Type.STRING).build()); + streamColumns.add(new StreamColumn.Builder().name("host").type(StreamColumn.Type.STRING).build()); + streamColumns.add(new StreamColumn.Builder().name("flag").type(StreamColumn.Type.BOOL).build()); + streamColumns.add(new StreamColumn.Builder().name("value").type(StreamColumn.Type.DOUBLE).build()); + StreamDefinition streamDefinition = new StreamDefinition(); + streamDefinition.setColumns(streamColumns); + + StreamEvent streamEvent = streamEventBuilder.attributes(mapdata, streamDefinition).streamId("streamId").metaVersion("metaVersion").timestamep(1478667686971l).build(); + Assert.assertEquals("StreamEvent[stream=STREAMID,timestamp=2016-11-09 05:01:26,971,data=[namevalue,,1,],metaVersion=metaVersion]", streamEvent.toString()); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/2b61cef5/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/alert/engine/model/StreamEventTest.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/alert/engine/model/StreamEventTest.java b/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/alert/engine/model/StreamEventTest.java new file mode 100644 index 0000000..6543a8d --- /dev/null +++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/alert/engine/model/StreamEventTest.java @@ -0,0 +1,191 @@ +/* + * 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 + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * 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. + */ +package org.apache.eagle.alert.engine.model; + +import org.apache.eagle.alert.engine.coordinator.StreamColumn; +import org.apache.eagle.alert.engine.coordinator.StreamDefinition; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; + +public class StreamEventTest { + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Test + public void testStreamEvent() { + Object[] data = new Object[]{"namevalue", "hostvalue", "1", 10.0, 1, -0.2, "{\"name\":\"heap.COMMITTED\", \"Value\":\"175636480\"}", 4}; + StreamEvent streamEvent = new StreamEvent("streamId", 1478667686971l, data); + + Assert.assertEquals("StreamEvent[stream=STREAMID,timestamp=2016-11-09 05:01:26,971,data=[namevalue,hostvalue,1,10.0,1,-0.2,{\"name\":\"heap.COMMITTED\", \"Value\":\"175636480\"},4],metaVersion=null]", streamEvent.toString()); + + streamEvent = new StreamEvent("streamId", 1478667686971l, data, "metaVersion"); + + Assert.assertEquals("StreamEvent[stream=STREAMID,timestamp=2016-11-09 05:01:26,971,data=[namevalue,hostvalue,1,10.0,1,-0.2,{\"name\":\"heap.COMMITTED\", \"Value\":\"175636480\"},4],metaVersion=metaVersion]", streamEvent.toString()); + StreamEvent streamEventCopy = streamEvent.copy(); + Assert.assertFalse(streamEventCopy == streamEvent); + Assert.assertTrue(streamEventCopy.equals(streamEvent)); + Assert.assertTrue(streamEventCopy.hashCode() == streamEvent.hashCode()); + + streamEventCopy.setMetaVersion(""); + Assert.assertFalse(streamEventCopy == streamEvent); + Assert.assertFalse(streamEventCopy.equals(streamEvent)); + Assert.assertFalse(streamEventCopy.hashCode() == streamEvent.hashCode()); + + streamEventCopy.copyFrom(streamEvent); + + Assert.assertFalse(streamEventCopy == streamEvent); + Assert.assertTrue(streamEventCopy.equals(streamEvent)); + Assert.assertTrue(streamEventCopy.hashCode() == streamEvent.hashCode()); + + + List<StreamColumn> streamColumns = new ArrayList<>(); + streamColumns.add(new StreamColumn.Builder().name("name").type(StreamColumn.Type.STRING).build()); + streamColumns.add(new StreamColumn.Builder().name("host").type(StreamColumn.Type.STRING).build()); + streamColumns.add(new StreamColumn.Builder().name("flag").type(StreamColumn.Type.BOOL).build()); + streamColumns.add(new StreamColumn.Builder().name("value").type(StreamColumn.Type.DOUBLE).build()); + streamColumns.add(new StreamColumn.Builder().name("data").type(StreamColumn.Type.LONG).build()); + streamColumns.add(new StreamColumn.Builder().name("salary").type(StreamColumn.Type.FLOAT).build()); + streamColumns.add(new StreamColumn.Builder().name("object").type(StreamColumn.Type.OBJECT).build()); + streamColumns.add(new StreamColumn.Builder().name("int").type(StreamColumn.Type.INT).build()); + + StreamDefinition streamDefinition = new StreamDefinition(); + streamDefinition.setColumns(streamColumns); + + Object[] values = streamEvent.getData(streamDefinition, "int", "salary", "flag", "object"); + Assert.assertEquals(4, values[0]); + Assert.assertEquals(-0.2, values[1]); + Assert.assertEquals("1", values[2]); + Assert.assertEquals("{\"name\":\"heap.COMMITTED\", \"Value\":\"175636480\"}", values[3]); + + values = streamEvent.getData(streamDefinition, Arrays.asList("int", "data", "flag", "object")); + Assert.assertEquals(4, values[0]); + Assert.assertEquals(1, values[1]); + Assert.assertEquals("1", values[2]); + Assert.assertEquals("{\"name\":\"heap.COMMITTED\", \"Value\":\"175636480\"}", values[3]); + } + + + @Test + public void testStreamEvent1() { + thrown.expect(IndexOutOfBoundsException.class); + List<StreamColumn> streamColumns = new ArrayList<>(); + streamColumns.add(new StreamColumn.Builder().name("name").type(StreamColumn.Type.STRING).build()); + streamColumns.add(new StreamColumn.Builder().name("host").type(StreamColumn.Type.STRING).build()); + streamColumns.add(new StreamColumn.Builder().name("flag").type(StreamColumn.Type.BOOL).build()); + streamColumns.add(new StreamColumn.Builder().name("value").type(StreamColumn.Type.DOUBLE).build()); + streamColumns.add(new StreamColumn.Builder().name("data").type(StreamColumn.Type.LONG).build()); + streamColumns.add(new StreamColumn.Builder().name("salary").type(StreamColumn.Type.FLOAT).build()); + streamColumns.add(new StreamColumn.Builder().name("object").type(StreamColumn.Type.OBJECT).build()); + streamColumns.add(new StreamColumn.Builder().name("int").type(StreamColumn.Type.INT).build()); + + StreamDefinition streamDefinition = new StreamDefinition(); + streamDefinition.setColumns(streamColumns); + StreamEvent streamEvent = new StreamEvent(); + streamEvent.setData(new Object[]{"namevalue", "hostvalue", "1", 10.0, 1, -0.2, "{\"name\":\"heap.COMMITTED\", \"Value\":\"175636480\"}\"", 4}); + streamEvent.getData(streamDefinition, "salary", "isYhd"); + + } + + @Test + public void testStreamEvent2() { + thrown.expect(IndexOutOfBoundsException.class); + List<StreamColumn> streamColumns = new ArrayList<>(); + streamColumns.add(new StreamColumn.Builder().name("name").type(StreamColumn.Type.STRING).build()); + streamColumns.add(new StreamColumn.Builder().name("host").type(StreamColumn.Type.STRING).build()); + streamColumns.add(new StreamColumn.Builder().name("flag").type(StreamColumn.Type.BOOL).build()); + streamColumns.add(new StreamColumn.Builder().name("value").type(StreamColumn.Type.DOUBLE).build()); + streamColumns.add(new StreamColumn.Builder().name("data").type(StreamColumn.Type.LONG).build()); + streamColumns.add(new StreamColumn.Builder().name("salary").type(StreamColumn.Type.FLOAT).build()); + streamColumns.add(new StreamColumn.Builder().name("object").type(StreamColumn.Type.OBJECT).build()); + streamColumns.add(new StreamColumn.Builder().name("int").type(StreamColumn.Type.INT).build()); + + StreamDefinition streamDefinition = new StreamDefinition(); + streamDefinition.setColumns(streamColumns); + StreamEvent streamEvent = new StreamEvent(); + streamEvent.setData(new Object[]{"namevalue", "hostvalue", "1", 10.0, 1, -0.2, "{\"name\":\"heap.COMMITTED\", \"Value\":\"175636480\"}\""}); + streamEvent.getData(streamDefinition, "salary", "int"); + + } + + @Test + public void testStreamEvent3() { + List<StreamColumn> streamColumns = new ArrayList<>(); + streamColumns.add(new StreamColumn.Builder().name("name").type(StreamColumn.Type.STRING).build()); + streamColumns.add(new StreamColumn.Builder().name("host").type(StreamColumn.Type.STRING).build()); + streamColumns.add(new StreamColumn.Builder().name("flag").type(StreamColumn.Type.BOOL).build()); + streamColumns.add(new StreamColumn.Builder().name("value").type(StreamColumn.Type.DOUBLE).build()); + streamColumns.add(new StreamColumn.Builder().name("data").type(StreamColumn.Type.LONG).build()); + streamColumns.add(new StreamColumn.Builder().name("salary").type(StreamColumn.Type.FLOAT).build()); + streamColumns.add(new StreamColumn.Builder().name("object").type(StreamColumn.Type.OBJECT).build()); + streamColumns.add(new StreamColumn.Builder().name("int").type(StreamColumn.Type.INT).build()); + + StreamDefinition streamDefinition = new StreamDefinition(); + streamDefinition.setColumns(streamColumns); + StreamEvent streamEvent = new StreamEvent(); + streamEvent.setData(new Object[]{"namevalue", 1, "flag", 10.0, 0.1, -0.2, "{\"name\":\"heap.COMMITTED\", \"Value\":\"175636480\"}\"", 1}); + Object[] values = streamEvent.getData(streamDefinition, "value", "host"); + Assert.assertEquals(10.0, values[0]); + Assert.assertEquals(1, values[1]); + } + + @Test + public void testStreamEventEqual() { + Long timestamp = System.currentTimeMillis(); + StreamEvent event1 = mockSimpleStreamEvent(timestamp); + StreamEvent event2 = mockSimpleStreamEvent(timestamp); + StreamEvent event3 = event2.copy(); + Assert.assertEquals(event1, event2); + Assert.assertEquals(event2, event3); + } + + private static StreamEvent mockSimpleStreamEvent(Long timestamp) { + return StreamEvent.builder() + .schema(mockStreamDefinition("sampleStream_1")) + .streamId("sampleStream_1") + .timestamep(timestamp) + .attributes(new HashMap<String, Object>() {{ + put("name", "cpu"); + put("value", 60.0); + put("unknown", "unknown column value"); + }}).build(); + } + + private static StreamDefinition mockStreamDefinition(String streamId) { + StreamDefinition sampleStreamDefinition = new StreamDefinition(); + List<StreamColumn> streamColumns = new ArrayList<>(); + streamColumns.add(new StreamColumn.Builder().name("name").type(StreamColumn.Type.STRING).build()); + streamColumns.add(new StreamColumn.Builder().name("host").type(StreamColumn.Type.STRING).build()); + streamColumns.add(new StreamColumn.Builder().name("flag").type(StreamColumn.Type.BOOL).build()); + streamColumns.add(new StreamColumn.Builder().name("timestamp").type(StreamColumn.Type.LONG).build()); + streamColumns.add(new StreamColumn.Builder().name("value").type(StreamColumn.Type.DOUBLE).build()); + + sampleStreamDefinition.setStreamId(streamId); + sampleStreamDefinition.setTimeseries(true); + sampleStreamDefinition.setValidate(true); + sampleStreamDefinition.setDescription("Schema for " + streamId); + sampleStreamDefinition.setColumns(streamColumns); + return sampleStreamDefinition; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/2b61cef5/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/alert/model/StreamEventTest.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/alert/model/StreamEventTest.java b/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/alert/model/StreamEventTest.java deleted file mode 100644 index e8ec1ad..0000000 --- a/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/alert/model/StreamEventTest.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * 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 - * <p> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p> - * 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. - */ -package org.apache.eagle.alert.model; - -import org.apache.eagle.alert.engine.coordinator.StreamColumn; -import org.apache.eagle.alert.engine.coordinator.StreamDefinition; -import org.apache.eagle.alert.engine.model.StreamEvent; -import org.junit.Assert; -import org.junit.Test; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; - -public class StreamEventTest { - @Test - public void testStreamEventEqual() { - Long timestamp = System.currentTimeMillis(); - StreamEvent event1 = mockSimpleStreamEvent(timestamp); - StreamEvent event2 = mockSimpleStreamEvent(timestamp); - StreamEvent event3 = event2.copy(); - Assert.assertEquals(event1, event2); - Assert.assertEquals(event2, event3); - } - - private static StreamEvent mockSimpleStreamEvent(Long timestamp) { - return StreamEvent.builder() - .schema(mockStreamDefinition("sampleStream_1")) - .streamId("sampleStream_1") - .timestamep(timestamp) - .attributes(new HashMap<String, Object>() {{ - put("name", "cpu"); - put("value", 60.0); - put("unknown", "unknown column value"); - }}).build(); - } - - private static StreamDefinition mockStreamDefinition(String streamId) { - StreamDefinition sampleStreamDefinition = new StreamDefinition(); - List<StreamColumn> streamColumns = new ArrayList<>(); - streamColumns.add(new StreamColumn.Builder().name("name").type(StreamColumn.Type.STRING).build()); - streamColumns.add(new StreamColumn.Builder().name("host").type(StreamColumn.Type.STRING).build()); - streamColumns.add(new StreamColumn.Builder().name("flag").type(StreamColumn.Type.BOOL).build()); - streamColumns.add(new StreamColumn.Builder().name("timestamp").type(StreamColumn.Type.LONG).build()); - streamColumns.add(new StreamColumn.Builder().name("value").type(StreamColumn.Type.DOUBLE).build()); - - sampleStreamDefinition.setStreamId(streamId); - sampleStreamDefinition.setTimeseries(true); - sampleStreamDefinition.setValidate(true); - sampleStreamDefinition.setDescription("Schema for " + streamId); - sampleStreamDefinition.setColumns(streamColumns); - return sampleStreamDefinition; - } -} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/2b61cef5/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/alert/model/TestPolicyDefinition.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/alert/model/TestPolicyDefinition.java b/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/alert/model/TestPolicyDefinition.java deleted file mode 100644 index 1cc063d..0000000 --- a/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/alert/model/TestPolicyDefinition.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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 - * <p> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p> - * 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. - */ - -package org.apache.eagle.alert.model; - -import org.apache.eagle.alert.engine.coordinator.PolicyDefinition; -import org.junit.Assert; -import org.junit.Test; - -public class TestPolicyDefinition { - - @Test - public void testEqual() { - PolicyDefinition.Definition definition = new PolicyDefinition.Definition(); - PolicyDefinition policy1 = new PolicyDefinition(); - policy1.setName("policy1"); - policy1.setDefinition(definition); - - PolicyDefinition policy2 = new PolicyDefinition(); - policy2.setName("policy1"); - policy2.setPolicyStatus(PolicyDefinition.PolicyStatus.DISABLED); - policy2.setDefinition(definition); - - PolicyDefinition policy3 = new PolicyDefinition(); - policy3.setName("policy1"); - policy3.setDefinition(definition); - - Assert.assertTrue(policy1.equals(policy3)); - Assert.assertFalse(policy1.equals(policy2)); - } -}