Jdurham2843 commented on a change in pull request #243:
URL: https://github.com/apache/solr/pull/243#discussion_r705840763



##########
File path: solr/solrj/src/test/org/apache/solr/client/solrj/io/TupleTest.java
##########
@@ -0,0 +1,199 @@
+/*
+ * 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.client.solrj.io;
+
+import org.apache.solr.SolrTestCase;
+import org.apache.solr.common.MapWriter.EntryWriter;
+import org.apache.solr.common.params.StreamParams;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+
+public class TupleTest extends SolrTestCase {
+
+    @Test
+    public void putAllSetsEOFMarker() {
+        final Map<String, Object> fields = new HashMap<>();
+        fields.put("field-one", new Object());
+        fields.put("field-two", new Object());
+        fields.put(StreamParams.EOF, true);
+
+        final Tuple tuple = new Tuple();
+        tuple.putAll(fields);
+
+        assertTrue(tuple.EOF);
+    }
+
+    @Test
+    public void putAllSetsEXCEPTIONMarker() {
+        final Map<String, Object> fields = new HashMap<>();
+        fields.put("field-one", new Object());
+        fields.put("field-two", new Object());
+        fields.put(StreamParams.EXCEPTION, "exception");
+
+        final Tuple tuple = new Tuple();
+        tuple.putAll(fields);
+
+        assertTrue(tuple.EXCEPTION);
+    }
+
+    @Test
+    public void cloneTest() {
+        final Map<String, Object> fields = new HashMap<>();
+        fields.put("field-one", new Object());
+        fields.put("field-two", new Object());
+        fields.put(StreamParams.EXCEPTION, "exception");
+        fields.put(StreamParams.EOF, true);
+        final Tuple original = new Tuple();
+        original.putAll(fields);
+        original.setFieldNames(new ArrayList<>(Arrays.asList("field-one", 
"field-two")));
+        original.setFieldLabels(new HashMap<>(Map.ofEntries(
+                Map.entry("field-one", "field one"),
+                Map.entry("field-two", "field two")
+        )));
+
+        final Tuple clone = new Tuple(original);
+
+        assertEquals(original.getFields().entrySet().size(), 
clone.getFields().entrySet().size());
+        assertEquals(original.getFieldNames().size(), 
clone.getFieldNames().size());
+        assertEquals(original.getFieldLabels().entrySet().size(), 
clone.getFieldLabels().entrySet().size());
+        assertEquals(original.EOF, clone.EOF);
+        assertEquals(original.EXCEPTION, clone.EXCEPTION);
+    }
+
+    @Test
+    public void mergeTest() {
+        final Map<String, Object> commonFields = new HashMap<>();
+        commonFields.put("field-one", new Object());
+        commonFields.put("field-two", new Object());
+        commonFields.put("field-three", new Object());
+        commonFields.put(StreamParams.EXCEPTION, "exception");
+        commonFields.put(StreamParams.EOF, true);
+
+        final Tuple tupleOne = new Tuple();
+        tupleOne.putAll(commonFields);
+        tupleOne.setFieldNames(new ArrayList<>(Arrays.asList("field-one-name", 
"field-two-name", "field-three-name")));
+        tupleOne.setFieldLabels(new HashMap<>(Map.ofEntries(
+                Map.entry("field-one-name", "field-one"),
+                Map.entry("field-two-nam", "field-two"),
+                Map.entry("field-three-name", "field-three")
+        )));
+
+        final Tuple tupleTwo = new Tuple();
+        tupleTwo.putAll(commonFields);
+        tupleTwo.put("field-four", new Object());
+        tupleTwo.put("new-field-two", new Object());
+        tupleTwo.setFieldNames(new ArrayList<>(Arrays.asList("field-one-name", 
"field-two-name", "field-four-name")));
+        tupleTwo.setFieldLabels(new HashMap<>(Map.ofEntries(
+                Map.entry("field-one-name", "field-one"),
+                Map.entry("field-two-name", "new-field-two"),
+                Map.entry("field-four-name", "field-four")
+        )));
+
+        tupleOne.merge(tupleTwo);
+
+        assertEquals(7, tupleOne.getFields().size());
+        assertEquals(4, tupleOne.getFieldNames().size());
+        assertEquals(5, tupleOne.getFieldLabels().size());

Review comment:
       That was a typo - nice catch! I'll push a change here shortly.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org
For additional commands, e-mail: issues-h...@solr.apache.org

Reply via email to