You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by da...@apache.org on 2018/11/02 11:16:15 UTC
[06/56] lucene-solr:jira/gradle: Add :solr:contrib:analytics module
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/f0366b94/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/ReplaceFunctionTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/ReplaceFunctionTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/ReplaceFunctionTest.java
deleted file mode 100644
index 38f1bb2..0000000
--- a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/ReplaceFunctionTest.java
+++ /dev/null
@@ -1,990 +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
- *
- * 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.Arrays;
-import java.util.Date;
-import java.util.Iterator;
-
-import org.apache.solr.SolrTestCaseJ4;
-import org.apache.solr.analytics.value.AnalyticsValue;
-import org.apache.solr.analytics.value.AnalyticsValueStream;
-import org.apache.solr.analytics.value.BooleanValue;
-import org.apache.solr.analytics.value.BooleanValueStream;
-import org.apache.solr.analytics.value.DateValue;
-import org.apache.solr.analytics.value.DateValueStream;
-import org.apache.solr.analytics.value.DoubleValue;
-import org.apache.solr.analytics.value.DoubleValueStream;
-import org.apache.solr.analytics.value.FloatValue;
-import org.apache.solr.analytics.value.FloatValueStream;
-import org.apache.solr.analytics.value.IntValue;
-import org.apache.solr.analytics.value.IntValueStream;
-import org.apache.solr.analytics.value.LongValue;
-import org.apache.solr.analytics.value.LongValueStream;
-import org.apache.solr.analytics.value.StringValue;
-import org.apache.solr.analytics.value.StringValueStream;
-import org.apache.solr.analytics.value.FillableTestValue.TestAnalyticsValue;
-import org.apache.solr.analytics.value.FillableTestValue.TestAnalyticsValueStream;
-import org.apache.solr.analytics.value.FillableTestValue.TestBooleanValue;
-import org.apache.solr.analytics.value.FillableTestValue.TestBooleanValueStream;
-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.junit.Test;
-
-public class ReplaceFunctionTest extends SolrTestCaseJ4 {
-
- @Test
- public void castingTest() {
- assertTrue(ReplaceFunction.creatorFunction.apply(new AnalyticsValueStream[] {new TestBooleanValue(), new TestStringValue(), new TestStringValue()}) instanceof StringValue);
-
- assertFalse(ReplaceFunction.creatorFunction.apply(new AnalyticsValueStream[] {new TestIntValueStream(), new TestFloatValue(), new TestDoubleValue()}) instanceof FloatValueStream);
-
- assertFalse(ReplaceFunction.creatorFunction.apply(new AnalyticsValueStream[] {new TestLongValueStream(), new TestDateValue(), new TestLongValue()}) instanceof DateValueStream);
-
- assertFalse(ReplaceFunction.creatorFunction.apply(new AnalyticsValueStream[] {new TestLongValue(), new TestAnalyticsValue(), new TestStringValue()}) instanceof StringValue);
-
- assertTrue(ReplaceFunction.creatorFunction.apply(new AnalyticsValueStream[] {new TestIntValue(), new TestLongValue(), new TestFloatValue()}) instanceof DoubleValue);
-
- assertFalse(ReplaceFunction.creatorFunction.apply(new AnalyticsValueStream[] {new TestDateValue(), new TestStringValue(), new TestLongValue()}) instanceof DateValue);
-
- assertFalse(ReplaceFunction.creatorFunction.apply(new AnalyticsValueStream[] {new TestBooleanValueStream(), new TestStringValue(), new TestStringValue()}) instanceof BooleanValueStream);
-
- assertFalse(ReplaceFunction.creatorFunction.apply(new AnalyticsValueStream[] {new TestDoubleValue(), new TestIntValue(), new TestLongValue()}) instanceof LongValue);
- }
-
- @Test
- public void singleValueBooleanTest() {
- TestBooleanValue val = new TestBooleanValue();
- TestBooleanValue comp = new TestBooleanValue();
- TestBooleanValue fill = new TestBooleanValue();
-
- AnalyticsValueStream uncasted = ReplaceFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, comp, fill});
- assertTrue(uncasted instanceof BooleanValue);
- BooleanValue func = (BooleanValue) uncasted;
-
- // Value doesn't exist
- val.setExists(false);
- comp.setExists(false);
- fill.setExists(false);
- func.getBoolean();
- assertFalse(func.exists());
-
- val.setExists(false);
- comp.setValue(false).setExists(true);
- fill.setValue(true).setExists(true);
- func.getBoolean();
- assertFalse(func.exists());
-
- // Comp doesn't exist
- val.setValue(true).setExists(true);
- comp.setExists(false);
- fill.setValue(false).setExists(true);
- assertEquals(true, func.getBoolean());
- assertTrue(func.exists());
-
- // Value exists
- val.setValue(true).setExists(true);
- comp.setValue(false).setExists(true);
- fill.setValue(false).setExists(true);
- assertEquals(true, func.getBoolean());
- assertTrue(func.exists());
-
- val.setValue(true).setExists(true);
- comp.setValue(true).setExists(true);
- fill.setValue(false).setExists(true);
- assertEquals(false, func.getBoolean());
- assertTrue(func.exists());
-
- val.setValue(false).setExists(true);
- comp.setValue(false).setExists(true);
- fill.setExists(false);
- func.getBoolean();
- assertFalse(func.exists());
- }
-
- @Test
- public void singleValueIntTest() {
- TestIntValue val = new TestIntValue();
- TestIntValue comp = new TestIntValue();
- TestIntValue fill = new TestIntValue();
-
- AnalyticsValueStream uncasted = ReplaceFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, comp, fill});
- assertTrue(uncasted instanceof IntValue);
- IntValue func = (IntValue) uncasted;
-
- // Value doesn't exist
- val.setExists(false);
- comp.setExists(false);
- func.getInt();
- assertFalse(func.exists());
-
- val.setExists(false);
- comp.setValue(-234).setExists(true);
- fill.setValue(765).setExists(true);
- func.getInt();
- assertFalse(func.exists());
-
- // Comp doesn't exist
- val.setValue(745).setExists(true);
- comp.setExists(false);
- fill.setValue(23423).setExists(true);
- assertEquals(745, func.getInt());
- assertTrue(func.exists());
-
- // Value exists
- // Comp != Val
- val.setValue(21).setExists(true);
- comp.setValue(234).setExists(true);
-
- fill.setValue(23423).setExists(true);
- assertEquals(21, func.getInt());
- assertTrue(func.exists());
-
- fill.setExists(false);
- assertEquals(21, func.getInt());
- assertTrue(func.exists());
-
- // Comp == Val
- val.setValue(-154).setExists(true);
- comp.setValue(-154).setExists(true);
-
- fill.setExists(false);
- func.getInt();
- assertFalse(func.exists());
-
- fill.setValue(23423).setExists(true);
- assertEquals(23423, func.getInt());
- assertTrue(func.exists());
- }
-
- @Test
- public void singleValueLongTest() {
- TestLongValue val = new TestLongValue();
- TestLongValue comp = new TestLongValue();
- TestLongValue fill = new TestLongValue();
-
- AnalyticsValueStream uncasted = ReplaceFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, comp, fill});
- assertTrue(uncasted instanceof LongValue);
- LongValue func = (LongValue) uncasted;
-
- // Value doesn't exist
- val.setExists(false);
- comp.setExists(false);
- fill.setExists(false);
- func.getLong();
- assertFalse(func.exists());
-
- val.setExists(false);
- comp.setValue(234L).setExists(true);
- fill.setValue(232584L).setExists(true);
- func.getLong();
- assertFalse(func.exists());
-
- // Comp doesn't exist
- val.setValue(745L).setExists(true);
- comp.setExists(false);
- fill.setValue(23423L).setExists(true);
- assertEquals(745L, func.getLong());
- assertTrue(func.exists());
-
- // Value exists
- // Comp != Val
- val.setValue(21L).setExists(true);
- comp.setValue(234L).setExists(true);
-
- fill.setValue(23423L).setExists(true);
- assertEquals(21L, func.getLong());
- assertTrue(func.exists());
-
- fill.setExists(false);
- assertEquals(21L, func.getLong());
- assertTrue(func.exists());
-
- // Comp == Val
- val.setValue(-154L).setExists(true);
- comp.setValue(-154L).setExists(true);
-
- fill.setExists(false);
- func.getLong();
- assertFalse(func.exists());
-
- fill.setValue(23423L).setExists(true);
- assertEquals(23423L, func.getLong());
- assertTrue(func.exists());
- }
-
- @Test
- public void singleValueFloatTest() {
- TestFloatValue val = new TestFloatValue();
- TestFloatValue comp = new TestFloatValue();
- TestFloatValue fill = new TestFloatValue();
-
- AnalyticsValueStream uncasted = ReplaceFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, comp, fill});
- assertTrue(uncasted instanceof FloatValue);
- FloatValue func = (FloatValue) uncasted;
-
- // Value doesn't exist
- val.setExists(false);
- comp.setExists(false);
- fill.setExists(false);
- func.getFloat();
- assertFalse(func.exists());
-
- val.setExists(false);
- comp.setValue(3124123.32F).setExists(true);
- fill.setValue(-32473.336F).setExists(true);
- func.getFloat();
- assertFalse(func.exists());
-
- // Comp doesn't exist
- val.setValue(-745.234F).setExists(true);
- comp.setExists(false);
- fill.setValue(23423.324F).setExists(true);
- assertEquals(-745.234F, func.getFloat(), .0000001);
- assertTrue(func.exists());
-
- // Value exists
- // Comp != Val
- val.setValue(3423.304F).setExists(true);
- comp.setValue(3423.303F).setExists(true);
-
- fill.setValue(-23.764F).setExists(true);
- assertEquals(3423.304F, func.getFloat(), .0000001);
- assertTrue(func.exists());
-
- fill.setExists(false);
- assertEquals(3423.304F, func.getFloat(), .0000001);
- assertTrue(func.exists());
-
- // Comp == Val
- val.setValue(-154.45F).setExists(true);
- comp.setValue(-154.45F).setExists(true);
-
- fill.setExists(false);
- func.getFloat();
- assertFalse(func.exists());
-
- fill.setValue(4353434.234F).setExists(true);
- assertEquals(4353434.234F, func.getFloat(), .0000001);
- assertTrue(func.exists());
- }
-
- @Test
- public void singleValueDoubleTest() {
- TestDoubleValue val = new TestDoubleValue();
- TestDoubleValue comp = new TestDoubleValue();
- TestDoubleValue fill = new TestDoubleValue();
-
- AnalyticsValueStream uncasted = ReplaceFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, comp, fill});
- assertTrue(uncasted instanceof DoubleValue);
- DoubleValue func = (DoubleValue) uncasted;
-
- // Value doesn't exist
- val.setExists(false);
- comp.setExists(false);
- fill.setExists(false);
- func.getDouble();
- assertFalse(func.exists());
-
- val.setExists(false);
- comp.setValue(3124123.32).setExists(true);
- fill.setValue(-13242.34).setExists(true);
- func.getDouble();
- assertFalse(func.exists());
-
- // Comp doesn't exist
- val.setValue(-745.234).setExists(true);
- comp.setExists(false);
- fill.setValue(23423.324).setExists(true);
- assertEquals(-745.234, func.getDouble(), .0000001);
- assertTrue(func.exists());
-
- // Value exists
- // Comp != Val
- val.setValue(34923.304).setExists(true);
- comp.setValue(34923.303).setExists(true);
-
- fill.setValue(-23.764).setExists(true);
- assertEquals(34923.304, func.getDouble(), .0000001);
- assertTrue(func.exists());
-
- fill.setExists(false);
- assertEquals(34923.304, func.getDouble(), .0000001);
- assertTrue(func.exists());
-
- // Comp == Val
- val.setValue(-154.45).setExists(true);
- comp.setValue(-154.45).setExists(true);
-
- fill.setExists(false);
- func.getDouble();
- assertFalse(func.exists());
-
- fill.setValue(4353434.234).setExists(true);
- assertEquals(4353434.234, func.getDouble(), .0000001);
- assertTrue(func.exists());
- }
-
- @Test
- public void singleValueDateTest() throws DateTimeParseException {
- Date date1 = Date.from(Instant.parse("1810-12-02T10:30:15Z"));
- Date date2 = Date.from(Instant.parse("1950-02-23T14:54:34Z"));
-
- TestDateValue val = new TestDateValue();
- TestDateValue comp = new TestDateValue();
- TestDateValue fill = new TestDateValue();
-
- AnalyticsValueStream uncasted = ReplaceFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, comp, fill});
- assertTrue(uncasted instanceof DateValue);
- DateValue func = (DateValue) uncasted;
-
- // Value doesn't exist
- val.setExists(false);
- comp.setExists(false);
- fill.setExists(false);
- func.getLong();
- assertFalse(func.exists());
-
- val.setExists(false);
- comp.setValue("1950-02-23T14:54:34Z").setExists(true);
- fill.setValue("1350-02-26T14:34:34Z").setExists(true);
- func.getLong();
- assertFalse(func.exists());
-
- // Comp doesn't exist
- val.setValue("1950-02-23T14:54:34Z").setExists(true);
- comp.setExists(false);
- fill.setValue("1350-02-26T14:34:34Z").setExists(true);
- assertEquals(date2.getTime(), func.getLong());
- assertTrue(func.exists());
-
- // Value exists
- // Comp != Val
- val.setValue("1950-02-23T14:54:34Z").setExists(true);
- comp.setValue("1350-02-26T14:34:34Z").setExists(true);
-
- fill.setValue("2023-11-01T20:30:15Z").setExists(true);
- assertEquals(date2.getTime(), func.getLong());
- assertTrue(func.exists());
-
- fill.setExists(false);
- assertEquals(date2.getTime(), func.getLong());
- assertTrue(func.exists());
-
- // Comp == Val
- val.setValue("2023-11-01T20:30:15Z").setExists(true);
- comp.setValue("2023-11-01T20:30:15Z").setExists(true);
-
- fill.setExists(false);
- func.getLong();
- assertFalse(func.exists());
-
- fill.setValue("1810-12-02T10:30:15Z").setExists(true);
- assertEquals(date1.getTime(), func.getLong());
- assertTrue(func.exists());
- }
-
- @Test
- public void singleValueStringTest() {
- TestStringValue val = new TestStringValue();
- TestStringValue comp = new TestStringValue();
- TestStringValue fill = new TestStringValue();
-
- AnalyticsValueStream uncasted = ReplaceFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, comp, fill});
- assertTrue(uncasted instanceof StringValue);
- StringValue func = (StringValue) uncasted;
-
- // Value doesn't exist
- val.setExists(false);
- comp.setExists(false);
- fill.setExists(false);
- func.getString();
- assertFalse(func.exists());
-
- val.setExists(false);
- comp.setValue("abc456").setExists(true);
- fill.setValue("not touched").setExists(true);
- func.getString();
- assertFalse(func.exists());
-
- // Comp doesn't exist
- val.setValue("abcd").setExists(true);
- comp.setExists(false);
- fill.setValue("12234").setExists(true);
- assertEquals("abcd", func.getString());
- assertTrue(func.exists());
-
- // Value exists
- // Comp != Val
- val.setValue("original").setExists(true);
- comp.setValue("different").setExists(true);
-
- fill.setValue("anything").setExists(true);
- assertEquals("original", func.getString());
- assertTrue(func.exists());
-
- fill.setExists(false);
- assertEquals("original", func.getString());
- assertTrue(func.exists());
-
- // Comp == Val
- val.setValue("the same").setExists(true);
- comp.setValue("the same").setExists(true);
-
- fill.setExists(false);
- func.getString();
- assertFalse(func.exists());
-
- fill.setValue("replacement").setExists(true);
- assertEquals("replacement", func.getString());
- assertTrue(func.exists());
- }
-
- @Test
- public void singleValueObjectTest() {
- TestAnalyticsValue val = new TestAnalyticsValue();
- TestAnalyticsValue comp = new TestAnalyticsValue();
- TestAnalyticsValue fill = new TestAnalyticsValue();
-
- AnalyticsValueStream uncasted = ReplaceFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, comp, fill});
- assertTrue(uncasted instanceof AnalyticsValue);
- AnalyticsValue func = (AnalyticsValue) uncasted;
-
- // Value doesn't exist
- val.setExists(false);
- comp.setExists(false);
- fill.setExists(false);
- func.getObject();
- assertFalse(func.exists());
-
- val.setExists(false);
- comp.setValue(Boolean.TRUE).setExists(true);
- fill.setValue("abc").setExists(true);
- func.getObject();
- assertFalse(func.exists());
-
- // Comp doesn't exist
- val.setValue("abcd").setExists(true);
- comp.setExists(false);
- fill.setValue(new Date(123321)).setExists(true);
- assertEquals("abcd", func.getObject());
- assertTrue(func.exists());
-
- // Value exists
- // Comp != Val
- val.setValue(new Date(1234)).setExists(true);
- comp.setValue(1234).setExists(true);
-
- fill.setValue("not used").setExists(true);
- assertEquals(new Date(1234), func.getObject());
- assertTrue(func.exists());
-
- fill.setExists(false);
- assertEquals(new Date(1234), func.getObject());
- assertTrue(func.exists());
-
- // Comp == Val
- val.setValue(2342.324F).setExists(true);
- comp.setValue(2342.324F).setExists(true);
-
- fill.setExists(false);
- func.getObject();
- assertFalse(func.exists());
-
- fill.setValue("replacement").setExists(true);
- assertEquals("replacement", func.getObject());
- assertTrue(func.exists());
- }
-
- @Test
- public void multiValueBooleanTest() {
- TestBooleanValueStream val = new TestBooleanValueStream();
- TestBooleanValue comp = new TestBooleanValue();
- TestBooleanValue fill = new TestBooleanValue();
-
- AnalyticsValueStream uncasted = ReplaceFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, comp, fill});
- assertTrue(uncasted instanceof BooleanValueStream);
- BooleanValueStream func = (BooleanValueStream) uncasted;
-
- // No values
- val.setValues();
- comp.setExists(false);
- fill.setExists(false);
- func.streamBooleans( value -> {
- assertTrue("There should be no values to stream", false);
- });
-
- val.setValues();
- comp.setValue(true).setExists(true);
- fill.setValue(false).setExists(true);
- func.streamBooleans( value -> {
- assertTrue("There should be no values to stream", false);
- });
-
- // Comp doesn't exist
- val.setValues(false, true, false, true, true);
- comp.setExists(false);
- fill.setValue(true).setExists(true);
- Iterator<Boolean> values1 = Arrays.asList(false, true, false, true, true).iterator();
- func.streamBooleans( value -> {
- assertTrue(values1.hasNext());
- assertEquals(values1.next(), value);
- });
- assertFalse(values1.hasNext());
-
- // Values exist
- val.setValues(false, true, false, true, true);
- comp.setValue(true).setExists(true);
- fill.setValue(false).setExists(true);
- Iterator<Boolean> values2 = Arrays.asList(false, false, false, false, false).iterator();
- func.streamBooleans( value -> {
- assertTrue(values2.hasNext());
- assertEquals(values2.next(), value);
- });
- assertFalse(values2.hasNext());
-
- val.setValues(false, true, false, true, true);
- comp.setValue(false).setExists(true);
- fill.setExists(false);
- Iterator<Boolean> values3 = Arrays.asList(true, true, true).iterator();
- func.streamBooleans( value -> {
- assertTrue(values3.hasNext());
- assertEquals(values3.next(), value);
- });
- assertFalse(values3.hasNext());
- }
-
- @Test
- public void multiValueIntTest() {
- TestIntValueStream val = new TestIntValueStream();
- TestIntValue comp = new TestIntValue();
- TestIntValue fill = new TestIntValue();
-
- AnalyticsValueStream uncasted = ReplaceFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, comp, fill});
- assertTrue(uncasted instanceof IntValueStream);
- IntValueStream func = (IntValueStream) uncasted;
-
- // No values
- val.setValues();
- comp.setExists(false);
- fill.setExists(false);
- func.streamInts( value -> {
- assertTrue("There should be no values to stream", false);
- });
-
- val.setValues();
- comp.setValue(324).setExists(true);
- fill.setValue(52341).setExists(true);
- func.streamInts( value -> {
- assertTrue("There should be no values to stream", false);
- });
-
- // Comp doesn't exist
- val.setValues(1, 234, -234, 4439, -234, -3245);
- comp.setExists(false);
- fill.setValue(52135).setExists(true);
- Iterator<Integer> values1 = Arrays.asList(1, 234, -234, 4439, -234, -3245).iterator();
- func.streamInts( value -> {
- assertTrue(values1.hasNext());
- assertEquals(values1.next().intValue(), value);
- });
- assertFalse(values1.hasNext());
-
- // Values exist
- val.setValues(1, 234, -234, 4439, -234, -3245);
- comp.setValue(-234).setExists(true);
- fill.setExists(false);
- Iterator<Integer> values2 = Arrays.asList(1, 234, 4439, -3245).iterator();
- func.streamInts( value -> {
- assertTrue(values2.hasNext());
- assertEquals(values2.next().intValue(), value);
- });
- assertFalse(values2.hasNext());
-
- val.setValues(1, 234, -234, 4439, -234, -3245);
- comp.setValue(4439).setExists(true);
- fill.setValue(-1000).setExists(true);
- Iterator<Integer> values3 = Arrays.asList(1, 234, -234, -1000, -234, -3245).iterator();
- func.streamInts( value -> {
- assertTrue(values3.hasNext());
- assertEquals(values3.next().intValue(), value);
- });
- assertFalse(values3.hasNext());
- }
-
- @Test
- public void multiValueLongTest() {
- TestLongValueStream val = new TestLongValueStream();
- TestLongValue comp = new TestLongValue();
- TestLongValue fill = new TestLongValue();
-
- AnalyticsValueStream uncasted = ReplaceFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, comp, fill});
- assertTrue(uncasted instanceof LongValueStream);
- LongValueStream func = (LongValueStream) uncasted;
-
- // No values
- val.setValues();
- comp.setExists(false);
- fill.setExists(false);
- func.streamLongs( value -> {
- assertTrue("There should be no values to stream", false);
- });
-
- val.setValues();
- comp.setValue(2323L).setExists(true);
- fill.setValue(-5943L).setExists(true);
- func.streamLongs( value -> {
- assertTrue("There should be no values to stream", false);
- });
-
- // Comp doesn't exist
- val.setValues(1L, 234L, -234L, 4439L, -234L, -3245L);
- comp.setExists(false);
- fill.setValue(52135L).setExists(true);
- Iterator<Long> values1 = Arrays.asList(1L, 234L, -234L, 4439L, -234L, -3245L).iterator();
- func.streamLongs( value -> {
- assertTrue(values1.hasNext());
- assertEquals(values1.next().longValue(), value);
- });
- assertFalse(values1.hasNext());
-
- // Values exist
- val.setValues(1L, 234L, -234L, 4439L, -234L, -3245L);
- comp.setValue(-234L).setExists(true);
- fill.setExists(false);
- Iterator<Long> values2 = Arrays.asList(1L, 234L, 4439L, -3245L).iterator();
- func.streamLongs( value -> {
- assertTrue(values2.hasNext());
- assertEquals(values2.next().longValue(), value);
- });
- assertFalse(values2.hasNext());
-
- val.setValues(1L, 234L, -234L, 4439L, -234L, -3245L);
- comp.setValue(4439L).setExists(true);
- fill.setValue(-1000L).setExists(true);
- Iterator<Long> values3 = Arrays.asList(1L, 234L, -234L, -1000L, -234L, -3245L).iterator();
- func.streamLongs( value -> {
- assertTrue(values3.hasNext());
- assertEquals(values3.next().longValue(), value);
- });
- assertFalse(values3.hasNext());
- }
-
- @Test
- public void multiValueFloatTest() {
- TestFloatValueStream val = new TestFloatValueStream();
- TestFloatValue comp = new TestFloatValue();
- TestFloatValue fill = new TestFloatValue();
-
- AnalyticsValueStream uncasted = ReplaceFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, comp, fill});
- assertTrue(uncasted instanceof FloatValueStream);
- FloatValueStream func = (FloatValueStream) uncasted;
-
- // No values
- val.setValues();
- comp.setExists(false);
- fill.setExists(false);
- func.streamFloats( value -> {
- assertTrue("There should be no values to stream", false);
- });
-
- val.setValues();
- comp.setValue(-230.32F).setExists(true);
- fill.setValue(9459.3458F).setExists(true);
- func.streamFloats( value -> {
- assertTrue("There should be no values to stream", false);
- });
-
- // Comp doesn't exist
- val.setValues(1423.3F, 423.4323F, -2349.2F, -343.43934F, 423.4323F);
- comp.setExists(false);
- fill.setValue(234.234F).setExists(true);
- Iterator<Float> values1 = Arrays.asList(1423.3F, 423.4323F, -2349.2F, -343.43934F, 423.4323F).iterator();
- func.streamFloats( value -> {
- assertTrue(values1.hasNext());
- assertEquals(values1.next(), value, .000001);
- });
- assertFalse(values1.hasNext());
-
- // Values exist
- val.setValues(1423.3F, 423.4323F, -2349.2F, -343.43934F, 423.4323F);
- comp.setValue(423.4323F).setExists(true);
- fill.setExists(false);
- Iterator<Float> values2 = Arrays.asList(1423.3F, -2349.2F, -343.43934F).iterator();
- func.streamFloats( value -> {
- assertTrue(values2.hasNext());
- assertEquals(values2.next(), value, .000001);
- });
- assertFalse(values2.hasNext());
-
- val.setValues(1423.3F, 423.4323F, -2349.2F, -343.43934F, 423.4323F);
- comp.setValue(423.4323F).setExists(true);
- fill.setValue(-1000F).setExists(true);
- Iterator<Float> values3 = Arrays.asList(1423.3F, -1000F, -2349.2F, -343.43934F, -1000F).iterator();
- func.streamFloats( value -> {
- assertTrue(values3.hasNext());
- assertEquals(values3.next(), value, .000001);
- });
- assertFalse(values3.hasNext());
- }
-
- @Test
- public void multiValueDoubleTest() {
- TestDoubleValueStream val = new TestDoubleValueStream();
- TestDoubleValue comp = new TestDoubleValue();
- TestDoubleValue fill = new TestDoubleValue();
-
- AnalyticsValueStream uncasted = ReplaceFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, comp, fill});
- assertTrue(uncasted instanceof DoubleValueStream);
- DoubleValueStream func = (DoubleValueStream) uncasted;
-
- // No values
- val.setValues();
- comp.setExists(false);
- fill.setExists(false);
- func.streamDoubles( value -> {
- assertTrue("There should be no values to stream", false);
- });
-
- val.setValues();
- comp.setValue(234237.67).setExists(true);
- fill.setValue(-234.312).setExists(true);
- func.streamDoubles( value -> {
- assertTrue("There should be no values to stream", false);
- });
-
- // Comp doesn't exist
- val.setValues(1423.3, 423.4323, -2349.2, -343.43934, 423.4323);
- comp.setExists(false);
- fill.setValue(234.234).setExists(true);
- Iterator<Double> values1 = Arrays.asList(1423.3, 423.4323, -2349.2, -343.43934, 423.4323).iterator();
- func.streamDoubles( value -> {
- assertTrue(values1.hasNext());
- assertEquals(values1.next(), value, .000001);
- });
- assertFalse(values1.hasNext());
-
- // Values exist
- val.setValues(1423.3, 423.4323, -2349.2, -343.43934, 423.4323);
- comp.setValue(423.4323).setExists(true);
- fill.setExists(false);
- Iterator<Double> values2 = Arrays.asList(1423.3, -2349.2, -343.43934).iterator();
- func.streamDoubles( value -> {
- assertTrue(values2.hasNext());
- assertEquals(values2.next(), value, .000001);
- });
- assertFalse(values2.hasNext());
-
- val.setValues(1423.3, 423.4323, -2349.2, -343.43934, 423.4323);
- comp.setValue(423.4323).setExists(true);
- fill.setValue(-1000.0).setExists(true);
- Iterator<Double> values3 = Arrays.asList(1423.3, -1000.0, -2349.2, -343.43934, -1000.0).iterator();
- func.streamDoubles( value -> {
- assertTrue(values3.hasNext());
- assertEquals(values3.next(), value, .000001);
- });
- assertFalse(values3.hasNext());
- }
-
- @Test
- public void multiValueDateTest() throws DateTimeParseException {
- Date date1 = Date.from(Instant.parse("1810-12-02T10:30:15Z"));
- Date date2 = Date.from(Instant.parse("1931-03-16T18:15:45Z"));
- Date date3 = Date.from(Instant.parse("2023-11-01T20:30:15Z"));
-
- TestDateValueStream val = new TestDateValueStream();
- TestDateValue comp = new TestDateValue();
- TestDateValue fill = new TestDateValue();
-
- AnalyticsValueStream uncasted = ReplaceFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, comp, fill});
- assertTrue(uncasted instanceof DateValueStream);
- DateValueStream func = (DateValueStream) uncasted;
-
- // No values
- val.setValues();
- comp.setExists(false);
- fill.setExists(false);
- func.streamLongs( value -> {
- assertTrue("There should be no values to stream", false);
- });
-
- val.setValues();
- comp.setValue("1700-12-14").setExists(true);
- fill.setValue("3450-04-23").setExists(true);
- func.streamLongs( value -> {
- assertTrue("There should be no values to stream", false);
- });
-
- // Comp doesn't exist
- val.setValues("1810-12-02T10:30:15Z", "1931-03-16T18:15:45Z", "2023-11-01T20:30:15Z", "1931-03-16T18:15:45Z");
- comp.setExists(false);
- fill.setValue("1810-12-02T10:30:15Z").setExists(true);
- Iterator<Long> values1 = Arrays.asList(date1.getTime(), date2.getTime(), date3.getTime(), date2.getTime()).iterator();
- func.streamLongs( value -> {
- assertTrue(values1.hasNext());
- assertEquals(values1.next().longValue(), value);
- });
- assertFalse(values1.hasNext());
-
- // Values exist
- val.setValues("1810-12-02T10:30:15Z", "1931-03-16T18:15:45Z", "2023-11-01T20:30:15Z", "1931-03-16T18:15:45Z");
- comp.setValue("1931-03-16T18:15:45Z").setExists(true);
- fill.setExists(false);
- Iterator<Long> values2 = Arrays.asList(date1.getTime(), date3.getTime()).iterator();
- func.streamLongs( value -> {
- assertTrue(values2.hasNext());
- assertEquals(values2.next().longValue(), value);
- });
- assertFalse(values2.hasNext());
-
- val.setValues("1810-12-02T10:30:15Z", "1931-03-16T18:15:45Z", "2023-11-01T20:30:15Z", "1931-03-16T18:15:45Z");
- comp.setValue("1931-03-16T18:15:45Z").setExists(true);
- fill.setValue("1810-12-02T10:30:15Z").setExists(true);
- Iterator<Long> values3 = Arrays.asList(date1.getTime(), date1.getTime(), date3.getTime(), date1.getTime()).iterator();
- func.streamLongs( value -> {
- assertTrue(values3.hasNext());
- assertEquals(values3.next().longValue(), value);
- });
- assertFalse(values3.hasNext());
- }
-
- @Test
- public void multiValueStringTest() {
- TestStringValueStream val = new TestStringValueStream();
- TestStringValue comp = new TestStringValue();
- TestStringValue fill = new TestStringValue();
-
- AnalyticsValueStream uncasted = ReplaceFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, comp, fill});
- assertTrue(uncasted instanceof StringValueStream);
- StringValueStream func = (StringValueStream) uncasted;
-
- // No values
- val.setValues();
- comp.setExists(false);
- fill.setExists(false);
- func.streamStrings( value -> {
- assertTrue("There should be no values to stream", false);
- });
-
- val.setValues();
- comp.setValue("ads").setExists(true);
- fill.setValue("empty").setExists(true);
- func.streamStrings( value -> {
- assertTrue("There should be no values to stream", false);
- });
-
- // Comp doesn't exist
- val.setValues("abc", "123", "456", "def", "123");
- comp.setExists(false);
- fill.setValue("won't show up").setExists(true);
- Iterator<String> values1 = Arrays.asList("abc", "123", "456", "def", "123").iterator();
- func.streamStrings( value -> {
- assertTrue(values1.hasNext());
- assertEquals(values1.next(), value);
- });
- assertFalse(values1.hasNext());
-
- // Values exist
- val.setValues("abc", "123", "456", "def", "123");
- comp.setValue("123").setExists(true);
- fill.setExists(false);
- Iterator<String> values2 = Arrays.asList("abc", "456", "def").iterator();
- func.streamStrings( value -> {
- assertTrue(values2.hasNext());
- assertEquals(values2.next(), value);
- });
- assertFalse(values2.hasNext());
-
- val.setValues("abc", "123", "456", "def", "123");
- comp.setValue("456").setExists(true);
- fill.setValue("changed").setExists(true);
- Iterator<String> values3 = Arrays.asList("abc", "123", "changed", "def", "123").iterator();
- func.streamStrings( value -> {
- assertTrue(values3.hasNext());
- assertEquals(values3.next(), value);
- });
- assertFalse(values3.hasNext());
- }
-
- @Test
- public void multiValueObjectTest() {
- TestAnalyticsValueStream val = new TestAnalyticsValueStream();
- TestAnalyticsValue comp = new TestAnalyticsValue();
- TestAnalyticsValue fill = new TestAnalyticsValue();
-
- AnalyticsValueStream func = ReplaceFunction.creatorFunction.apply(new AnalyticsValueStream[] {val, comp, fill});
-
- // No values
- val.setValues();
- comp.setExists(false);
- fill.setExists(false);
- func.streamObjects( value -> {
- assertTrue("There should be no values to stream", false);
- });
-
- val.setValues();
- comp.setValue("doesn't matter").setExists(true);
- fill.setValue("won't show up").setExists(true);
- func.streamObjects( value -> {
- assertTrue("There should be no values to stream", false);
- });
-
- // Comp doesn't exist
- val.setValues("asdfs", new Date(12312), 213123L, new Date(12312));
- comp.setExists(false);
- fill.setValue("won't show up").setExists(true);
- Iterator<Object> values1 = Arrays.<Object>asList("asdfs", new Date(12312), 213123L, new Date(12312)).iterator();
- func.streamObjects( value -> {
- assertTrue(values1.hasNext());
- assertEquals(values1.next(), value);
- });
- assertFalse(values1.hasNext());
-
- // Values exist
- val.setValues("asdfs", new Date(12312), 213123L, new Date(12312));
- comp.setValue("asdfs").setExists(true);
- fill.setExists(false);
- Iterator<Object> values2 = Arrays.<Object>asList(new Date(12312), 213123L, new Date(12312)).iterator();
- func.streamObjects( value -> {
- assertTrue(values2.hasNext());
- assertEquals(values2.next(), value);
- });
- assertFalse(values2.hasNext());
-
- val.setValues("asdfs", new Date(12312), 213123L, new Date(12312));
- comp.setValue(new Date(12312)).setExists(true);
- fill.setValue(Boolean.FALSE).setExists(true);
- Iterator<Object> values3 = Arrays.<Object>asList("asdfs", Boolean.FALSE, 213123L, Boolean.FALSE).iterator();
- func.streamObjects( value -> {
- assertTrue(values3.hasNext());
- assertEquals(values3.next(), value);
- });
- assertFalse(values3.hasNext());
- }
-}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/f0366b94/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/RoundFunctionTest.java
----------------------------------------------------------------------
diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/RoundFunctionTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/RoundFunctionTest.java
deleted file mode 100644
index 2da48f5..0000000
--- a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/RoundFunctionTest.java
+++ /dev/null
@@ -1,180 +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
- *
- * 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.function.mapping.DecimalNumericConversionFunction.RoundFunction;
-import org.apache.solr.analytics.value.AnalyticsValueStream;
-import org.apache.solr.analytics.value.IntValue;
-import org.apache.solr.analytics.value.IntValueStream;
-import org.apache.solr.analytics.value.LongValue;
-import org.apache.solr.analytics.value.LongValueStream;
-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.junit.Test;
-
-public class RoundFunctionTest extends SolrTestCaseJ4 {
-
- @Test
- public void singleValueFloatParameterTest() {
- TestFloatValue val = new TestFloatValue();
-
- AnalyticsValueStream uncasted = RoundFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});
- assertTrue(uncasted instanceof IntValue);
- IntValue func = (IntValue) uncasted;
-
- // Value doesn't exist
- val.setExists(false);
- func.getInt();
- assertFalse(func.exists());
-
- // Value exists
- val.setValue(21.56F).setExists(true);
- assertEquals(22, func.getInt());
- assertTrue(func.exists());
-
- val.setValue(-100.3F).setExists(true);
- assertEquals(-100, func.getInt());
- assertTrue(func.exists());
- }
-
- @Test
- public void singleValueDoubleParameterTest() {
- TestDoubleValue val = new TestDoubleValue();
-
- AnalyticsValueStream uncasted = RoundFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});
- assertTrue(uncasted instanceof LongValue);
- LongValue func = (LongValue) uncasted;
-
- // Value doesn't exist
- val.setExists(false);
- func.getLong();
- assertFalse(func.exists());
-
- // Value exists
- val.setValue(21.56).setExists(true);
- assertEquals(22L, func.getLong());
- assertTrue(func.exists());
-
- val.setValue(-100.3).setExists(true);
- assertEquals(-100L, func.getLong());
- assertTrue(func.exists());
- }
-
- @Test
- public void multiValueFloatParameterTest() {
- TestFloatValueStream val = new TestFloatValueStream();
-
- AnalyticsValueStream uncasted = RoundFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});
- assertTrue(uncasted instanceof IntValueStream);
- IntValueStream func = (IntValueStream) uncasted;
-
- // No values
- val.setValues();
- func.streamInts( value -> {
- assertTrue("There should be no values to stream", false);
- });
-
- // One value
- val.setValues(-4F);
- Iterator<Integer> values1 = Arrays.asList(-4).iterator();
- func.streamInts( value -> {
- assertTrue(values1.hasNext());
- assertEquals(values1.next().intValue(), value);
- });
- assertFalse(values1.hasNext());
-
- // Multiple values
- val.setValues(4F, -10.9999F, 50.00001F, 74.99999F, 101.4999F, 105.5F);
- Iterator<Integer> values2 = Arrays.asList(4, -11, 50, 75, 101, 106).iterator();
- func.streamInts( value -> {
- assertTrue(values2.hasNext());
- assertEquals(values2.next().intValue(), value);
- });
- assertFalse(values2.hasNext());
- }
-
- @Test
- public void multiValueDoubleParameterTest() {
- TestDoubleValueStream val = new TestDoubleValueStream();
-
- AnalyticsValueStream uncasted = RoundFunction.creatorFunction.apply(new AnalyticsValueStream[] {val});
- assertTrue(uncasted instanceof LongValueStream);
- LongValueStream func = (LongValueStream) uncasted;
-
- // No values
- val.setValues();
- func.streamLongs( value -> {
- assertTrue("There should be no values to stream", false);
- });
-
- // One value
- val.setValues(-4);
- Iterator<Long> values1 = Arrays.asList(-4L).iterator();
- func.streamLongs( value -> {
- assertTrue(values1.hasNext());
- assertEquals(values1.next().longValue(), value);
- });
- assertFalse(values1.hasNext());
-
- // Multiple values
- val.setValues(4, -10.9999, 50.000001, 74.99999, 101.4999, 105.5);
- Iterator<Long> values2 = Arrays.asList(4L, -11L, 50L, 75L, 101L, 106L).iterator();
- func.streamLongs( value -> {
- assertTrue(values2.hasNext());
- assertEquals(values2.next().longValue(), value);
- });
- assertFalse(values2.hasNext());
- }
-
- @Test
- public void nonDecimalParameterTest() {
- AnalyticsValueStream result;
- AnalyticsValueStream param;
-
- param = new TestIntValue();
- result = RoundFunction.creatorFunction.apply(new AnalyticsValueStream[] {param});
- assertTrue(result instanceof IntValue);
- assertEquals(param, result);
-
- param = new TestIntValueStream();
- result = RoundFunction.creatorFunction.apply(new AnalyticsValueStream[] {param});
- assertTrue(result instanceof IntValueStream);
- assertEquals(param, result);
-
- param = new TestLongValue();
- result = RoundFunction.creatorFunction.apply(new AnalyticsValueStream[] {param});
- assertTrue(result instanceof LongValue);
- assertEquals(param, result);
-
- param = new TestLongValueStream();
- result = RoundFunction.creatorFunction.apply(new AnalyticsValueStream[] {param});
- assertTrue(result instanceof LongValueStream);
- assertEquals(param, result);
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/f0366b94/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
deleted file mode 100644
index 79ef86a..0000000
--- a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/StringCastFunctionTest.java
+++ /dev/null
@@ -1,87 +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
- *
- * 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/f0366b94/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
deleted file mode 100644
index 1095bba..0000000
--- a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/SubtractFunctionTest.java
+++ /dev/null
@@ -1,128 +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
- *
- * 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/f0366b94/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
deleted file mode 100644
index 419f883..0000000
--- a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/mapping/TopFunctionTest.java
+++ /dev/null
@@ -1,406 +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
- *
- * 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/f0366b94/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
deleted file mode 100644
index f34c667..0000000
--- a/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/LegacyAbstractAnalyticsCloudTest.java
+++ /dev/null
@@ -1,167 +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
- *
- * 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/f0366b94/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
deleted file mode 100644
index 3488f63..0000000
--- a/solr/contrib/analytics/src/test/org/apache/solr/analytics/legacy/LegacyAbstractAnalyticsTest.java
+++ /dev/null
@@ -1,234 +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
- *
- * 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);
- }
- }
-
-}