From 9b985f6461ae891b8a2eb2661959ff680dc22688 Mon Sep 17 00:00:00 2001 From: Mark Robert Miller Date: Tue, 18 Mar 2014 17:27:47 +0000 Subject: [PATCH] SOLR-5832: Scary logging from ZkControllerTest suggests test setup isn't doing what it's suppose to. git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1578974 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/solr/core/CoreContainer.java | 15 ++++++ .../apache/solr/cloud/ZkControllerTest.java | 53 +++++++++++-------- .../apache/solr/util/MockCoreContainer.java | 24 +++++++++ 3 files changed, 71 insertions(+), 21 deletions(-) create mode 100644 solr/core/src/test/org/apache/solr/util/MockCoreContainer.java diff --git a/solr/core/src/java/org/apache/solr/core/CoreContainer.java b/solr/core/src/java/org/apache/solr/core/CoreContainer.java index 711d649b8e3..30ed54d129b 100644 --- a/solr/core/src/java/org/apache/solr/core/CoreContainer.java +++ b/solr/core/src/java/org/apache/solr/core/CoreContainer.java @@ -18,6 +18,7 @@ package org.apache.solr.core; import com.google.common.collect.Maps; + import org.apache.solr.cloud.ZkController; import org.apache.solr.cloud.ZkSolrResourceLoader; import org.apache.solr.common.SolrException; @@ -158,6 +159,20 @@ public class CoreContainer { this.coresLocator = locator; } + /** + * This method allows subclasses to construct a CoreContainer + * without any default init behavior. + * + * @param testConstructor pass (Object)null. + * @lucene.experimental + */ + protected CoreContainer(Object testConstructor) { + solrHome = null; + loader = null; + coresLocator = null; + cfg = null; + } + /** * Create a new CoreContainer and load its cores * @param solrHome the solr home directory diff --git a/solr/core/src/test/org/apache/solr/cloud/ZkControllerTest.java b/solr/core/src/test/org/apache/solr/cloud/ZkControllerTest.java index 64ce1246535..f9f847fa6e7 100644 --- a/solr/core/src/test/org/apache/solr/cloud/ZkControllerTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/ZkControllerTest.java @@ -17,7 +17,12 @@ package org.apache.solr.cloud; * the License. */ -import org.apache.commons.io.FileUtils; +import java.io.File; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + import org.apache.lucene.util.LuceneTestCase.Slow; import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.common.cloud.SolrZkClient; @@ -25,18 +30,14 @@ import org.apache.solr.common.cloud.ZkNodeProps; import org.apache.solr.common.cloud.ZkStateReader; import org.apache.solr.core.CoreContainer; import org.apache.solr.core.CoreDescriptor; +import org.apache.solr.handler.component.HttpShardHandlerFactory; +import org.apache.solr.handler.component.ShardHandlerFactory; import org.apache.solr.util.ExternalPaths; import org.apache.zookeeper.CreateMode; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; -import java.io.File; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - @Slow public class ZkControllerTest extends SolrTestCaseJ4 { @@ -46,23 +47,14 @@ public class ZkControllerTest extends SolrTestCaseJ4 { private static final boolean DEBUG = false; - - private static final File solrHomeDirectory = new File(TEMP_DIR, "ZkControllerTest"); - @BeforeClass public static void beforeClass() throws Exception { - if (solrHomeDirectory.exists()) { - FileUtils.deleteDirectory(solrHomeDirectory); - } - copyMinFullSetup(solrHomeDirectory); - initCore(); + createTempDir(); } @AfterClass public static void afterClass() throws Exception { - if (solrHomeDirectory.exists()) { - FileUtils.deleteDirectory(solrHomeDirectory); - } + } public void testNodeNameUrlConversion() throws Exception { @@ -307,9 +299,7 @@ public class ZkControllerTest extends SolrTestCaseJ4 { } private CoreContainer getCoreContainer() { - CoreContainer cc = new CoreContainer(solrHomeDirectory.getAbsolutePath()); - cc.load(); - return cc; + return new MockCoreContainer(); } @Override @@ -317,4 +307,25 @@ public class ZkControllerTest extends SolrTestCaseJ4 { super.tearDown(); } + private static class MockCoreContainer extends CoreContainer { + private HttpShardHandlerFactory shardHandlerFactory; + + public MockCoreContainer() { + super((Object)null); + this.shardHandlerFactory = new HttpShardHandlerFactory(); + } + + @Override + public void load() {}; + + @Override + public String getAdminPath() { + return "/admin/cores"; + } + + @Override + public ShardHandlerFactory getShardHandlerFactory() { + return shardHandlerFactory; + } + } } diff --git a/solr/core/src/test/org/apache/solr/util/MockCoreContainer.java b/solr/core/src/test/org/apache/solr/util/MockCoreContainer.java new file mode 100644 index 00000000000..94d988a2c05 --- /dev/null +++ b/solr/core/src/test/org/apache/solr/util/MockCoreContainer.java @@ -0,0 +1,24 @@ +package org.apache.solr.util; + +import org.apache.solr.core.CoreContainer; + +/* + * 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. + */ + +public class MockCoreContainer extends CoreContainer { + +}