http://git-wip-us.apache.org/repos/asf/eagle/blob/6fd95d5c/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/alert/engine/coordinator/PublishmentTest.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/alert/engine/coordinator/PublishmentTest.java b/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/alert/engine/coordinator/PublishmentTest.java deleted file mode 100644 index 494d8ca..0000000 --- a/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/alert/engine/coordinator/PublishmentTest.java +++ /dev/null @@ -1,100 +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.engine.coordinator; - -import com.google.common.collect.ImmutableMap; -import org.junit.Assert; -import org.junit.Test; - -import java.util.*; - -public class PublishmentTest { - @Test - public void testPublishment() { - Map<String, Object> properties = new HashMap<>(); - properties.put("kafka_broker", "localhost:9092"); - properties.put("topic", "TEST_TOPIC_NAME"); - - List<Map<String, Object>> kafkaClientConfig = new ArrayList<>(); - kafkaClientConfig.add(ImmutableMap.of("name", "producer.type", "value", "sync")); - properties.put("kafka_client_config", kafkaClientConfig); - - PolicyDefinition policy = createPolicy("testStream", "testPolicy"); - Publishment publishment = new Publishment(); - publishment.setName("testAsyncPublishment"); - publishment.setType("org.apache.eagle.alert.engine.publisher.impl.AlertKafkaPublisher"); - publishment.setPolicyIds(Arrays.asList(policy.getName())); - publishment.setDedupIntervalMin("PT0M"); - OverrideDeduplicatorSpec overrideDeduplicatorSpec = new OverrideDeduplicatorSpec(); - overrideDeduplicatorSpec.setClassName("testClass"); - publishment.setOverrideDeduplicator(overrideDeduplicatorSpec); - publishment.setSerializer("org.apache.eagle.alert.engine.publisher.impl.JsonEventSerializer"); - publishment.setProperties(properties); - - Assert.assertEquals("Publishment[name:testAsyncPublishment,type:org.apache.eagle.alert.engine.publisher.impl.AlertKafkaPublisher,policyId:[testPolicy],properties:{kafka_client_config=[{name=producer.type, value=sync}], topic=TEST_TOPIC_NAME, kafka_broker=localhost:9092}", publishment.toString()); - - - Publishment publishment1 = new Publishment(); - publishment1.setName("testAsyncPublishment"); - publishment1.setType("org.apache.eagle.alert.engine.publisher.impl.AlertKafkaPublisher"); - publishment1.setPolicyIds(Arrays.asList(policy.getName())); - publishment1.setDedupIntervalMin("PT0M"); - OverrideDeduplicatorSpec overrideDeduplicatorSpec1 = new OverrideDeduplicatorSpec(); - overrideDeduplicatorSpec1.setClassName("testClass"); - publishment1.setOverrideDeduplicator(overrideDeduplicatorSpec1); - publishment1.setSerializer("org.apache.eagle.alert.engine.publisher.impl.JsonEventSerializer"); - publishment1.setProperties(properties); - - Assert.assertTrue(publishment.equals(publishment1)); - Assert.assertTrue(publishment.hashCode() == publishment1.hashCode()); - Assert.assertFalse(publishment == publishment1); - publishment1.getOverrideDeduplicator().setClassName("testClass1"); - - - Assert.assertFalse(publishment.equals(publishment1)); - Assert.assertFalse(publishment.hashCode() == publishment1.hashCode()); - Assert.assertFalse(publishment == publishment1); - - publishment1.getOverrideDeduplicator().setClassName("testClass"); - publishment1.setStreamIds(Arrays.asList("streamid1,streamid2")); - Assert.assertFalse(publishment.equals(publishment1)); - Assert.assertFalse(publishment.hashCode() == publishment1.hashCode()); - Assert.assertFalse(publishment == publishment1); - } - - 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/eagle/blob/6fd95d5c/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/alert/engine/coordinator/PublishmentTypeTest.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/alert/engine/coordinator/PublishmentTypeTest.java b/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/alert/engine/coordinator/PublishmentTypeTest.java deleted file mode 100644 index fcd856a..0000000 --- a/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/alert/engine/coordinator/PublishmentTypeTest.java +++ /dev/null @@ -1,46 +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.engine.coordinator; - -import org.junit.Assert; -import org.junit.Test; - -public class PublishmentTypeTest { - - @Test - public void testPublishmentType() { - PublishmentType publishmentType = new PublishmentType(); - publishmentType.setName("KAFKA"); - publishmentType.setType("setClassName"); - publishmentType.setDescription("setDescription"); - - PublishmentType publishmentType1 = new PublishmentType(); - publishmentType1.setName("KAFKA"); - publishmentType1.setType("setClassName"); - publishmentType1.setDescription("setDescription"); - - Assert.assertFalse(publishmentType.equals(new String(""))); - Assert.assertFalse(publishmentType == publishmentType1); - Assert.assertTrue(publishmentType.equals(publishmentType1)); - Assert.assertTrue(publishmentType.hashCode() == publishmentType1.hashCode()); - - publishmentType1.setType("JMS"); - - Assert.assertFalse(publishmentType.equals(publishmentType1)); - Assert.assertFalse(publishmentType.hashCode() == publishmentType1.hashCode()); - } -} http://git-wip-us.apache.org/repos/asf/eagle/blob/6fd95d5c/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/alert/engine/coordinator/StreamColumnTest.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/alert/engine/coordinator/StreamColumnTest.java b/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/alert/engine/coordinator/StreamColumnTest.java deleted file mode 100644 index ccc7717..0000000 --- a/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/alert/engine/coordinator/StreamColumnTest.java +++ /dev/null @@ -1,153 +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.engine.coordinator; - -import org.junit.Assert; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; - -import java.util.HashMap; - - -public class StreamColumnTest { - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Test - public void testStreamStringColumn() { - StreamColumn streamColumn = new StreamColumn.Builder().name("NAMEyhd").type(StreamColumn.Type.STRING).defaultValue("EAGLEyhd").required(true).build(); - streamColumn.setNodataExpression("PT1M,dynamic,1,NAMEyhd"); - Assert.assertEquals("StreamColumn=name[NAMEyhd], type=[string], defaultValue=[EAGLEyhd], required=[true], nodataExpression=[PT1M,dynamic,1,NAMEyhd]", streamColumn.toString()); - Assert.assertTrue(streamColumn.getDefaultValue() instanceof String); - } - - @Test - public void testStreamLongColumn() { - thrown.expect(NumberFormatException.class); - new StreamColumn.Builder().name("salary").type(StreamColumn.Type.LONG).defaultValue("eagle").required(true).build(); - } - - @Test - public void testStreamLongColumn1() { - StreamColumn streamColumn = new StreamColumn.Builder().name("salary").type(StreamColumn.Type.LONG).defaultValue("0").required(true).build(); - streamColumn.setNodataExpression("PT1M,dynamic,1,salary"); - Assert.assertEquals("StreamColumn=name[salary], type=[long], defaultValue=[0], required=[true], nodataExpression=[PT1M,dynamic,1,salary]", streamColumn.toString()); - Assert.assertTrue(streamColumn.getDefaultValue() instanceof Long); - } - - @Test - public void testStreamDoubleColumn() { - thrown.expect(NumberFormatException.class); - new StreamColumn.Builder().name("salary").type(StreamColumn.Type.DOUBLE).defaultValue("eagle").required(true).build(); - } - - @Test - public void testStreamDoubleColumn1() { - StreamColumn streamColumn = new StreamColumn.Builder().name("salary").type(StreamColumn.Type.DOUBLE).defaultValue("0.1").required(true).build(); - streamColumn.setNodataExpression("PT1M,dynamic,1,salary"); - Assert.assertEquals("StreamColumn=name[salary], type=[double], defaultValue=[0.1], required=[true], nodataExpression=[PT1M,dynamic,1,salary]", streamColumn.toString()); - - streamColumn = new StreamColumn.Builder().name("salary").type(StreamColumn.Type.DOUBLE).defaultValue("-0.1").required(true).build(); - streamColumn.setNodataExpression("PT1M,dynamic,1,salary"); - Assert.assertEquals("StreamColumn=name[salary], type=[double], defaultValue=[-0.1], required=[true], nodataExpression=[PT1M,dynamic,1,salary]", streamColumn.toString()); - - streamColumn = new StreamColumn.Builder().name("salary").type(StreamColumn.Type.DOUBLE).defaultValue("1").required(true).build(); - streamColumn.setNodataExpression("PT1M,dynamic,1,salary"); - Assert.assertEquals("StreamColumn=name[salary], type=[double], defaultValue=[1.0], required=[true], nodataExpression=[PT1M,dynamic,1,salary]", streamColumn.toString()); - Assert.assertTrue(streamColumn.getDefaultValue() instanceof Double); - } - - @Test - public void testStreamFloatColumn() { - thrown.expect(NumberFormatException.class); - new StreamColumn.Builder().name("salary").type(StreamColumn.Type.FLOAT).defaultValue("eagle").required(true).build(); - } - - @Test - public void testStreamFloatColumn1() { - StreamColumn streamColumn = new StreamColumn.Builder().name("salary").type(StreamColumn.Type.FLOAT).defaultValue("0.1").required(true).build(); - streamColumn.setNodataExpression("PT1M,dynamic,1,salary"); - Assert.assertEquals("StreamColumn=name[salary], type=[float], defaultValue=[0.1], required=[true], nodataExpression=[PT1M,dynamic,1,salary]", streamColumn.toString()); - - streamColumn = new StreamColumn.Builder().name("salary").type(StreamColumn.Type.FLOAT).defaultValue("-0.1").required(true).build(); - streamColumn.setNodataExpression("PT1M,dynamic,1,salary"); - Assert.assertEquals("StreamColumn=name[salary], type=[float], defaultValue=[-0.1], required=[true], nodataExpression=[PT1M,dynamic,1,salary]", streamColumn.toString()); - - streamColumn = new StreamColumn.Builder().name("salary").type(StreamColumn.Type.FLOAT).defaultValue("1").required(true).build(); - streamColumn.setNodataExpression("PT1M,dynamic,1,salary"); - Assert.assertEquals("StreamColumn=name[salary], type=[float], defaultValue=[1.0], required=[true], nodataExpression=[PT1M,dynamic,1,salary]", streamColumn.toString()); - Assert.assertTrue(streamColumn.getDefaultValue() instanceof Float); - } - - @Test - public void testStreamIntColumn() { - thrown.expect(NumberFormatException.class); - new StreamColumn.Builder().name("salary").type(StreamColumn.Type.INT).defaultValue("eagle").required(true).build(); - } - - @Test - public void testStreamIntColumn1() { - thrown.expect(NumberFormatException.class); - new StreamColumn.Builder().name("salary").type(StreamColumn.Type.INT).defaultValue("0.1").required(true).build(); - } - - - @Test - public void testStreamIntColumn2() { - StreamColumn streamColumn = new StreamColumn.Builder().name("salary").type(StreamColumn.Type.INT).defaultValue("1").required(true).build(); - streamColumn.setNodataExpression("PT1M,dynamic,1,salary"); - Assert.assertEquals("StreamColumn=name[salary], type=[int], defaultValue=[1], required=[true], nodataExpression=[PT1M,dynamic,1,salary]", streamColumn.toString()); - - streamColumn = new StreamColumn.Builder().name("salary").type(StreamColumn.Type.INT).defaultValue("0").required(true).build(); - streamColumn.setNodataExpression("PT1M,dynamic,1,salary"); - Assert.assertEquals("StreamColumn=name[salary], type=[int], defaultValue=[0], required=[true], nodataExpression=[PT1M,dynamic,1,salary]", streamColumn.toString()); - Assert.assertTrue(streamColumn.getDefaultValue() instanceof Integer); - } - - @Test - public void testStreamBoolColumn() { - StreamColumn streamBoolColumn = new StreamColumn.Builder().name("isYhd").type(StreamColumn.Type.BOOL).defaultValue("eagle").required(false).build(); - streamBoolColumn.setNodataExpression("PT1M,dynamic,1,isYhd"); - Assert.assertEquals("StreamColumn=name[isYhd], type=[bool], defaultValue=[false], required=[false], nodataExpression=[PT1M,dynamic,1,isYhd]", streamBoolColumn.toString()); - streamBoolColumn = new StreamColumn.Builder().name("isYhd").type(StreamColumn.Type.BOOL).defaultValue("1").required(true).build(); - streamBoolColumn.setNodataExpression("PT1M,dynamic,1,isYhd"); - Assert.assertEquals("StreamColumn=name[isYhd], type=[bool], defaultValue=[false], required=[true], nodataExpression=[PT1M,dynamic,1,isYhd]", streamBoolColumn.toString()); - streamBoolColumn = new StreamColumn.Builder().name("isYhd").type(StreamColumn.Type.BOOL).defaultValue("0").required(true).build(); - streamBoolColumn.setNodataExpression("PT1M,dynamic,1,isYhd"); - Assert.assertEquals("StreamColumn=name[isYhd], type=[bool], defaultValue=[false], required=[true], nodataExpression=[PT1M,dynamic,1,isYhd]", streamBoolColumn.toString()); - streamBoolColumn = new StreamColumn.Builder().name("isYhd").type(StreamColumn.Type.BOOL).defaultValue("True").required(true).build(); - streamBoolColumn.setNodataExpression("PT1M,dynamic,1,isYhd"); - Assert.assertEquals("StreamColumn=name[isYhd], type=[bool], defaultValue=[true], required=[true], nodataExpression=[PT1M,dynamic,1,isYhd]", streamBoolColumn.toString()); - Assert.assertTrue(streamBoolColumn.getDefaultValue() instanceof Boolean); - } - - @Test - public void testStreamObjectColumn() { - thrown.expect(IllegalArgumentException.class); - new StreamColumn.Builder().name("name").type(StreamColumn.Type.OBJECT).defaultValue("eagle").required(true).build(); - } - - @Test - public void testStreamObjectColumn1() { - StreamColumn streamColumn = new StreamColumn.Builder().name("name").type(StreamColumn.Type.OBJECT).defaultValue("{\"name\":\"heap.COMMITTED\", \"Value\":\"175636480\"}").required(true).build(); - streamColumn.setNodataExpression("PT1M,dynamic,1,name"); - Assert.assertEquals("StreamColumn=name[name], type=[object], defaultValue=[{name=heap.COMMITTED, Value=175636480}], required=[true], nodataExpression=[PT1M,dynamic,1,name]", streamColumn.toString()); - Assert.assertTrue(streamColumn.getDefaultValue() instanceof HashMap); - } -} http://git-wip-us.apache.org/repos/asf/eagle/blob/6fd95d5c/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/alert/engine/coordinator/StreamDefinitionTest.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/alert/engine/coordinator/StreamDefinitionTest.java b/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/alert/engine/coordinator/StreamDefinitionTest.java deleted file mode 100644 index 85ef5dc..0000000 --- a/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/alert/engine/coordinator/StreamDefinitionTest.java +++ /dev/null @@ -1,52 +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.engine.coordinator; - -import org.junit.Assert; -import org.junit.Test; - -import java.util.ArrayList; -import java.util.List; - -public class StreamDefinitionTest { - @Test - public void testStreamDefinition() { - - 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("data").type(StreamColumn.Type.LONG).build()); - streamColumns.add(new StreamColumn.Builder().name("value").type(StreamColumn.Type.DOUBLE).build()); - - StreamDefinition streamDefinition = new StreamDefinition(); - Assert.assertEquals("StreamDefinition[group=global, streamId=null, dataSource=null, description=null, validate=true, timeseries=false, columns=[]", streamDefinition.toString()); - streamDefinition.setColumns(streamColumns); - - Assert.assertEquals(3, streamDefinition.getColumnIndex("data")); - Assert.assertEquals(-1, streamDefinition.getColumnIndex("DATA")); - Assert.assertEquals(-1, streamDefinition.getColumnIndex("isYhd")); - Assert.assertEquals("StreamDefinition[group=global, streamId=null, dataSource=null, description=null, validate=true, timeseries=false, columns=[StreamColumn=name[name], type=[string], defaultValue=[null], required=[true], nodataExpression=[null], StreamColumn=name[host], type=[string], defaultValue=[null], required=[true], nodataExpression=[null], StreamColumn=name[flag], type=[bool], defaultValue=[null], required=[true], nodataExpression=[null], StreamColumn=name[data], type=[long], defaultValue=[null], required=[true], nodataExpression=[null], StreamColumn=name[value], type=[double], defaultValue=[null], required=[true], nodataExpression=[null]]", streamDefinition.toString()); - StreamDefinition streamDefinition1 = streamDefinition.copy(); - Assert.assertEquals("StreamDefinition[group=global, streamId=null, dataSource=null, description=null, validate=true, timeseries=false, columns=[StreamColumn=name[name], type=[string], defaultValue=[null], required=[true], nodataExpression=[null], StreamColumn=name[host], type=[string], defaultValue=[null], required=[true], nodataExpression=[null], StreamColumn=name[flag], type=[bool], defaultValue=[null], required=[true], nodataExpression=[null], StreamColumn=name[data], type=[long], defaultValue=[null], required=[true], nodataExpression=[null], StreamColumn=name[value], type=[double], defaultValue=[null], required=[true], nodataExpression=[null]]", streamDefinition1.toString()); - - Assert.assertTrue(streamDefinition1.equals(streamDefinition)); - Assert.assertFalse(streamDefinition1 == streamDefinition); - Assert.assertTrue(streamDefinition1.hashCode() == streamDefinition.hashCode()); - } -} http://git-wip-us.apache.org/repos/asf/eagle/blob/6fd95d5c/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 deleted file mode 100644 index f7615df..0000000 --- a/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/alert/engine/coordinator/StreamPartitionTest.java +++ /dev/null @@ -1,43 +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.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/eagle/blob/6fd95d5c/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 deleted file mode 100644 index d8123f1..0000000 --- a/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/alert/engine/coordinator/StreamSortSpecTest.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.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/eagle/blob/6fd95d5c/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 deleted file mode 100644 index 2b79cf6..0000000 --- a/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/alert/engine/coordinator/StreamingClusterTest.java +++ /dev/null @@ -1,47 +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.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/eagle/blob/6fd95d5c/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 deleted file mode 100644 index 5903ffd..0000000 --- a/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/alert/engine/model/AlertPublishEventTest.java +++ /dev/null @@ -1,111 +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.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); - alertStreamEvent.ensureAlertId(); - 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.setContext(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/eagle/blob/6fd95d5c/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 deleted file mode 100644 index 6706b1a..0000000 --- a/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/alert/engine/model/AlertStreamEventTest.java +++ /dev/null @@ -1,55 +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.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}); - AlertStreamEvent alertStreamEvent1 = new AlertStreamEvent(alertStreamEvent); - Assert.assertFalse(alertStreamEvent1 == alertStreamEvent); - Assert.assertTrue(alertStreamEvent1.equals(alertStreamEvent)); - Assert.assertTrue(alertStreamEvent1.hashCode() == alertStreamEvent.hashCode()); - } -} http://git-wip-us.apache.org/repos/asf/eagle/blob/6fd95d5c/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 deleted file mode 100644 index 719445b..0000000 --- a/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/alert/engine/model/PartitionedEventTest.java +++ /dev/null @@ -1,54 +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.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/eagle/blob/6fd95d5c/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 deleted file mode 100644 index 16c7ad2..0000000 --- a/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/alert/engine/model/StreamEventBuilderTest.java +++ /dev/null @@ -1,166 +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.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/eagle/blob/6fd95d5c/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 deleted file mode 100644 index 547ef75..0000000 --- a/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/test/java/org/apache/eagle/alert/engine/model/StreamEventTest.java +++ /dev/null @@ -1,204 +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.engine.model; - -import org.apache.eagle.alert.engine.coordinator.StreamColumn; -import org.apache.eagle.alert.engine.coordinator.StreamDefinition; -import org.apache.eagle.alert.utils.StreamValidationException; -import org.apache.eagle.alert.utils.StreamValidator; -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 testStreamValidator() throws StreamValidationException { - StreamDefinition streamDefinition = mockStreamDefinition("TEST_STREAM"); - StreamValidator validator = new StreamValidator(streamDefinition); - thrown.expect(StreamValidationException.class); - validator.validateMap(new HashMap<String, Object>() {{ - put("name", "cpu"); - put("value", 60.0); - }}); - } - - @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
