You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ab...@apache.org on 2017/10/19 10:36:16 UTC
[09/50] [abbrv] lucene-solr:jira/solr-11320: SOLR-11145,
SOLR-11146: Added comprehensive unit tests for Analytics Component
2.0 as well as analytics bug fixes.
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/StringCastFunctionTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/StringCastFunctionTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/StringCastFunctionTest.java
new file mode 100644
index 0000000..79ef86a
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/StringCastFunctionTest.java
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.function.mapping;
+
+import java.util.Arrays;
+import java.util.Iterator;
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.analytics.value.AnalyticsValueStream;
+import org.apache.solr.analytics.value.StringValue;
+import org.apache.solr.analytics.value.StringValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestBooleanValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestIntValue;
+import org.junit.Test;
+
+public class StringCastFunctionTest extends SolrTestCaseJ4 {
+
+ @Test
+ public void singleValueParameterTest() {
+ TestIntValue val = new TestIntValue();
+
+ AnalyticsValueStream uncasted = StringCastFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});
+ assertTrue(uncasted instanceof StringValue);
+ StringValue func = (StringValue) uncasted;
+
+ // Value doesn't exist
+ val.setExists(false);
+ func.getObject();
+ assertFalse(func.exists());
+
+ // Value exists
+ val.setValue(21).setExists(true);
+ assertEquals("21", func.getObject());
+ assertTrue(func.exists());
+
+ val.setValue(-100).setExists(true);
+ assertEquals("-100", func.getObject());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void multiValueParameterTest() {
+ TestBooleanValueStream val = new TestBooleanValueStream();
+
+ AnalyticsValueStream uncasted = StringCastFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});
+ assertTrue(uncasted instanceof StringValueStream);
+ StringValueStream func = (StringValueStream) uncasted;
+
+ // No values
+ val.setValues();
+ func.streamStrings( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // One value
+ val.setValues(true);
+ Iterator<String> values1 = Arrays.asList("true").iterator();
+ func.streamObjects( value -> {
+ assertTrue(values1.hasNext());
+ assertEquals(values1.next(), value);
+ });
+ assertFalse(values1.hasNext());
+
+ // Multiple values
+ val.setValues(true, true, false, false);
+ Iterator<String> values2 = Arrays.asList("true", "true", "false", "false").iterator();
+ func.streamObjects( value -> {
+ assertTrue(values2.hasNext());
+ assertEquals(values2.next(), value);
+ });
+ assertFalse(values2.hasNext());
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/SubtractFunctionTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/SubtractFunctionTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/SubtractFunctionTest.java
new file mode 100644
index 0000000..1095bba
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/SubtractFunctionTest.java
@@ -0,0 +1,128 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.function.mapping;
+
+import java.util.Arrays;
+import java.util.Iterator;
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.analytics.value.AnalyticsValueStream;
+import org.apache.solr.analytics.value.DoubleValue;
+import org.apache.solr.analytics.value.DoubleValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestFloatValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestIntValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestLongValueStream;
+import org.junit.Test;
+
+public class SubtractFunctionTest extends SolrTestCaseJ4 {
+ @Test
+ public void twoSingleValueParametersTest() {
+ TestIntValue minuend = new TestIntValue();
+ TestFloatValue subtrahend = new TestFloatValue();
+
+ AnalyticsValueStream uncasted = SubtractFunction.creatorFunction.apply(new AnalyticsValueStream[] {minuend, subtrahend});
+ assertTrue(uncasted instanceof DoubleValue);
+ DoubleValue func = (DoubleValue) uncasted;
+
+ // Neither exists
+ minuend.setExists(false);
+ subtrahend.setExists(false);
+ func.getDouble();
+ assertFalse(func.exists());
+
+ // One exists
+ minuend.setValue(30).setExists(true);
+ subtrahend.setExists(false);
+ func.getDouble();
+ assertFalse(func.exists());
+
+ // Both exist
+ minuend.setValue(60).setExists(true);
+ subtrahend.setValue(23.56F).setExists(true);
+ assertEquals(36.44, func.getDouble(), 0.00001);
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void oneMultiOneSingleValueParameterTest() {
+ TestLongValueStream minuend = new TestLongValueStream();
+ TestDoubleValue subtrahend = new TestDoubleValue();
+
+ AnalyticsValueStream uncasted = SubtractFunction.creatorFunction.apply(new AnalyticsValueStream[] {minuend, subtrahend});
+ assertTrue(uncasted instanceof DoubleValueStream);
+ DoubleValueStream func = (DoubleValueStream) uncasted;
+
+ // No values, One value
+ minuend.setValues();
+ subtrahend.setValue(21.56F).setExists(true);
+ func.streamDoubles( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple values, no value
+ minuend.setValues(4L, 10023L);
+ subtrahend.setExists(false);
+ func.streamDoubles( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple values, one value
+ minuend.setValues(20L, 5L, 234L);
+ subtrahend.setValue(44.56F).setExists(true);
+ Iterator<Double> values = Arrays.asList(-24.56, -39.56, 189.44).iterator();
+ func.streamDoubles( value -> {
+ assertTrue(values.hasNext());
+ assertEquals(values.next(), value, 0.00001);
+ });
+ assertFalse(values.hasNext());
+ }
+
+ @Test
+ public void oneSingleOneMultiValueParameterTest() {
+ TestDoubleValue minuend = new TestDoubleValue();
+ TestLongValueStream subtrahend = new TestLongValueStream();
+
+ AnalyticsValueStream uncasted = SubtractFunction.creatorFunction.apply(new AnalyticsValueStream[] {minuend, subtrahend});
+ assertTrue(uncasted instanceof DoubleValueStream);
+ DoubleValueStream func = (DoubleValueStream) uncasted;
+
+ // No values, One value
+ minuend.setValue(21.56F).setExists(true);
+ subtrahend.setValues();
+ func.streamDoubles( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple values, no value
+ minuend.setExists(false);
+ subtrahend.setValues(4L, 10023L);
+ func.streamDoubles( value -> {
+ assertTrue("There should be no values to stream", false);
+ });
+
+ // Multiple values, one value
+ minuend.setValue(44.56F).setExists(true);
+ subtrahend.setValues(20L, 5L, 234L);
+ Iterator<Double> values = Arrays.asList(24.56, 39.56, -189.44).iterator();
+ func.streamDoubles( value -> {
+ assertTrue(values.hasNext());
+ assertEquals(values.next(), value, 0.00001);
+ });
+ assertFalse(values.hasNext());
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/TopFunctionTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/TopFunctionTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/TopFunctionTest.java
new file mode 100644
index 0000000..419f883
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/TopFunctionTest.java
@@ -0,0 +1,406 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.function.mapping;
+
+import java.time.Instant;
+import java.time.format.DateTimeParseException;
+import java.util.Date;
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.analytics.value.AnalyticsValueStream;
+import org.apache.solr.analytics.value.DateValue;
+import org.apache.solr.analytics.value.DoubleValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestDateValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestDateValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestDoubleValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestFloatValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestFloatValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestIntValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestIntValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestLongValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestLongValueStream;
+import org.apache.solr.analytics.value.FillableTestValue.TestStringValue;
+import org.apache.solr.analytics.value.FillableTestValue.TestStringValueStream;
+import org.apache.solr.analytics.value.FloatValue;
+import org.apache.solr.analytics.value.IntValue;
+import org.apache.solr.analytics.value.LongValue;
+import org.apache.solr.analytics.value.StringValue;
+import org.junit.Test;
+
+public class TopFunctionTest extends SolrTestCaseJ4 {
+
+ @Test
+ public void multiValueIntTest() {
+ TestIntValueStream val = new TestIntValueStream();
+
+ AnalyticsValueStream uncasted = TopFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});
+ assertTrue(uncasted instanceof IntValue);
+ IntValue func = (IntValue) uncasted;
+
+ // Neither exists
+ val.setValues();
+ func.getInt();
+ assertFalse(func.exists());
+
+ // One exists
+ val.setValues(30);
+ assertEquals(30, func.getInt());
+ assertTrue(func.exists());
+
+ // Both exist
+ val.setValues(30, 20, -10, 59);
+ assertEquals(59, func.getInt());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void multiValueLongTest() {
+ TestLongValueStream val = new TestLongValueStream();
+
+ AnalyticsValueStream uncasted = TopFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});
+ assertTrue(uncasted instanceof LongValue);
+ LongValue func = (LongValue) uncasted;
+
+ // Neither exists
+ val.setValues();
+ func.getLong();
+ assertFalse(func.exists());
+
+ // One exists
+ val.setValues(30L);
+ assertEquals(30L, func.getLong());
+ assertTrue(func.exists());
+
+ // Both exist
+ val.setValues(30L, 20L, -10L, 59L);
+ assertEquals(59L, func.getLong());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void multiValueFloatTest() {
+ TestFloatValueStream val = new TestFloatValueStream();
+
+ AnalyticsValueStream uncasted = TopFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});
+ assertTrue(uncasted instanceof FloatValue);
+ FloatValue func = (FloatValue) uncasted;
+
+ // Neither exists
+ val.setValues();
+ func.getFloat();
+ assertFalse(func.exists());
+
+ // One exists
+ val.setValues(30.0F);
+ assertEquals(30.0F, func.getFloat(), .000001);
+ assertTrue(func.exists());
+
+ // Both exist
+ val.setValues(30.5F, 20.01F, -10.49F, -10.48F);
+ assertEquals(30.5F, func.getFloat(), .000001);
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void multiValueDoubleTest() {
+ TestDoubleValueStream val = new TestDoubleValueStream();
+
+ AnalyticsValueStream uncasted = TopFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});
+ assertTrue(uncasted instanceof DoubleValue);
+ DoubleValue func = (DoubleValue) uncasted;
+
+ // Neither exists
+ val.setValues();
+ func.getDouble();
+ assertFalse(func.exists());
+
+ // One exists
+ val.setValues(30.0);
+ assertEquals(30.0, func.getDouble(), .000001);
+ assertTrue(func.exists());
+
+ // Both exist
+ val.setValues(30.5, 20.01, -10.49, -10.48);
+ assertEquals(30.5, func.getDouble(), .000001);
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void multiValueDateTest() throws DateTimeParseException {
+ TestDateValueStream val = new TestDateValueStream();
+
+ AnalyticsValueStream uncasted = TopFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});
+ assertTrue(uncasted instanceof DateValue);
+ DateValue func = (DateValue) uncasted;
+
+ // Neither exists
+ val.setValues();
+ func.getDate();
+ assertFalse(func.exists());
+
+ // One exists
+ val.setValues("1950-05-03T10:30:50Z");
+ assertEquals(Date.from(Instant.parse("1950-05-03T10:30:50Z")), func.getDate());
+ assertTrue(func.exists());
+
+ // Both exist
+ val.setValues("1950-05-03T10:30:50Z", "2200-01-01T10:00:50Z", "1800-12-31T11:30:50Z", "1930-05-020T10:45:50Z");
+ assertEquals(Date.from(Instant.parse("2200-01-01T10:00:50Z")), func.getDate());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void multiValueStringTest() {
+ TestStringValueStream val = new TestStringValueStream();
+
+ AnalyticsValueStream uncasted = TopFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});
+ assertTrue(uncasted instanceof StringValue);
+ StringValue func = (StringValue) uncasted;
+
+ // Neither exists
+ val.setValues();
+ func.getString();
+ assertFalse(func.exists());
+
+ // One exists
+ val.setValues("abc");
+ assertEquals("abc", func.getString());
+ assertTrue(func.exists());
+
+ // Both exist
+ val.setValues("1abcdef", "abc", "def", "def1", "1abc");
+ assertEquals("def1", func.getString());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void multipleSingleValueIntTest() {
+ TestIntValue val1 = new TestIntValue();
+ TestIntValue val2 = new TestIntValue();
+ TestIntValue val3 = new TestIntValue();
+ TestIntValue val4 = new TestIntValue();
+
+ AnalyticsValueStream uncasted = TopFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2, val3, val4});
+ assertTrue(uncasted instanceof IntValue);
+ IntValue func = (IntValue) uncasted;
+
+ // None exist
+ val1.setExists(false);
+ val2.setExists(false);
+ val3.setExists(false);
+ val4.setExists(false);
+ func.getInt();
+ assertFalse(func.exists());
+
+ // Some exist
+ val1.setValue(1000).setExists(false);
+ val2.setValue(30).setExists(true);
+ val3.setValue(-1000).setExists(false);
+ val4.setValue(12).setExists(true);
+ assertEquals(30, func.getInt());
+ assertTrue(func.exists());
+
+ // All exist values, one value
+ val1.setValue(45).setExists(true);
+ val2.setValue(30).setExists(true);
+ val3.setValue(-2).setExists(true);
+ val4.setValue(12).setExists(true);
+ assertEquals(45, func.getInt());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void multipleSingleValueLongTest() {
+ TestLongValue val1 = new TestLongValue();
+ TestLongValue val2 = new TestLongValue();
+ TestLongValue val3 = new TestLongValue();
+ TestLongValue val4 = new TestLongValue();
+
+ AnalyticsValueStream uncasted = TopFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2, val3, val4});
+ assertTrue(uncasted instanceof LongValue);
+ LongValue func = (LongValue) uncasted;
+
+ // None exist
+ val1.setExists(false);
+ val2.setExists(false);
+ val3.setExists(false);
+ val4.setExists(false);
+ func.getLong();
+ assertFalse(func.exists());
+
+ // Some exist
+ val1.setValue(1000L).setExists(false);
+ val2.setValue(30L).setExists(true);
+ val3.setValue(-1000L).setExists(false);
+ val4.setValue(12L).setExists(true);
+ assertEquals(30L, func.getLong());
+ assertTrue(func.exists());
+
+ // All exist values, one value
+ val1.setValue(45L).setExists(true);
+ val2.setValue(30L).setExists(true);
+ val3.setValue(-2L).setExists(true);
+ val4.setValue(12L).setExists(true);
+ assertEquals(45L, func.getLong());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void multipleSingleValueFloatTest() {
+ TestFloatValue val1 = new TestFloatValue();
+ TestFloatValue val2 = new TestFloatValue();
+ TestFloatValue val3 = new TestFloatValue();
+ TestFloatValue val4 = new TestFloatValue();
+
+ AnalyticsValueStream uncasted = TopFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2, val3, val4});
+ assertTrue(uncasted instanceof FloatValue);
+ FloatValue func = (FloatValue) uncasted;
+
+ // None exist
+ val1.setExists(false);
+ val2.setExists(false);
+ val3.setExists(false);
+ val4.setExists(false);
+ func.getFloat();
+ assertFalse(func.exists());
+
+ // Some exist
+ val1.setValue(1000.1233F).setExists(false);
+ val2.setValue(30.34F).setExists(true);
+ val3.setValue(-1000.3241F).setExists(false);
+ val4.setValue(12.123F).setExists(true);
+ assertEquals(30.34F, func.getFloat(), .000001);
+ assertTrue(func.exists());
+
+ // All exist values, one value
+ val1.setValue(45.43F).setExists(true);
+ val2.setValue(30.231F).setExists(true);
+ val3.setValue(-2.33F).setExists(true);
+ val4.setValue(12.5F).setExists(true);
+ assertEquals(45.43F, func.getFloat(), .000001);
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void multipleSingleValueDoubleTest() {
+ TestDoubleValue val1 = new TestDoubleValue();
+ TestDoubleValue val2 = new TestDoubleValue();
+ TestDoubleValue val3 = new TestDoubleValue();
+ TestDoubleValue val4 = new TestDoubleValue();
+
+ AnalyticsValueStream uncasted = TopFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2, val3, val4});
+ assertTrue(uncasted instanceof DoubleValue);
+ DoubleValue func = (DoubleValue) uncasted;
+
+ // None exist
+ val1.setExists(false);
+ val2.setExists(false);
+ val3.setExists(false);
+ val4.setExists(false);
+ func.getDouble();
+ assertFalse(func.exists());
+
+ // Some exist
+ val1.setValue(1000.1233).setExists(false);
+ val2.setValue(30.34).setExists(true);
+ val3.setValue(-1000.3241).setExists(false);
+ val4.setValue(12.123).setExists(true);
+ assertEquals(30.34, func.getDouble(), .000001);
+ assertTrue(func.exists());
+
+ // All exist values, one value
+ val1.setValue(45.43).setExists(true);
+ val2.setValue(30.231).setExists(true);
+ val3.setValue(-2.33).setExists(true);
+ val4.setValue(12.5).setExists(true);
+ assertEquals(45.43, func.getDouble(), .000001);
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void multipleSingleValueDateTest() throws DateTimeParseException {
+ TestDateValue val1 = new TestDateValue();
+ TestDateValue val2 = new TestDateValue();
+ TestDateValue val3 = new TestDateValue();
+ TestDateValue val4 = new TestDateValue();
+
+ AnalyticsValueStream uncasted = TopFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2, val3, val4});
+ assertTrue(uncasted instanceof DateValue);
+ DateValue func = (DateValue) uncasted;
+
+ // None exist
+ val1.setExists(false);
+ val2.setExists(false);
+ val3.setExists(false);
+ val4.setExists(false);
+ func.getDate();
+ assertFalse(func.exists());
+
+ // Some exist
+ val1.setValue("9999-05-03T10:30:50Z").setExists(false);
+ val2.setValue("1950-05-03T10:30:50Z").setExists(true);
+ val3.setValue("0000-05-03T10:30:50Z").setExists(false);
+ val4.setValue("1850-05-03T10:30:50Z").setExists(true);
+ assertEquals(Date.from(Instant.parse("1950-05-03T10:30:50Z")), func.getDate());
+ assertTrue(func.exists());
+
+ // All exist values, one value
+ val1.setValue("2200-05-03T10:30:50Z").setExists(true);
+ val2.setValue("1950-05-03T10:30:50Z").setExists(true);
+ val3.setValue("1700-05-03T10:30:50Z").setExists(true);
+ val4.setValue("1850-05-03T10:30:50Z").setExists(true);
+ assertEquals(Date.from(Instant.parse("2200-05-03T10:30:50Z")), func.getDate());
+ assertTrue(func.exists());
+ }
+
+ @Test
+ public void multipleStringValueDateTest() {
+ TestStringValue val1 = new TestStringValue();
+ TestStringValue val2 = new TestStringValue();
+ TestStringValue val3 = new TestStringValue();
+ TestStringValue val4 = new TestStringValue();
+
+ AnalyticsValueStream uncasted = TopFunction.creatorFunction.apply(new AnalyticsValueStream[] {val1, val2, val3, val4});
+ assertTrue(uncasted instanceof StringValue);
+ StringValue func = (StringValue) uncasted;
+
+ // None exist
+ val1.setExists(false);
+ val2.setExists(false);
+ val3.setExists(false);
+ val4.setExists(false);
+ func.getString();
+ assertFalse(func.exists());
+
+ // Some exist
+ val1.setValue("abc").setExists(true);
+ val2.setValue("1111").setExists(false);
+ val3.setValue("asdfads").setExists(true);
+ val4.setValue("zzzzzzzz").setExists(false);
+ assertEquals("asdfads", func.getString());
+ assertTrue(func.exists());
+
+ // All exist values, one value
+ val1.setValue("abc").setExists(true);
+ val2.setValue("abc1234").setExists(true);
+ val3.setValue("fdgsfg1").setExists(true);
+ val4.setValue("fdgsfg").setExists(true);
+ assertEquals("fdgsfg1", func.getString());
+ assertTrue(func.exists());
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/LegacyAbstractAnalyticsCloudTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/LegacyAbstractAnalyticsCloudTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/LegacyAbstractAnalyticsCloudTest.java
new file mode 100644
index 0000000..f34c667
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/LegacyAbstractAnalyticsCloudTest.java
@@ -0,0 +1,167 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.legacy;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+
+import org.apache.solr.analytics.util.AnalyticsResponseHeadings;
+import org.apache.solr.analytics.util.MedianCalculator;
+import org.apache.solr.analytics.util.OrdinalCalculator;
+import org.apache.solr.client.solrj.SolrServerException;
+import org.apache.solr.client.solrj.request.CollectionAdminRequest;
+import org.apache.solr.client.solrj.request.QueryRequest;
+import org.apache.solr.client.solrj.request.UpdateRequest;
+import org.apache.solr.client.solrj.response.QueryResponse;
+import org.apache.solr.cloud.AbstractDistribZkTestBase;
+import org.apache.solr.cloud.SolrCloudTestCase;
+import org.apache.solr.common.params.ModifiableSolrParams;
+import org.apache.solr.common.util.NamedList;
+import org.junit.BeforeClass;
+
+public class LegacyAbstractAnalyticsCloudTest extends SolrCloudTestCase {
+
+ protected static final String COLLECTIONORALIAS = "collection1";
+ protected static final int TIMEOUT = DEFAULT_TIMEOUT;
+ protected static final String id = "id";
+
+ @BeforeClass
+ public static void setupCollection() throws Exception {
+ configureCluster(4)
+ .addConfig("conf", configset("cloud-analytics"))
+ .configure();
+
+ CollectionAdminRequest.createCollection(COLLECTIONORALIAS, "conf", 2, 1).process(cluster.getSolrClient());
+ AbstractDistribZkTestBase.waitForRecoveriesToFinish(COLLECTIONORALIAS, cluster.getSolrClient().getZkStateReader(),
+ false, true, TIMEOUT);
+ cleanIndex();
+ }
+
+ public static void cleanIndex() throws Exception {
+ new UpdateRequest()
+ .deleteByQuery("*:*")
+ .commit(cluster.getSolrClient(), COLLECTIONORALIAS);
+ }
+
+ protected static final String[] BASEPARMS = new String[]{ "q", "*:*", "indent", "true", "olap", "true", "rows", "0" };
+
+ public static enum VAL_TYPE {
+ INTEGER("int"),
+ LONG("long"),
+ FLOAT("float"),
+ DOUBLE("double"),
+ STRING("str"),
+ DATE("date");
+
+ private VAL_TYPE (final String text) {
+ this.text = text;
+ }
+
+ private final String text;
+
+ @Override
+ public String toString() {
+ return text;
+ }
+ }
+
+ protected NamedList<Object> queryLegacyCloudAnalytics(String[] testParams) throws SolrServerException, IOException, InterruptedException {
+ ModifiableSolrParams params = new ModifiableSolrParams();
+ params.set("q", "*:*");
+ params.set("indent", "true");
+ params.set("olap", "true");
+ params.set("rows", "0");
+ for (int i = 0; i + 1 < testParams.length;) {
+ params.add(testParams[i++], testParams[i++]);
+ }
+ cluster.waitForAllNodes(10000);
+ QueryRequest qreq = new QueryRequest(params);
+ QueryResponse resp = qreq.process(cluster.getSolrClient(), COLLECTIONORALIAS);
+ return resp.getResponse();
+ }
+
+ @SuppressWarnings("unchecked")
+ protected <T> T getValue(NamedList<Object> response, String infoName, String exprName) {
+ return (T)response.findRecursive(AnalyticsResponseHeadings.COMPLETED_OLD_HEADER,
+ infoName,
+ exprName);
+ }
+
+ public <T extends Number & Comparable<T>> Double calculateNumberStat(ArrayList<T> list, String stat) {
+ Double result;
+ if (stat.equals("median")) {
+ result = MedianCalculator.getMedian(list);
+ } else if (stat.equals("mean")) {
+ double d = 0;
+ for (T element : list) {
+ d += element.doubleValue();
+ }
+ result = Double.valueOf(d/list.size());
+ } else if (stat.equals("sum")) {
+ double d = 0;
+ for (T element : list) {
+ d += element.doubleValue();
+ }
+ result = Double.valueOf(d);
+ } else if (stat.equals("sumOfSquares")) {
+ double d = 0;
+ for (T element : list) {
+ d += element.doubleValue()*element.doubleValue();
+ }
+ result = Double.valueOf(d);
+ } else if (stat.equals("stddev")) {
+ double sum = 0;
+ double sumSquares = 0;
+ for (T element : list) {
+ sum += element.doubleValue();
+ sumSquares += element.doubleValue()*element.doubleValue();
+ }
+ result = Math.sqrt(sumSquares/list.size()-sum*sum/(list.size()*list.size()));
+ } else {
+ throw new IllegalArgumentException();
+ }
+ return result;
+ }
+
+ public <T extends Comparable<T>> Object calculateStat(ArrayList<T> list, String stat) {
+ Object result;
+ if (stat.contains("perc_")) {
+ ArrayList<Integer> percs = new ArrayList<>(1);
+ int ord = (int) Math.ceil(Double.parseDouble(stat.substring(5))/100 * list.size()) - 1;
+ percs.add(ord);
+ OrdinalCalculator.putOrdinalsInPosition(list, percs);
+ result = list.get(percs.get(0));
+ } else if (stat.equals("count")) {
+ result = Long.valueOf(list.size());
+ } else if (stat.equals("unique")) {
+ HashSet<T> set = new HashSet<>();
+ set.addAll(list);
+ result = Long.valueOf((long)set.size());
+ } else if (stat.equals("max")) {
+ Collections.sort(list);
+ result = list.get(list.size()-1);
+ } else if (stat.equals("min")) {
+ Collections.sort(list);
+ result = list.get(0);
+ } else {
+ result = null;
+ }
+ return result;
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/LegacyAbstractAnalyticsTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/LegacyAbstractAnalyticsTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/LegacyAbstractAnalyticsTest.java
new file mode 100644
index 0000000..3488f63
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/LegacyAbstractAnalyticsTest.java
@@ -0,0 +1,234 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.legacy;
+
+import java.io.ByteArrayInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Scanner;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathExpressionException;
+import javax.xml.xpath.XPathFactory;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.lucene.util.IOUtils;
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.analytics.util.AnalyticsResponseHeadings;
+import org.apache.solr.analytics.util.MedianCalculator;
+import org.apache.solr.analytics.util.OrdinalCalculator;
+import org.apache.solr.request.SolrQueryRequest;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.w3c.dom.Document;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+import com.google.common.collect.ObjectArrays;
+
+public class LegacyAbstractAnalyticsTest extends SolrTestCaseJ4 {
+
+ protected static final String[] BASEPARMS = new String[]{ "q", "*:*", "indent", "true", "olap", "true", "rows", "0" };
+ protected static final HashMap<String,Object> defaults = new HashMap<>();
+
+ public static enum VAL_TYPE {
+ INTEGER("int"),
+ LONG("long"),
+ FLOAT("float"),
+ DOUBLE("double"),
+ STRING("str"),
+ DATE("date");
+
+ private VAL_TYPE (final String text) {
+ this.text = text;
+ }
+
+ private final String text;
+
+ @Override
+ public String toString() {
+ return text;
+ }
+ }
+
+ static private Document doc;
+ static private XPathFactory xPathFact;
+
+ static private String rawResponse;
+
+ @BeforeClass
+ public static void beforeClassAbstractAnalysis() {
+ xPathFact = XPathFactory.newInstance();
+ }
+
+ @AfterClass
+ public static void afterClassAbstractAnalysis() {
+ xPathFact = null;
+ doc = null;
+ rawResponse = null;
+ defaults.clear();
+ }
+
+ public static void setResponse(String response) throws ParserConfigurationException, IOException, SAXException {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ factory.setNamespaceAware(true); // never forget this!
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ doc = builder.parse(new InputSource(new ByteArrayInputStream(response.getBytes(StandardCharsets.UTF_8))));
+ rawResponse = response;
+ }
+
+ protected String getRawResponse() {
+ return rawResponse;
+ }
+
+ public Object getStatResult(String section, String name, VAL_TYPE type) throws XPathExpressionException {
+
+ // Construct the XPath expression. The form better not change or all these will fail.
+ StringBuilder sb = new StringBuilder("/response/lst[@name='"+AnalyticsResponseHeadings.COMPLETED_OLD_HEADER+"']/lst[@name='").append(section).append("']");
+
+ // This is a little fragile in that it demands the elements have the same name as type, i.e. when looking for a
+ // VAL_TYPE.DOUBLE, the element in question is <double name="blah">47.0</double>.
+ sb.append("/").append(type.toString()).append("[@name='").append(name).append("']");
+ String val = xPathFact.newXPath().compile(sb.toString()).evaluate(doc, XPathConstants.STRING).toString();
+ try {
+ switch (type) {
+ case INTEGER: return Integer.parseInt(val);
+ case DOUBLE: return Double.parseDouble(val);
+ case FLOAT: return Float.parseFloat(val);
+ case LONG: return Long.parseLong(val);
+ case STRING: assertTrue(rawResponse, val != null && val.length() > 0 ); return val;
+ case DATE: assertTrue(rawResponse, val != null && val.length() > 0 ); return val;
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail("Caught exception in getStatResult, xPath = " + sb.toString() + " \nraw data: " + rawResponse);
+ }
+ fail("Unknown type used in getStatResult");
+ return null; // Really can't get here, but the compiler thinks we can!
+ }
+
+
+ public <T extends Number & Comparable<T>> Double calculateNumberStat(ArrayList<T> list, String stat) {
+ Double result;
+ if (stat.equals("median")) {
+ result = MedianCalculator.getMedian(list);
+ } else if (stat.equals("mean")) {
+ double d = 0;
+ for (T element : list) {
+ d += element.doubleValue();
+ }
+ result = Double.valueOf(d/list.size());
+ } else if (stat.equals("sum")) {
+ double d = 0;
+ for (T element : list) {
+ d += element.doubleValue();
+ }
+ result = Double.valueOf(d);
+ } else if (stat.equals("sumOfSquares")) {
+ double d = 0;
+ for (T element : list) {
+ d += element.doubleValue()*element.doubleValue();
+ }
+ result = Double.valueOf(d);
+ } else if (stat.equals("stddev")) {
+ double sum = 0;
+ double sumSquares = 0;
+ for (T element : list) {
+ sum += element.doubleValue();
+ sumSquares += element.doubleValue()*element.doubleValue();
+ }
+ result = Math.sqrt(sumSquares/list.size()-sum*sum/(list.size()*list.size()));
+ } else {
+ throw new IllegalArgumentException();
+ }
+ return result;
+ }
+
+ public <T extends Comparable<T>> Object calculateStat(ArrayList<T> list, String stat) {
+ Object result;
+ if (stat.contains("perc_")) {
+ ArrayList<Integer> percs = new ArrayList<>(1);
+ int ord = (int) Math.ceil(Double.parseDouble(stat.substring(5))/100 * list.size()) - 1;
+ percs.add(ord);
+ OrdinalCalculator.putOrdinalsInPosition(list, percs);
+ result = list.get(percs.get(0));
+ } else if (stat.equals("count")) {
+ result = Long.valueOf(list.size());
+ } else if (stat.equals("unique")) {
+ HashSet<T> set = new HashSet<>();
+ set.addAll(list);
+ result = Long.valueOf((long)set.size());
+ } else if (stat.equals("max")) {
+ Collections.sort(list);
+ result = list.get(list.size()-1);
+ } else if (stat.equals("min")) {
+ Collections.sort(list);
+ result = list.get(0);
+ } else {
+ result = null;
+ }
+ return result;
+ }
+
+ @SuppressWarnings("unchecked")
+ public <T extends Comparable<T>> Long calculateMissing(ArrayList<T> list, String type) {
+ T def = (T)defaults.get(type);
+ long miss = 0;
+ for (T element : list) {
+ if (element.compareTo(def)==0) {
+ miss++;
+ }
+ }
+ return Long.valueOf(miss);
+ }
+
+ public static SolrQueryRequest request(String...args){
+ return SolrTestCaseJ4.req( ObjectArrays.concat(BASEPARMS, args,String.class) );
+ }
+
+ public static String[] fileToStringArr(Class<?> clazz, String fileName) throws FileNotFoundException {
+ InputStream in = clazz.getResourceAsStream("/solr/analytics/legacy/" + fileName);
+ if (in == null) throw new FileNotFoundException("Resource not found: " + fileName);
+ Scanner file = new Scanner(in, "UTF-8");
+ try {
+ ArrayList<String> strList = new ArrayList<>();
+ while (file.hasNextLine()) {
+ String line = file.nextLine();
+ line = line.trim();
+ if( StringUtils.isBlank(line) || line.startsWith("#")){
+ continue;
+ }
+ String[] param = line.split("=");
+ strList.add(param[0]);
+ strList.add(param[1]);
+ }
+ return strList.toArray(new String[0]);
+ } finally {
+ IOUtils.closeWhileHandlingException(file, in);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/LegacyNoFacetCloudTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/LegacyNoFacetCloudTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/LegacyNoFacetCloudTest.java
new file mode 100644
index 0000000..7489f3f
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/LegacyNoFacetCloudTest.java
@@ -0,0 +1,551 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.legacy;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.solr.client.solrj.request.UpdateRequest;
+import org.apache.solr.common.util.NamedList;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class LegacyNoFacetCloudTest extends LegacyAbstractAnalyticsCloudTest {
+ static public final int INT = 71;
+ static public final int LONG = 36;
+ static public final int FLOAT = 93;
+ static public final int DOUBLE = 49;
+ static public final int DATE = 12;
+ static public final int STRING = 28;
+ static public final int NUM_LOOPS = 100;
+
+ //INT
+ static ArrayList<Integer> intTestStart;
+ static long intMissing = 0;
+
+ //LONG
+ static ArrayList<Long> longTestStart;
+ static long longMissing = 0;
+
+ //FLOAT
+ static ArrayList<Float> floatTestStart;
+ static long floatMissing = 0;
+
+ //DOUBLE
+ static ArrayList<Double> doubleTestStart;
+ static long doubleMissing = 0;
+
+ //DATE
+ static ArrayList<String> dateTestStart;
+ static long dateMissing = 0;
+
+ //STR
+ static ArrayList<String> stringTestStart;
+ static long stringMissing = 0;
+
+ @BeforeClass
+ public static void populate() throws Exception {
+ cleanIndex();
+
+ intTestStart = new ArrayList<>();
+ longTestStart = new ArrayList<>();
+ floatTestStart = new ArrayList<>();
+ doubleTestStart = new ArrayList<>();
+ dateTestStart = new ArrayList<>();
+ stringTestStart = new ArrayList<>();
+
+ UpdateRequest req = new UpdateRequest();
+ for (int j = 0; j < NUM_LOOPS; ++j) {
+ int i = j%INT;
+ long l = j%LONG;
+ float f = j%FLOAT;
+ double d = j%DOUBLE;
+ String dt = (1800+j%DATE) + "-12-31T23:59:59Z";
+ String s = "str" + (j%STRING);
+ List<String> fields = new ArrayList<>();
+ fields.add("id"); fields.add("1000"+j);
+
+ if( i != 0 ){
+ fields.add("int_id"); fields.add("" + i);
+ intTestStart.add(i);
+ } else intMissing++;
+
+ if( l != 0l ){
+ fields.add("long_ld"); fields.add("" + l);
+ longTestStart.add(l);
+ } else longMissing++;
+
+ if( f != 0.0f ){
+ fields.add("float_fd"); fields.add("" + f);
+ floatTestStart.add(f);
+ } else floatMissing++;
+
+ if( d != 0.0d ){
+ fields.add("double_dd"); fields.add("" + d);
+ doubleTestStart.add(d);
+ } else doubleMissing++;
+
+ if( (j%DATE) != 0 ){
+ fields.add("date_dtd"); fields.add(dt);
+ dateTestStart.add(dt);
+ } else dateMissing++;
+
+ if( (j%STRING) != 0 ){
+ fields.add("string_sd"); fields.add(s);
+ stringTestStart.add(s);
+ } else stringMissing++;
+
+ req.add(fields.toArray(new String[0]));
+ }
+ req.commit(cluster.getSolrClient(), COLLECTIONORALIAS);
+ }
+
+ @Test
+ public void sumTest() throws Exception {
+ String[] params = new String[] {
+ "o.sr.s.int_id", "sum(int_id)",
+ "o.sr.s.long_ld", "sum(long_ld)",
+ "o.sr.s.float_fd", "sum(float_fd)",
+ "o.sr.s.double_dd", "sum(double_dd)"
+ };
+ NamedList<Object> response = queryLegacyCloudAnalytics(params);
+ String responseStr = response.toString();
+
+ //Int
+ Double intResult = getValue(response, "sr", "int_id");
+ Double intTest = (Double)calculateNumberStat(intTestStart, "sum");
+ assertEquals(responseStr, intResult,intTest);
+
+ //Long
+ Double longResult = getValue(response, "sr", "long_ld");
+ Double longTest = (Double)calculateNumberStat(longTestStart, "sum");
+ assertEquals(responseStr, longResult,longTest);
+
+ //Float
+ Double floatResult = getValue(response, "sr", "float_fd");
+ Double floatTest = (Double)calculateNumberStat(floatTestStart, "sum");
+ assertEquals(responseStr, floatResult,floatTest);
+
+ //Double
+ Double doubleResult = getValue(response, "sr", "double_dd");
+ Double doubleTest = (Double) calculateNumberStat(doubleTestStart, "sum");
+ assertEquals(responseStr, doubleResult,doubleTest);
+ }
+
+ @Test
+ public void meanTest() throws Exception {
+ String[] params = new String[] {
+ "o.mr.s.int_id", "mean(int_id)",
+ "o.mr.s.long_ld", "mean(long_ld)",
+ "o.mr.s.float_fd", "mean(float_fd)",
+ "o.mr.s.double_dd", "mean(double_dd)"
+ };
+ NamedList<Object> response = queryLegacyCloudAnalytics(params);
+ String responseStr = response.toString();
+
+ //Int
+ Double intResult = getValue(response, "mr", "int_id");
+ Double intTest = (Double)calculateNumberStat(intTestStart, "mean");
+ assertEquals(responseStr, intResult,intTest);
+
+ //Long
+ Double longResult = getValue(response, "mr", "long_ld");
+ Double longTest = (Double)calculateNumberStat(longTestStart, "mean");
+ assertEquals(responseStr, longResult,longTest);
+
+ //Float
+ Double floatResult = getValue(response, "mr", "float_fd");
+ Double floatTest = (Double)calculateNumberStat(floatTestStart, "mean");
+ assertEquals(responseStr, floatResult,floatTest);
+
+ //Double
+ Double doubleResult = getValue(response, "mr", "double_dd");
+ Double doubleTest = (Double)calculateNumberStat(doubleTestStart, "mean");
+ assertEquals(responseStr, doubleResult,doubleTest);
+ }
+
+ @Test
+ public void stddevTest() throws Exception {
+ String[] params = new String[] {
+ "o.str.s.int_id", "stddev(int_id)",
+ "o.str.s.long_ld", "stddev(long_ld)",
+ "o.str.s.float_fd", "stddev(float_fd)",
+ "o.str.s.double_dd", "stddev(double_dd)"
+ };
+ NamedList<Object> response = queryLegacyCloudAnalytics(params);
+ String responseStr = response.toString();
+
+ //Int
+ Double intResult = getValue(response, "str", "int_id");
+ Double intTest = (Double)calculateNumberStat(intTestStart, "stddev");
+ assertEquals(responseStr, intResult, intTest, 0.00000000001);
+
+ //Long
+ Double longResult = getValue(response, "str", "long_ld");
+ Double longTest = (Double)calculateNumberStat(longTestStart, "stddev");
+ assertEquals(responseStr, longResult, longTest, 0.00000000001);
+
+ //Float
+ Double floatResult = getValue(response, "str", "float_fd");
+ Double floatTest = (Double)calculateNumberStat(floatTestStart, "stddev");
+ assertEquals(responseStr, floatResult, floatTest, 0.00000000001);
+
+
+ //Double
+ Double doubleResult = getValue(response, "str", "double_dd");
+ Double doubleTest = (Double)calculateNumberStat(doubleTestStart, "stddev");
+ assertEquals(responseStr, doubleResult, doubleTest, 0.00000000001);
+ }
+
+ @Test
+ public void medianTest() throws Exception {
+ String[] params = new String[] {
+ "o.medr.s.int_id", "median(int_id)",
+ "o.medr.s.long_ld", "median(long_ld)",
+ "o.medr.s.float_fd", "median(float_fd)",
+ "o.medr.s.double_dd", "median(double_dd)",
+ "o.medr.s.date_dtd", "median(date_dtd)"
+ };
+ NamedList<Object> response = queryLegacyCloudAnalytics(params);
+ String responseStr = response.toString();
+
+ //Int
+ Double intResult = getValue(response, "medr", "int_id");
+ Double intTest = (Double)calculateNumberStat(intTestStart, "median");
+ assertEquals(responseStr, intResult,intTest);
+
+ //Long
+ Double longResult = getValue(response, "medr", "long_ld");
+ Double longTest = (Double)calculateNumberStat(longTestStart, "median");
+ assertEquals(responseStr, longResult,longTest);
+
+ //Float
+ Double floatResult = getValue(response, "medr", "float_fd");
+ Double floatTest = (Double)calculateNumberStat(floatTestStart, "median");
+ assertEquals(responseStr, floatResult,floatTest);
+
+ //Double
+ Double doubleResult = getValue(response, "medr", "double_dd");
+ Double doubleTest = (Double)calculateNumberStat(doubleTestStart, "median");
+ assertEquals(responseStr, doubleResult,doubleTest);
+
+ // TODO: Add test for date median
+ }
+
+ @Test
+ public void perc20Test() throws Exception {
+ String[] params = new String[] {
+ "o.p2r.s.int_id", "percentile(20,int_id)",
+ "o.p2r.s.long_ld", "percentile(20,long_ld)",
+ "o.p2r.s.float_fd", "percentile(20,float_fd)",
+ "o.p2r.s.double_dd", "percentile(20,double_dd)",
+ "o.p2r.s.date_dtd", "string(percentile(20,date_dtd))",
+ "o.p2r.s.string_sd", "percentile(20,string_sd)"
+ };
+ NamedList<Object> response = queryLegacyCloudAnalytics(params);
+ String responseStr = response.toString();
+
+ //Int 20
+ Integer intResult = getValue(response, "p2r", "int_id");
+ Integer intTest = (Integer)calculateStat(intTestStart, "perc_20");
+ assertEquals(responseStr, intResult,intTest);
+
+ //Long 20
+ Long longResult = getValue(response, "p2r", "long_ld");
+ Long longTest = (Long)calculateStat(longTestStart, "perc_20");
+ assertEquals(responseStr, longResult,longTest);
+
+ //Float 20
+ Float floatResult = getValue(response, "p2r", "float_fd");
+ Float floatTest = (Float)calculateStat(floatTestStart, "perc_20");
+ assertEquals(responseStr, floatResult,floatTest);
+
+ //Double 20
+ Double doubleResult = getValue(response, "p2r", "double_dd");
+ Double doubleTest = (Double)calculateStat(doubleTestStart, "perc_20");
+ assertEquals(responseStr, doubleResult,doubleTest);
+
+ //Date 20
+ String dateResult = getValue(response, "p2r", "date_dtd");
+ String dateTest = (String)calculateStat(dateTestStart, "perc_20");
+ assertEquals(responseStr, dateResult,dateTest);
+
+ //String 20
+ String stringResult = getValue(response, "p2r", "string_sd");
+ String stringTest = (String)calculateStat(stringTestStart, "perc_20");
+ assertEquals(responseStr, stringResult,stringTest);
+ }
+
+ @Test
+ public void perc60Test() throws Exception {
+ String[] params = new String[] {
+ "o.p6r.s.int_id", "percentile(60,int_id)",
+ "o.p6r.s.long_ld", "percentile(60,long_ld)",
+ "o.p6r.s.float_fd", "percentile(60,float_fd)",
+ "o.p6r.s.double_dd", "percentile(60,double_dd)",
+ "o.p6r.s.date_dtd", "string(percentile(60,date_dtd))",
+ "o.p6r.s.string_sd", "percentile(60,string_sd)"
+ };
+ NamedList<Object> response = queryLegacyCloudAnalytics(params);
+ String responseStr = response.toString();
+
+ //Int 60
+ Integer intResult = getValue(response, "p6r", "int_id");
+ Integer intTest = (Integer)calculateStat(intTestStart, "perc_60");
+ assertEquals(responseStr, intResult,intTest);
+
+ //Long 60
+ Long longResult = getValue(response, "p6r", "long_ld");
+ Long longTest = (Long)calculateStat(longTestStart, "perc_60");
+ assertEquals(responseStr, longResult,longTest);
+
+ //Float 60
+ Float floatResult = getValue(response, "p6r", "float_fd");
+ Float floatTest = (Float)calculateStat(floatTestStart, "perc_60");
+ assertEquals(responseStr, floatResult,floatTest);
+
+ //Double 60
+ Double doubleResult = getValue(response, "p6r", "double_dd");
+ Double doubleTest = (Double)calculateStat(doubleTestStart, "perc_60");
+ assertEquals(responseStr, doubleResult,doubleTest);
+
+ //Date 60
+ String dateResult = getValue(response, "p6r", "date_dtd");
+ String dateTest = (String)calculateStat(dateTestStart, "perc_60");
+ assertEquals(responseStr, dateResult,dateTest);
+
+ //String 60
+ String stringResult = getValue(response, "p6r", "string_sd");
+ String stringTest = (String)calculateStat(stringTestStart, "perc_60");
+ assertEquals(responseStr, stringResult,stringTest);
+ }
+
+ @Test
+ public void minTest() throws Exception {
+ String[] params = new String[] {
+ "o.mir.s.int_id", "min(int_id)",
+ "o.mir.s.long_ld", "min(long_ld)",
+ "o.mir.s.float_fd", "min(float_fd)",
+ "o.mir.s.double_dd", "min(double_dd)",
+ "o.mir.s.date_dtd", "string(min(date_dtd))",
+ "o.mir.s.string_sd", "min(string_sd)"
+ };
+ NamedList<Object> response = queryLegacyCloudAnalytics(params);
+ String responseStr = response.toString();
+
+ //Int
+ Integer intResult = getValue(response, "mir", "int_id");
+ Integer intTest = (Integer)calculateStat(intTestStart, "min");
+ assertEquals(responseStr, intResult,intTest);
+
+ //Long
+ Long longResult = getValue(response, "mir", "long_ld");
+ Long longTest = (Long)calculateStat(longTestStart, "min");
+ assertEquals(responseStr, longResult,longTest);
+
+ //Float
+ Float floatResult = getValue(response, "mir", "float_fd");
+ Float floatTest = (Float)calculateStat(floatTestStart, "min");
+ assertEquals(responseStr, floatResult,floatTest);
+
+ //Double
+ Double doubleResult = getValue(response, "mir", "double_dd");
+ Double doubleTest = (Double)calculateStat(doubleTestStart, "min");
+ assertEquals(responseStr, doubleResult,doubleTest);
+
+ //Date
+ String dateResult = getValue(response, "mir", "date_dtd");
+ String dateTest = (String)calculateStat(dateTestStart, "min");
+ assertEquals(responseStr, dateResult,dateTest);
+
+ //String
+ String stringResult = getValue(response, "mir", "string_sd");
+ String stringTest = (String)calculateStat(stringTestStart, "min");
+ assertEquals(responseStr, stringResult,stringTest);
+ }
+
+ @Test
+ public void maxTest() throws Exception {
+ String[] params = new String[] {
+ "o.mar.s.int_id", "max(int_id)",
+ "o.mar.s.long_ld", "max(long_ld)",
+ "o.mar.s.float_fd", "max(float_fd)",
+ "o.mar.s.double_dd", "max(double_dd)",
+ "o.mar.s.date_dtd", "string(max(date_dtd))",
+ "o.mar.s.string_sd", "max(string_sd)"
+ };
+ NamedList<Object> response = queryLegacyCloudAnalytics(params);
+ String responseStr = response.toString();
+
+ //Int
+ Integer intResult = getValue(response, "mar", "int_id");
+ Integer intTest = (Integer)calculateStat(intTestStart, "max");
+ assertEquals(responseStr, intResult,intTest);
+
+ //Long
+ Long longResult = getValue(response, "mar", "long_ld");
+ Long longTest = (Long)calculateStat(longTestStart, "max");
+ assertEquals(responseStr, longResult,longTest);
+
+ //Float
+ Float floatResult = getValue(response, "mar", "float_fd");
+ Float floatTest = (Float)calculateStat(floatTestStart, "max");
+ assertEquals(responseStr, floatResult,floatTest);
+
+ //Double
+ Double doubleResult = getValue(response, "mar", "double_dd");
+ Double doubleTest = (Double)calculateStat(doubleTestStart, "max");
+ assertEquals(responseStr, doubleResult,doubleTest);
+
+ //Date
+ String dateResult = getValue(response, "mar", "date_dtd");
+ String dateTest = (String)calculateStat(dateTestStart, "max");
+ assertEquals(responseStr, dateResult,dateTest);
+
+ //String
+ String stringResult = getValue(response, "mar", "string_sd");
+ String stringTest = (String)calculateStat(stringTestStart, "max");
+ assertEquals(responseStr, stringResult,stringTest);
+ }
+
+ @Test
+ public void uniqueTest() throws Exception {
+ String[] params = new String[] {
+ "o.ur.s.int_id", "unique(int_id)",
+ "o.ur.s.long_ld", "unique(long_ld)",
+ "o.ur.s.float_fd", "unique(float_fd)",
+ "o.ur.s.double_dd", "unique(double_dd)",
+ "o.ur.s.date_dtd", "unique(date_dtd)",
+ "o.ur.s.string_sd", "unique(string_sd)"
+ };
+ NamedList<Object> response = queryLegacyCloudAnalytics(params);
+ String responseStr = response.toString();
+
+ //Int
+ Long intResult = getValue(response, "ur", "int_id");
+ Long intTest = (Long)calculateStat(intTestStart, "unique");
+ assertEquals(responseStr, intResult,intTest);
+
+ //Long
+ Long longResult = getValue(response, "ur", "long_ld");
+ Long longTest = (Long)calculateStat(longTestStart, "unique");
+ assertEquals(responseStr, longResult,longTest);
+
+ //Float
+ Long floatResult = getValue(response, "ur", "float_fd");
+ Long floatTest = (Long)calculateStat(floatTestStart, "unique");
+ assertEquals(responseStr, floatResult,floatTest);
+
+ //Double
+ Long doubleResult = getValue(response, "ur", "double_dd");
+ Long doubleTest = (Long)calculateStat(doubleTestStart, "unique");
+ assertEquals(responseStr, doubleResult,doubleTest);
+
+ //Date
+ Long dateResult = getValue(response, "ur", "date_dtd");
+ Long dateTest = (Long)calculateStat(dateTestStart, "unique");
+ assertEquals(responseStr, dateResult,dateTest);
+
+ //String
+ Long stringResult = getValue(response, "ur", "string_sd");
+ Long stringTest = (Long)calculateStat(stringTestStart, "unique");
+ assertEquals(responseStr, stringResult,stringTest);
+ }
+
+ @Test
+ public void countTest() throws Exception {
+ String[] params = new String[] {
+ "o.cr.s.int_id", "count(int_id)",
+ "o.cr.s.long_ld", "count(long_ld)",
+ "o.cr.s.float_fd", "count(float_fd)",
+ "o.cr.s.double_dd", "count(double_dd)",
+ "o.cr.s.date_dtd", "count(date_dtd)",
+ "o.cr.s.string_sd", "count(string_sd)"
+ };
+ NamedList<Object> response = queryLegacyCloudAnalytics(params);
+ String responseStr = response.toString();
+
+ //Int
+ Long intResult = getValue(response, "cr", "int_id");
+ Long intTest = (Long)calculateStat(intTestStart, "count");
+ assertEquals(responseStr, intResult,intTest);
+
+ //Long
+ Long longResult = getValue(response, "cr", "long_ld");
+ Long longTest = (Long)calculateStat(longTestStart, "count");
+ assertEquals(responseStr, longResult,longTest);
+
+ //Float
+ Long floatResult = getValue(response, "cr", "float_fd");
+ Long floatTest = (Long)calculateStat(floatTestStart, "count");
+ assertEquals(responseStr, floatResult,floatTest);
+
+ //Double
+ Long doubleResult = getValue(response, "cr", "double_dd");
+ Long doubleTest = (Long)calculateStat(doubleTestStart, "count");
+ assertEquals(responseStr, doubleResult,doubleTest);
+
+ //Date
+ Long dateResult = getValue(response, "cr", "date_dtd");
+ Long dateTest = (Long)calculateStat(dateTestStart, "count");
+ assertEquals(responseStr, dateResult,dateTest);
+
+ //String
+ Long stringResult = getValue(response, "cr", "string_sd");
+ Long stringTest = (Long)calculateStat(stringTestStart, "count");
+ assertEquals(responseStr, stringResult,stringTest);
+ }
+
+ @Test
+ public void missingDefaultTest() throws Exception {
+ String[] params = new String[] {
+ "o.misr.s.int_id", "missing(int_id)",
+ "o.misr.s.long_ld", "missing(long_ld)",
+ "o.misr.s.float_fd", "missing(float_fd)",
+ "o.misr.s.double_dd", "missing(double_dd)",
+ "o.misr.s.date_dtd", "missing(date_dtd)",
+ "o.misr.s.string_sd", "missing(string_sd)"
+ };
+ NamedList<Object> response = queryLegacyCloudAnalytics(params);
+ String responseStr = response.toString();
+
+ //Int
+ long intResult = getValue(response, "misr", "int_id");
+ assertEquals(responseStr, intMissing,intResult);
+
+ //Long
+ long longResult = getValue(response, "misr", "long_ld");
+ assertEquals(responseStr, longMissing,longResult);
+
+ //Float
+ long floatResult = getValue(response, "misr", "float_fd");
+ assertEquals(responseStr, floatMissing,floatResult);
+
+ //Double
+ long doubleResult = getValue(response, "misr", "double_dd");
+ assertEquals(responseStr, doubleMissing,doubleResult);
+
+ //Date
+ long dateResult = getValue(response, "misr", "date_dtd");
+ assertEquals(responseStr, dateMissing,dateResult);
+
+ //String
+ long stringResult = getValue(response, "misr", "string_sd");
+ assertEquals(responseStr, stringMissing, stringResult);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/86d84bff/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/LegacyNoFacetTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/LegacyNoFacetTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/LegacyNoFacetTest.java
new file mode 100644
index 0000000..4fb573d
--- /dev/null
+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/LegacyNoFacetTest.java
@@ -0,0 +1,450 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.analytics.legacy;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class LegacyNoFacetTest extends LegacyAbstractAnalyticsTest {
+ static String fileName = "noFacets.txt";
+
+ static public final int INT = 71;
+ static public final int LONG = 36;
+ static public final int FLOAT = 93;
+ static public final int DOUBLE = 49;
+ static public final int DATE = 12;
+ static public final int STRING = 28;
+ static public final int NUM_LOOPS = 100;
+
+ //INT
+ static ArrayList<Integer> intTestStart;
+ static long intMissing = 0;
+
+ //LONG
+ static ArrayList<Long> longTestStart;
+ static long longMissing = 0;
+
+ //FLOAT
+ static ArrayList<Float> floatTestStart;
+ static long floatMissing = 0;
+
+ //DOUBLE
+ static ArrayList<Double> doubleTestStart;
+ static long doubleMissing = 0;
+
+ //DATE
+ static ArrayList<String> dateTestStart;
+ static long dateMissing = 0;
+
+ //STR
+ static ArrayList<String> stringTestStart;
+ static long stringMissing = 0;
+
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ initCore("solrconfig-analytics.xml","schema-analytics.xml");
+ h.update("<delete><query>*:*</query></delete>");
+ defaults.put("int_id", new Integer(0));
+ defaults.put("long_ld", new Long(0));
+ defaults.put("float_fd", new Float(0));
+ defaults.put("double_dd", new Double(0));
+ defaults.put("date_dtd", "1800-12-31T23:59:59Z");
+ defaults.put("string_sd", "str0");
+
+ intTestStart = new ArrayList<>();
+ longTestStart = new ArrayList<>();
+ floatTestStart = new ArrayList<>();
+ doubleTestStart = new ArrayList<>();
+ dateTestStart = new ArrayList<>();
+ stringTestStart = new ArrayList<>();
+
+ for (int j = 0; j < NUM_LOOPS; ++j) {
+ int i = j%INT;
+ long l = j%LONG;
+ float f = j%FLOAT;
+ double d = j%DOUBLE;
+ String dt = (1800+j%DATE) + "-12-31T23:59:59Z";
+ String s = "str" + (j%STRING);
+ List<String> fields = new ArrayList<>();
+ fields.add("id"); fields.add("1000"+j);
+
+ if( i != 0 ){
+ fields.add("int_id"); fields.add("" + i);
+ intTestStart.add(i);
+ } else intMissing++;
+
+ if( l != 0l ){
+ fields.add("long_ld"); fields.add("" + l);
+ longTestStart.add(l);
+ } else longMissing++;
+
+ if( f != 0.0f ){
+ fields.add("float_fd"); fields.add("" + f);
+ floatTestStart.add(f);
+ } else floatMissing++;
+
+ if( d != 0.0d ){
+ fields.add("double_dd"); fields.add("" + d);
+ doubleTestStart.add(d);
+ } else doubleMissing++;
+
+ if( (j%DATE) != 0 ){
+ fields.add("date_dtd"); fields.add(dt);
+ dateTestStart.add(dt);
+ } else dateMissing++;
+
+ if( (j%STRING) != 0 ){
+ fields.add("string_sd"); fields.add(s);
+ stringTestStart.add(s);
+ } else stringMissing++;
+
+ assertU(adoc(fields.toArray(new String[0])));
+
+
+ if (usually()) {
+ assertU(commit()); // to have several segments
+ }
+ }
+
+ assertU(commit());
+
+ //Sort ascending tests
+ setResponse(h.query(request(fileToStringArr(LegacyNoFacetTest.class, fileName))));
+ }
+
+ @Test
+ public void sumTest() throws Exception {
+ //Int
+ Double intResult = (Double)getStatResult("sr", "int_id", VAL_TYPE.DOUBLE);
+ Double intTest = (Double)calculateNumberStat(intTestStart, "sum");
+ assertEquals(getRawResponse(), intResult,intTest);
+
+ //Long
+ Double longResult = (Double)getStatResult("sr", "long_ld", VAL_TYPE.DOUBLE);
+ Double longTest = (Double)calculateNumberStat(longTestStart, "sum");
+ assertEquals(getRawResponse(), longResult,longTest);
+
+ //Float
+ Double floatResult = (Double)getStatResult("sr", "float_fd", VAL_TYPE.DOUBLE);
+ Double floatTest = (Double)calculateNumberStat(floatTestStart, "sum");
+ assertEquals(getRawResponse(), floatResult,floatTest);
+
+ //Double
+ Double doubleResult = (Double)getStatResult("sr", "double_dd", VAL_TYPE.DOUBLE);
+ Double doubleTest = (Double) calculateNumberStat(doubleTestStart, "sum");
+ assertEquals(getRawResponse(), doubleResult,doubleTest);
+ }
+
+ @Test
+ public void meanTest() throws Exception {
+ //Int
+ Double intResult = (Double)getStatResult("mr", "int_id", VAL_TYPE.DOUBLE);
+ Double intTest = (Double)calculateNumberStat(intTestStart, "mean");
+ assertEquals(getRawResponse(), intResult,intTest);
+
+ //Long
+ Double longResult = (Double)getStatResult("mr", "long_ld", VAL_TYPE.DOUBLE);
+ Double longTest = (Double)calculateNumberStat(longTestStart, "mean");
+ assertEquals(getRawResponse(), longResult,longTest);
+
+ //Float
+ Double floatResult = (Double)getStatResult("mr", "float_fd", VAL_TYPE.DOUBLE);
+ Double floatTest = (Double)calculateNumberStat(floatTestStart, "mean");
+ assertEquals(getRawResponse(), floatResult,floatTest);
+
+ //Double
+ Double doubleResult = (Double)getStatResult("mr", "double_dd", VAL_TYPE.DOUBLE);
+ Double doubleTest = (Double)calculateNumberStat(doubleTestStart, "mean");
+ assertEquals(getRawResponse(), doubleResult,doubleTest);
+ }
+
+ @Test
+ public void stddevTest() throws Exception {
+ //Int
+ Double intResult = (Double)getStatResult("str", "int_id", VAL_TYPE.DOUBLE);
+ Double intTest = (Double)calculateNumberStat(intTestStart, "stddev");
+ assertEquals(getRawResponse(), intResult, intTest, 0.00000000001);
+
+ //Long
+ Double longResult = (Double)getStatResult("str", "long_ld", VAL_TYPE.DOUBLE);
+ Double longTest = (Double)calculateNumberStat(longTestStart, "stddev");
+ assertEquals(getRawResponse(), longResult, longTest, 0.00000000001);
+
+ //Float
+ Double floatResult = (Double)getStatResult("str", "float_fd", VAL_TYPE.DOUBLE);
+ Double floatTest = (Double)calculateNumberStat(floatTestStart, "stddev");
+ assertEquals(getRawResponse(), floatResult, floatTest, 0.00000000001);
+
+
+ //Double
+ Double doubleResult = (Double)getStatResult("str", "double_dd", VAL_TYPE.DOUBLE);
+ Double doubleTest = (Double)calculateNumberStat(doubleTestStart, "stddev");
+ assertEquals(getRawResponse(), doubleResult, doubleTest, 0.00000000001);
+ }
+
+ @Test
+ public void medianTest() throws Exception {
+ //Int
+ Double intResult = (Double)getStatResult("medr", "int_id", VAL_TYPE.DOUBLE);
+ Double intTest = (Double)calculateNumberStat(intTestStart, "median");
+ assertEquals(getRawResponse(), intResult,intTest);
+
+ //Long
+ Double longResult = (Double)getStatResult("medr", "long_ld", VAL_TYPE.DOUBLE);
+ Double longTest = (Double)calculateNumberStat(longTestStart, "median");
+ assertEquals(getRawResponse(), longResult,longTest);
+
+ //Float
+ Double floatResult = (Double)getStatResult("medr", "float_fd", VAL_TYPE.DOUBLE);
+ Double floatTest = (Double)calculateNumberStat(floatTestStart, "median");
+ assertEquals(getRawResponse(), floatResult,floatTest);
+
+ //Double
+ Double doubleResult = (Double)getStatResult("medr", "double_dd", VAL_TYPE.DOUBLE);
+ Double doubleTest = (Double)calculateNumberStat(doubleTestStart, "median");
+ assertEquals(getRawResponse(), doubleResult,doubleTest);
+ }
+
+ @Test
+ public void perc20Test() throws Exception {
+ //Int 20
+ Integer intResult = (Integer)getStatResult("p2r", "int_id", VAL_TYPE.INTEGER);
+ Integer intTest = (Integer)calculateStat(intTestStart, "perc_20");
+ assertEquals(getRawResponse(), intResult,intTest);
+
+ //Long 20
+ Long longResult = (Long)getStatResult("p2r", "long_ld", VAL_TYPE.LONG);
+ Long longTest = (Long)calculateStat(longTestStart, "perc_20");
+ assertEquals(getRawResponse(), longResult,longTest);
+
+ //Float 20
+ Float floatResult = (Float)getStatResult("p2r", "float_fd", VAL_TYPE.FLOAT);
+ Float floatTest = (Float)calculateStat(floatTestStart, "perc_20");
+ //assertEquals(getRawResponse(), floatResult,floatTest);
+
+ //Double 20
+ Double doubleResult = (Double)getStatResult("p2r", "double_dd", VAL_TYPE.DOUBLE);
+ Double doubleTest = (Double)calculateStat(doubleTestStart, "perc_20");
+ assertEquals(getRawResponse(), doubleResult,doubleTest);
+
+ //Date 20
+ String dateResult = (String)getStatResult("p2r", "date_dtd", VAL_TYPE.DATE);
+ String dateTest = (String)calculateStat(dateTestStart, "perc_20");
+ assertEquals(getRawResponse(), dateResult,dateTest);
+
+ //String 20
+ String stringResult = (String)getStatResult("p2r", "string_sd", VAL_TYPE.STRING);
+ String stringTest = (String)calculateStat(stringTestStart, "perc_20");
+ assertEquals(getRawResponse(), stringResult,stringTest);
+ }
+
+ @Test
+ public void perc60Test() throws Exception {
+ //Int 60
+ Integer intResult = (Integer)getStatResult("p6r", "int_id", VAL_TYPE.INTEGER);
+ Integer intTest = (Integer)calculateStat(intTestStart, "perc_60");
+ assertEquals(getRawResponse(), intResult,intTest);
+
+ //Long 60
+ Long longResult = (Long)getStatResult("p6r", "long_ld", VAL_TYPE.LONG);
+ Long longTest = (Long)calculateStat(longTestStart, "perc_60");
+ assertEquals(getRawResponse(), longResult,longTest);
+
+ //Float 60
+ Float floatResult = (Float)getStatResult("p6r", "float_fd", VAL_TYPE.FLOAT);
+ Float floatTest = (Float)calculateStat(floatTestStart, "perc_60");
+ assertEquals(getRawResponse(), floatResult,floatTest);
+
+ //Double 60
+ Double doubleResult = (Double)getStatResult("p6r", "double_dd", VAL_TYPE.DOUBLE);
+ Double doubleTest = (Double)calculateStat(doubleTestStart, "perc_60");
+ assertEquals(getRawResponse(), doubleResult,doubleTest);
+
+ //Date 60
+ String dateResult = (String)getStatResult("p6r", "date_dtd", VAL_TYPE.DATE);
+ String dateTest = (String)calculateStat(dateTestStart, "perc_60");
+ assertEquals(getRawResponse(), dateResult,dateTest);
+
+ //String 60
+ String stringResult = (String)getStatResult("p6r", "string_sd", VAL_TYPE.STRING);
+ String stringTest = (String)calculateStat(stringTestStart, "perc_60");
+ assertEquals(getRawResponse(), stringResult,stringTest);
+ }
+
+ @Test
+ public void minTest() throws Exception {
+ //Int
+ Integer intResult = ((Integer)getStatResult("mir", "int_id", VAL_TYPE.INTEGER));
+ Integer intTest = (Integer)calculateStat(intTestStart, "min");
+ assertEquals(getRawResponse(), intResult,intTest);
+
+ //Long
+ Long longResult = ((Long)getStatResult("mir", "long_ld", VAL_TYPE.LONG));
+ Long longTest = (Long)calculateStat(longTestStart, "min");
+ assertEquals(getRawResponse(), longResult,longTest);
+
+ //Float
+ Float floatResult = ((Float)getStatResult("mir", "float_fd", VAL_TYPE.FLOAT));
+ Float floatTest = (Float)calculateStat(floatTestStart, "min");
+ assertEquals(getRawResponse(), floatResult,floatTest);
+
+ //Double
+ Double doubleResult = (Double)getStatResult("mir", "double_dd", VAL_TYPE.DOUBLE);
+ Double doubleTest = (Double)calculateStat(doubleTestStart, "min");
+ assertEquals(getRawResponse(), doubleResult,doubleTest);
+
+ //Date
+ String dateResult = (String)getStatResult("mir", "date_dtd", VAL_TYPE.DATE);
+ String dateTest = (String)calculateStat(dateTestStart, "min");
+ assertEquals(getRawResponse(), dateResult,dateTest);
+
+ //String
+ String stringResult = (String)getStatResult("mir", "string_sd", VAL_TYPE.STRING);
+ String stringTest = (String)calculateStat(stringTestStart, "min");
+ assertEquals(getRawResponse(), stringResult,stringTest);
+ }
+
+ @Test
+ public void maxTest() throws Exception {
+ //Int
+ Integer intResult = ((Integer)getStatResult("mar", "int_id", VAL_TYPE.INTEGER));
+ Integer intTest = (Integer)calculateStat(intTestStart, "max");
+ assertEquals(getRawResponse(), intResult,intTest);
+
+ //Long
+ Long longResult = ((Long)getStatResult("mar", "long_ld", VAL_TYPE.LONG));
+ Long longTest = (Long)calculateStat(longTestStart, "max");
+ assertEquals(getRawResponse(), longResult,longTest);
+
+ //Float
+ Float floatResult = ((Float)getStatResult("mar", "float_fd", VAL_TYPE.FLOAT));
+ Float floatTest = (Float)calculateStat(floatTestStart, "max");
+ assertEquals(getRawResponse(), floatResult,floatTest);
+
+ //Double
+ Double doubleResult = (Double)getStatResult("mar", "double_dd", VAL_TYPE.DOUBLE);
+ Double doubleTest = (Double)calculateStat(doubleTestStart, "max");
+ assertEquals(getRawResponse(), doubleResult,doubleTest);
+
+ //Date
+ String dateResult = (String)getStatResult("mar", "date_dtd", VAL_TYPE.DATE);
+ String dateTest = (String)calculateStat(dateTestStart, "max");
+ assertEquals(getRawResponse(), dateResult,dateTest);
+
+ //String
+ String stringResult = (String)getStatResult("mar", "string_sd", VAL_TYPE.STRING);
+ String stringTest = (String)calculateStat(stringTestStart, "max");
+ assertEquals(getRawResponse(), stringResult,stringTest);
+ }
+
+ @Test
+ public void uniqueTest() throws Exception {
+ //Int
+ Long intResult = (Long)getStatResult("ur", "int_id", VAL_TYPE.LONG);
+ Long intTest = (Long)calculateStat(intTestStart, "unique");
+ assertEquals(getRawResponse(), intResult,intTest);
+
+ //Long
+ Long longResult = (Long)getStatResult("ur", "long_ld", VAL_TYPE.LONG);
+ Long longTest = (Long)calculateStat(longTestStart, "unique");
+ assertEquals(getRawResponse(), longResult,longTest);
+
+ //Float
+ Long floatResult = (Long)getStatResult("ur", "float_fd", VAL_TYPE.LONG);
+ Long floatTest = (Long)calculateStat(floatTestStart, "unique");
+ assertEquals(getRawResponse(), floatResult,floatTest);
+
+ //Double
+ Long doubleResult = (Long)getStatResult("ur", "double_dd", VAL_TYPE.LONG);
+ Long doubleTest = (Long)calculateStat(doubleTestStart, "unique");
+ assertEquals(getRawResponse(), doubleResult,doubleTest);
+
+ //Date
+ Long dateResult = (Long)getStatResult("ur", "date_dtd", VAL_TYPE.LONG);
+ Long dateTest = (Long)calculateStat(dateTestStart, "unique");
+ assertEquals(getRawResponse(), dateResult,dateTest);
+
+ //String
+ Long stringResult = (Long)getStatResult("ur", "string_sd", VAL_TYPE.LONG);
+ Long stringTest = (Long)calculateStat(stringTestStart, "unique");
+ assertEquals(getRawResponse(), stringResult,stringTest);
+ }
+
+ @Test
+ public void countTest() throws Exception {
+ //Int
+ Long intResult = (Long)getStatResult("cr", "int_id", VAL_TYPE.LONG);
+ Long intTest = (Long)calculateStat(intTestStart, "count");
+ assertEquals(getRawResponse(), intResult,intTest);
+
+ //Long
+ Long longResult = (Long)getStatResult("cr", "long_ld", VAL_TYPE.LONG);
+ Long longTest = (Long)calculateStat(longTestStart, "count");
+ assertEquals(getRawResponse(), longResult,longTest);
+
+ //Float
+ Long floatResult = (Long)getStatResult("cr", "float_fd", VAL_TYPE.LONG);
+ Long floatTest = (Long)calculateStat(floatTestStart, "count");
+ assertEquals(getRawResponse(), floatResult,floatTest);
+
+ //Double
+ Long doubleResult = (Long)getStatResult("cr", "double_dd", VAL_TYPE.LONG);
+ Long doubleTest = (Long)calculateStat(doubleTestStart, "count");
+ assertEquals(getRawResponse(), doubleResult,doubleTest);
+
+ //Date
+ Long dateResult = (Long)getStatResult("cr", "date_dtd", VAL_TYPE.LONG);
+ Long dateTest = (Long)calculateStat(dateTestStart, "count");
+ assertEquals(getRawResponse(), dateResult,dateTest);
+
+ //String
+ Long stringResult = (Long)getStatResult("cr", "string_sd", VAL_TYPE.LONG);
+ Long stringTest = (Long)calculateStat(stringTestStart, "count");
+ assertEquals(getRawResponse(), stringResult,stringTest);
+ }
+
+ @Test
+ public void missingDefaultTest() throws Exception {
+ //Int
+ long intResult = (Long)getStatResult("misr", "int_id", VAL_TYPE.LONG);
+ assertEquals(getRawResponse(), intMissing,intResult);
+
+ //Long
+ long longResult = (Long)getStatResult("misr", "long_ld", VAL_TYPE.LONG);
+ assertEquals(getRawResponse(), longMissing,longResult);
+
+ //Float
+ long floatResult = (Long)getStatResult("misr", "float_fd", VAL_TYPE.LONG);
+ assertEquals(getRawResponse(), floatMissing,floatResult);
+
+ //Double
+ long doubleResult = (Long)getStatResult("misr", "double_dd", VAL_TYPE.LONG);
+ assertEquals(getRawResponse(), doubleMissing,doubleResult);
+
+ //Date
+ long dateResult = (Long)getStatResult("misr", "date_dtd", VAL_TYPE.LONG);
+ assertEquals(getRawResponse(), dateMissing,dateResult);
+
+ //String
+ long stringResult = (Long)getStatResult("misr", "string_sd", VAL_TYPE.LONG);
+ assertEquals(getRawResponse(), stringMissing, stringResult);
+ }
+
+}