You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ho...@apache.org on 2012/01/13 23:56:02 UTC

svn commit: r1231367 - in /lucene/dev/trunk/solr: CHANGES.txt contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/ContextImpl.java contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestContextImpl.java

Author: hossman
Date: Fri Jan 13 22:56:02 2012
New Revision: 1231367

URL: http://svn.apache.org/viewvc?rev=1231367&view=rev
Log:
SOLR-2542: Fixed DIH Context variables which were broken for all scopes other then SCOPE_ENTITY

Added:
    lucene/dev/trunk/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestContextImpl.java   (with props)
Modified:
    lucene/dev/trunk/solr/CHANGES.txt
    lucene/dev/trunk/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/ContextImpl.java

Modified: lucene/dev/trunk/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/CHANGES.txt?rev=1231367&r1=1231366&r2=1231367&view=diff
==============================================================================
--- lucene/dev/trunk/solr/CHANGES.txt (original)
+++ lucene/dev/trunk/solr/CHANGES.txt Fri Jan 13 22:56:02 2012
@@ -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)

Modified: lucene/dev/trunk/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/ContextImpl.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/ContextImpl.java?rev=1231367&r1=1231366&r2=1231367&view=diff
==============================================================================
--- lucene/dev/trunk/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/ContextImpl.java (original)
+++ lucene/dev/trunk/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/ContextImpl.java Fri Jan 13 22:56:02 2012
@@ -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

Added: lucene/dev/trunk/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestContextImpl.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestContextImpl.java?rev=1231367&view=auto
==============================================================================
--- lucene/dev/trunk/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestContextImpl.java (added)
+++ lucene/dev/trunk/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestContextImpl.java Fri Jan 13 22:56:02 2012
@@ -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);
+    
+  }
+  
+}