Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-2542: Fixed DIH Context variables which were broken for all scopes other then SCOPE_ENTITY

Chris M. Hostetterb2de49f60692
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 7da876e5965..250b191f110 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -455,6 +455,9 @@ Bug Fixes
* SOLR-3024: Fixed JSONTestUtil.matchObj, in previous releases it was not
respecting the 'delta' arg (David Smiley via hossman)
+* SOLR-2542: Fixed DIH Context variables which were broken for all scopes other
+ then SCOPE_ENTITY (Linbin Chen & Frank Wesemann via hossman)
+
Other Changes
----------------------
* SOLR-2922: Upgrade commons-io and commons-lang to 2.1 and 2.6, respectively. (koji)
diff --git a/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/ContextImpl.java b/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/ContextImpl.java
index 899ced532c0..73a47e34153 100644
--- a/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/ContextImpl.java
+++ b/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/ContextImpl.java
@@ -155,7 +155,7 @@ public class ContextImpl extends Context {
private void putVal(String name, Object val, Map map) {
if(val == null) map.remove(name);
- else entitySession.put(name, val);
+ else map.put(name, val);
}
@Override
diff --git a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestContextImpl.java b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestContextImpl.java
new file mode 100644
index 00000000000..8d1b6e0db43
--- /dev/null
+++ b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestContextImpl.java
@@ -0,0 +1,71 @@
+/**
+ * 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.handler.dataimport;
+
+import java.util.HashMap;
+
+import org.apache.solr.handler.dataimport.DataConfig.Entity;
+import org.apache.solr.handler.dataimport.DataImporter.RequestParams;
+import org.junit.Test;
+
+public class TestContextImpl extends AbstractDataImportHandlerTestCase {
+
+ @Test
+ public void testEntityScope() {
+ ContextImpl ctx = new ContextImpl(new Entity(), new VariableResolverImpl(), null, "something", new HashMap<String,Object>(), null, null);
+ String lala = new String("lala");
+ ctx.setSessionAttribute("huhu", lala, Context.SCOPE_ENTITY);
+ Object got = ctx.getSessionAttribute("huhu", Context.SCOPE_ENTITY);
+
+ assertEquals(lala, got);
+
+ }
+ @Test
+ public void testCoreScope() {
+ DataImporter di = new DataImporter();
+ di.loadAndInit("<dataConfig><document /></dataConfig>");
+ DocBuilder db = new DocBuilder(di, new SolrWriter(null, null),new SimplePropertiesWriter(), new RequestParams());
+ ContextImpl ctx = new ContextImpl(new Entity(), new VariableResolverImpl(), null, "something", new HashMap<String,Object>(), null, db);
+ String lala = new String("lala");
+ ctx.setSessionAttribute("huhu", lala, Context.SCOPE_SOLR_CORE);
+ Object got = ctx.getSessionAttribute("huhu", Context.SCOPE_SOLR_CORE);
+ assertEquals(lala, got);
+
+ }
+ @Test
+ public void testDocumentScope() {
+ ContextImpl ctx = new ContextImpl(new Entity(), new VariableResolverImpl(), null, "something", new HashMap<String,Object>(), null, null);
+ ctx.setDoc(new DocBuilder.DocWrapper());
+ String lala = new String("lala");
+ ctx.setSessionAttribute("huhu", lala, Context.SCOPE_DOC);
+ Object got = ctx.getSessionAttribute("huhu", Context.SCOPE_DOC);
+
+ assertEquals(lala, got);
+
+ }
+ @Test
+ public void testGlobalScope() {
+ ContextImpl ctx = new ContextImpl(new Entity(), new VariableResolverImpl(), null, "something", new HashMap<String,Object>(), null, null);
+ String lala = new String("lala");
+ ctx.setSessionAttribute("huhu", lala, Context.SCOPE_GLOBAL);
+ Object got = ctx.getSessionAttribute("huhu", Context.SCOPE_GLOBAL);
+
+ assertEquals(lala, got);
+
+ }
+
+}