<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Solr: How to test solr  distributed component? in Archives of Support Questions (Read Only)</title>
    <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Solr-How-to-test-solr-distributed-component/m-p/171836#M50145</link>
    <description>&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have developed a custom Solr search component for which I need to write unit tests. As I have seen in the code of other Solr components, writing unit tests in Solr is done by extending the &lt;A href="http://lucene.apache.org/solr/4_9_0/solr-test-framework/org/apache/solr/SolrTestCaseJ4.html" target="_blank"&gt;SolrTestCaseJ4&lt;/A&gt; class. Unfortunately, &lt;A href="http://lucene.apache.org/solr/4_9_0/solr-test-framework/org/apache/solr/SolrTestCaseJ4.html" target="_blank"&gt;SolrTestCaseJ4&lt;/A&gt; doesn't deal with testing in a distributed setting, and my custom component works only in such a setting. As a matter of fact, my component deliberately returns empty responses when not in a distributed setting.&lt;/P&gt;
&lt;P&gt;I'm trying to think of a way to use the &lt;A href="http://lucene.apache.org/solr/4_9_0/solr-test-framework/org/apache/solr/BaseDistributedSearchTestCase.html" target="_blank"&gt;BaseDistributedSearchTestCase&lt;/A&gt; class to test my component. The problem with &lt;A href="http://lucene.apache.org/solr/4_9_0/solr-test-framework/org/apache/solr/BaseDistributedSearchTestCase.html" target="_blank"&gt;BaseDistributedSearchTestCase&lt;/A&gt; is that how it works won't solve my issue. When using &lt;A href="http://lucene.apache.org/solr/4_9_0/solr-test-framework/org/apache/solr/BaseDistributedSearchTestCase.html" target="_blank"&gt;BaseDistributedSearchTestCase&lt;/A&gt; you define a single test method where you index all the documents and perform some queries. Running the tests executes the requests both on a distributed setting and on a single core setting. It then compares the responses of each setting to verify their equality. I cannot explicitly assert anything in that flow. How do I write unit tests for a Solr distributed component?&lt;/P&gt;</description>
    <pubDate>Sat, 30 Nov 2019 14:30:39 GMT</pubDate>
    <dc:creator>gkiranseo</dc:creator>
    <dc:date>2019-11-30T14:30:39Z</dc:date>
    <item>
      <title>Solr: How to test solr  distributed component?</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Solr-How-to-test-solr-distributed-component/m-p/171836#M50145</link>
      <description>&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have developed a custom Solr search component for which I need to write unit tests. As I have seen in the code of other Solr components, writing unit tests in Solr is done by extending the &lt;A href="http://lucene.apache.org/solr/4_9_0/solr-test-framework/org/apache/solr/SolrTestCaseJ4.html" target="_blank"&gt;SolrTestCaseJ4&lt;/A&gt; class. Unfortunately, &lt;A href="http://lucene.apache.org/solr/4_9_0/solr-test-framework/org/apache/solr/SolrTestCaseJ4.html" target="_blank"&gt;SolrTestCaseJ4&lt;/A&gt; doesn't deal with testing in a distributed setting, and my custom component works only in such a setting. As a matter of fact, my component deliberately returns empty responses when not in a distributed setting.&lt;/P&gt;
