jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tomm...@apache.org
Subject svn commit: r1462183 - in /jackrabbit/oak/trunk/oak-solr-core/src: main/java/org/apache/jackrabbit/oak/plugins/index/solr/server/ test/java/org/apache/jackrabbit/oak/plugins/index/solr/server/
Date Thu, 28 Mar 2013 16:08:30 GMT
Author: tommaso
Date: Thu Mar 28 16:08:30 2013
New Revision: 1462183

URL: http://svn.apache.org/r1462183
Log:
OAK-720 - UpToDate NSC should not return defaults if the NS doesn't exist at the specified
path

Modified:
    jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/server/DefaultOakSolrProvider.java
    jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/server/OakSolrNodeStateConfiguration.java
    jackrabbit/oak/trunk/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/server/UpToDateNodeStateConfigurationTest.java

Modified: jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/server/DefaultOakSolrProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/server/DefaultOakSolrProvider.java?rev=1462183&r1=1462182&r2=1462183&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/server/DefaultOakSolrProvider.java
(original)
+++ jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/server/DefaultOakSolrProvider.java
Thu Mar 28 16:08:30 2013
@@ -57,20 +57,25 @@ public class DefaultOakSolrProvider impl
         String coreName = oakSolrConfiguration.getCoreName();
         String solrConfigPath = oakSolrConfiguration.getSolrConfigPath();
 
-        checkSolrConfiguration(solrHomePath, solrConfigPath, coreName);
+        if (solrConfigPath != null && solrHomePath != null && coreName !=
null) {
 
-        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
-        Thread.currentThread().setContextClassLoader(CoreContainer.class.getClassLoader());
+            checkSolrConfiguration(solrHomePath, solrConfigPath, coreName);
 
-        CoreContainer coreContainer = new CoreContainer(solrHomePath);
-        try {
-            coreContainer.load(solrHomePath, new File(solrConfigPath));
-        } finally {
-            Thread.currentThread().setContextClassLoader(classLoader);
-        }
+            ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+            Thread.currentThread().setContextClassLoader(CoreContainer.class.getClassLoader());
 
+            CoreContainer coreContainer = new CoreContainer(solrHomePath);
+            try {
+                coreContainer.load(solrHomePath, new File(solrConfigPath));
+            } finally {
+                Thread.currentThread().setContextClassLoader(classLoader);
+            }
 
-        return new EmbeddedSolrServer(coreContainer, coreName);
+            return new EmbeddedSolrServer(coreContainer, coreName);
+        }
+        else {
+            throw new Exception("SolrServer configuration proprties not set");
+        }
     }
 
     private void checkSolrConfiguration(String solrHomePath, String solrConfigPath, String
coreName) throws IOException {
@@ -84,7 +89,7 @@ public class DefaultOakSolrProvider impl
                 // copy all the needed files to the just created directory
                 copy("/solr/solr.xml", solrHomePath);
                 copy("/solr/zoo.cfg", solrHomePath);
-                if (!new File(solrHomePath + "/" + "oak").mkdir() || !new File(solrHomePath
+ "/" + "oak/conf/").mkdir()) {
+                if (!new File(solrHomePath + "/oak/conf").mkdirs()) {
                     throw new IOException("could not create nested core directory in solrHomePath");
                 }
                 String coreDir = solrHomePath + "/oak/conf/";

Modified: jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/server/OakSolrNodeStateConfiguration.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/server/OakSolrNodeStateConfiguration.java?rev=1462183&r1=1462182&r2=1462183&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/server/OakSolrNodeStateConfiguration.java
(original)
+++ jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/server/OakSolrNodeStateConfiguration.java
Thu Mar 28 16:08:30 2013
@@ -38,7 +38,8 @@ public abstract class OakSolrNodeStateCo
      * get the {@link NodeState} which contains the properties for the Oak -
      * Solr configuration.
      *
-     * @return a {@link NodeState} for the Solr configuration.
+     * @return a {@link NodeState} for the Solr configuration or <code>null</code>
+     *         if such a {@link NodeState} doesn't exist.
      */
     protected abstract NodeState getConfigurationNodeState();
 
@@ -112,9 +113,9 @@ public abstract class OakSolrNodeStateCo
             if (property != null) {
                 value = property.getValue(Type.STRING);
             }
-        }
-        if (value == null || value.length() == 0) {
-            value = defaultValue;
+            if (value == null || value.length() == 0) {
+                value = defaultValue;
+            }
         }
         return value;
     }

Modified: jackrabbit/oak/trunk/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/server/UpToDateNodeStateConfigurationTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/server/UpToDateNodeStateConfigurationTest.java?rev=1462183&r1=1462182&r2=1462183&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/server/UpToDateNodeStateConfigurationTest.java
(original)
+++ jackrabbit/oak/trunk/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/server/UpToDateNodeStateConfigurationTest.java
Thu Mar 28 16:08:30 2013
@@ -10,6 +10,7 @@ import org.junit.Test;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
 
 /**
  * Testcase for {@link UpToDateNodeStateConfiguration}
@@ -28,17 +29,24 @@ public class UpToDateNodeStateConfigurat
     }
 
     @Test
-    public void testPath() throws Exception {
+    public void testExistingPath() throws Exception {
         String path = "oak:index/solrIdx";
         UpToDateNodeStateConfiguration upToDateNodeStateConfiguration = new UpToDateNodeStateConfiguration(store,
path);
-        assertEquals("cn", upToDateNodeStateConfiguration.getCoreName());
+        assertEquals("cn", upToDateNodeStateConfiguration.getCoreName()); // property defined
in the node state
+        assertEquals("path_exact", upToDateNodeStateConfiguration.getPathField()); // using
default as this property not defined in the node state
     }
 
     @Test
     public void testNonExistingPath() throws Exception {
         String path = "some/path/to/oak:index/solrIdx";
         UpToDateNodeStateConfiguration upToDateNodeStateConfiguration = new UpToDateNodeStateConfiguration(store,
path);
-        assertNotNull(upToDateNodeStateConfiguration.getSolrConfigPath());
-        assertEquals("./solr.xml", upToDateNodeStateConfiguration.getSolrConfigPath());
+        assertNull(upToDateNodeStateConfiguration.getSolrConfigPath());
+    }
+
+    @Test
+    public void testNodeStateNotFound() throws Exception {
+        String path = "some/path/to/somewhere/unknown";
+        UpToDateNodeStateConfiguration upToDateNodeStateConfiguration = new UpToDateNodeStateConfiguration(store,
path);
+        assertNull(upToDateNodeStateConfiguration.getConfigurationNodeState());
     }
 }



Mime
View raw message