&lt;P&gt;I'm trying to think of a way to use the &lt;A href="http://lucene.apache.org/solr/4_9_0/solr-test-framework/org/apache/solr/BaseDistributedSearchTestCase.html" target="_blank"&gt;BaseDistributedSearchTestCase&lt;/A&gt; class to test my component. The problem with &lt;A href="http://lucene.apache.org/solr/4_9_0/solr-test-framework/org/apache/solr/BaseDistributedSearchTestCase.html" target="_blank"&gt;BaseDistributedSearchTestCase&lt;/A&gt; is that how it works won't solve my issue. When using &lt;A href="http://lucene.apache.org/solr/4_9_0/solr-test-framework/org/apache/solr/BaseDistributedSearchTestCase.html" target="_blank"&gt;BaseDistributedSearchTestCase&lt;/A&gt; you define a single test method where you index all the documents and perform some queries. Running the tests executes the requests both on a distributed setting and on a single core setting. It then compares the responses of each setting to verify their equality. I cannot explicitly assert anything in that flow. How do I write unit tests for a Solr distributed component?&lt;/P&gt;</description>
      <pubDate>Sat, 30 Nov 2019 14:30:39 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Solr-How-to-test-solr-distributed-component/m-p/171836#M50145</guid>
      <dc:creator>gkiranseo</dc:creator>
      <dc:date>2019-11-30T14:30:39Z</dc:date>
    </item>
    <item>
      <title>Re: Solr: How to test solr  distributed component?</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Solr-How-to-test-solr-distributed-component/m-p/171837#M50146</link>
      <description>&lt;P&gt;@&lt;A href="https://community.hortonworks.com/users/15055/gkiranseo.html"&gt;kiran gutha&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Since Solr 4.7 has been added a class, MiniSolrCloudCluster, that actually "deploys" locally (and if you want ram only or on a temp dir) a complete solr cluster, with zookeeper, shards and everything, for your tests. You can find the jira here : &lt;A href="https://issues.apache.org/jira/browse/SOLR-5865"&gt;https://issues.apache.org/jira/browse/SOLR-5865&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Here is an example:&lt;/P&gt;&lt;PRE&gt;private static MiniSolrCloudCluster miniCluster;
    private static CloudSolrServer cloudSolrServer;

    @BeforeClass
    public static void setup() throws Exception {
        miniCluster = new MiniSolrCloudCluster(2, null, new File("src/main/solr/solr.xml"), null, null);
        uploadConfigToZk("src/main/solr/content/conf/", "content");

        // override settings in the solrconfig include
        System.setProperty("solr.tests.maxBufferedDocs", "100000");
        System.setProperty("solr.tests.maxIndexingThreads", "-1");
        System.setProperty("solr.tests.ramBufferSizeMB", "100");
        // use non-test classes so RandomizedRunner isn't necessary
        System.setProperty("solr.tests.mergeScheduler", "org.apache.lucene.index.ConcurrentMergeScheduler");
        System.setProperty("solr.directoryFactory", "solr.RAMDirectoryFactory");        

        cloudSolrServer = new CloudSolrServer(miniCluster.getZkServer().getZkAddress(), false);
        cloudSolrServer.setRequestWriter(new RequestWriter());
        cloudSolrServer.setParser(new XMLResponseParser());
        cloudSolrServer.setDefaultCollection("content");
        cloudSolrServer.setParallelUpdates(false);
        cloudSolrServer.connect();

        createCollection(cloudSolrServer, "content", 2, 1, "content");

    }

    protected static void uploadConfigToZk(String configDir, String configName) throws Exception {
        SolrZkClient zkClient = null;
        try {
            zkClient = new SolrZkClient(miniCluster.getZkServer().getZkAddress(), 10000, 45000, null);
            uploadConfigFileToZk(zkClient, configName, "solrconfig.xml", new File(configDir, "solrconfig.xml"));
            uploadConfigFileToZk(zkClient, configName, "schema.xml", new File(configDir, "schema.xml"));
            uploadConfigFileToZk(zkClient, configName, "stopwords_en.txt", new File(configDir, "stopwords_en.txt"));
            uploadConfigFileToZk(zkClient, configName, "stopwords_it.txt", new File(configDir, "stopwords_it.txt"));

            System.out.println(zkClient.getChildren(ZkController.CONFIGS_ZKNODE + "/" + configName, null, true));
        } finally {
            if (zkClient != null)
                zkClient.close();
        }
    }

    protected static void uploadConfigFileToZk(SolrZkClient zkClient, String configName, String nameInZk, File file) throws Exception {
        zkClient.makePath(ZkController.CONFIGS_ZKNODE + "/" + configName + "/" + nameInZk, file, false, true);
    }

    @AfterClass
    public static void shutDown() throws Exception {
        miniCluster.shutdown();
    }

    protected static NamedList createCollection(CloudSolrServer server, String name, int numShards, int replicationFactor, String configName) throws Exception {
        ModifiableSolrParams modParams = new ModifiableSolrParams();
        modParams.set(CoreAdminParams.ACTION, CollectionAction.CREATE.name());
        modParams.set("name", name);
        modParams.set("numShards", numShards);
        modParams.set("replicationFactor", replicationFactor);
        modParams.set("collection.configName", configName);
        QueryRequest request = new QueryRequest(modParams);
        request.setPath("/admin/collections");
        return server.request(request);
    }

    @Test
    public void test() throws Exception {
      // Do you stuff here using cloudSolrServer as a normal solrServer
    }
&lt;/PRE&gt;</description>
      <pubDate>Tue, 27 Dec 2016 05:33:56 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Solr-How-to-test-solr-distributed-component/m-p/171837#M50146</guid>
      <dc:creator>cstanca</dc:creator>
      <dc:date>2016-12-27T05:33:56Z</dc:date>
    </item>
  </channel>
</rss>

