You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by "Madhire, Naveen" <Na...@capitalone.com> on 2016/03/16 21:22:26 UTC

SolrCloud App Unit Testing

Hi,

I am writing a Solr Application, can anyone please let me know how to Unit test the application?

I see we have MiniSolrCloudCluster class available in Solr, but I am confused about how to use that for Unit testing.

How should I create a embedded server for unit testing?



Thanks,
Naveen
________________________________________________________

The information contained in this e-mail is confidential and/or proprietary to Capital One and/or its affiliates and may only be used solely in performance of work or services for Capital One. The information transmitted herewith is intended only for use by the individual or entity to which it is addressed. If the reader of this message is not the intended recipient, you are hereby notified that any review, retransmission, dissemination, distribution, copying or other use of, or taking of any action in reliance upon this information is strictly prohibited. If you have received this communication in error, please contact the sender and delete the material from your computer.

Re: SolrCloud App Unit Testing

Posted by Chris Hostetter <ho...@fucit.org>.
Naveen:

As a "user" of Solr, wanting to develop tests for your solr based 
application you'll probably get more responses on the solr-user@lucene 
list (the dev@lucene is for discussing hte development of lucene & solr 
themselves)

The quick answer is that, assuming you are writting your tests in java, 
you can use MiniSolrCloudCluster to spin up embeeded instances of Solr and 
create/access (solrj) SolrClient objects for sending requests to the solr 
cluster.

If you are attempting to write unit tests is some other (non-java) 
langauge, you'll need to find some way to 'exec" the "bin/solr" command on 
the command line from your test framework -- either that, or leave a solr 
cluster running at all times, and configure your tests to generate 
distinct collection names and create those collections against the 
existing cluster.


: Date: Wed, 16 Mar 2016 20:22:26 +0000
: From: "Madhire, Naveen" <Na...@capitalone.com>
: Reply-To: dev@lucene.apache.org
: To: "dev@lucene.apache.org" <de...@lucene.apache.org>
: Subject: SolrCloud App Unit Testing
: 
: Hi,
: 
: I am writing a Solr Application, can anyone please let me know how to Unit test the application?
: 
: I see we have MiniSolrCloudCluster class available in Solr, but I am confused about how to use that for Unit testing.
: 
: How should I create a embedded server for unit testing?
: 
: 
: 
: Thanks,
: Naveen
: ________________________________________________________
: 
: The information contained in this e-mail is confidential and/or proprietary to Capital One and/or its affiliates and may only be used solely in performance of work or services for Capital One. The information transmitted herewith is intended only for use by the individual or entity to which it is addressed. If the reader of this message is not the intended recipient, you are hereby notified that any review, retransmission, dissemination, distribution, copying or other use of, or taking of any action in reliance upon this information is strictly prohibited. If you have received this communication in error, please contact the sender and delete the material from your computer.
: 

-Hoss
http://www.lucidworks.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org


Re: SolrCloud App Unit Testing

Posted by Steve Davids <sd...@gmail.com>.
Naveen,

The Solr codebase generally uses the base “SolrTestCaseJ4” class and sometimes mixes in the cloud cluster. I personally write a generic abstract base test class to fit my needs and have an abstract `getSolrServer` method with an EmbeddedSolrServer implementation along with a separate implementation for the CloudSolrServer. I use the EmbeddedSolrServer for almost all of my test cases since it is a lot faster to setup, I’ll pull in the Cloud implementation if there is some distributed logic that is necessary for testing. Here is a simple example project (https://gitlab.com/bti360/solr-exercise/tree/example-solution <https://gitlab.com/bti360/solr-exercise/tree/example-solution>) which has a base test <https://gitlab.com/bti360/solr-exercise/blob/example-solution/src/test/java/com/bti360/gt/search/BaseSolrTestCase.java> which piggy-backs off the SolrTestCase class. If you don’t want to complete the “exercise” switch over to the 

Hopefully that points you in the right direction,

-Steve


> On Mar 17, 2016, at 1:03 PM, Davis, Daniel (NIH/NLM) [C] <da...@nih.gov> wrote:
> 
> MiniSolrCloudCluster is intended for building unit tests for cloud commands within Solr itself.
> 
> What most people do to test applications based on Solr (and their Solr configurations) is to start solr either on their CI server or in the cloud (more likely the later), and then point their application at that Solr instance through configuration for the unit tests.   They may also have separate tests to test the Solr collection/core configuration itself.
> 
> You can have your CI tool (Travis/etc.) or unit test scripts start-up Solr locally, or in the cloud, using various tools and concoctions.   Part of the core of that is the solr command-line in SOLR_HOME/bin, post tool in SOLR_HOME/bin, and zkcli in SOLR_HOME/server/scripts/cloud-scripts.
> 
> To start Solr in the cloud, you should look towards something that exists:
> 	https://github.com/lucidworks/solr-scale-tk 
> 	https://github.com/vkhatri/chef-solrcloud
> 
> Hope this helps,
> 
> -Dan
> 
> -----Original Message-----
> From: Madhire, Naveen [mailto:Naveen.Madhire@capitalone.com] 
> Sent: Thursday, March 17, 2016 11:24 AM
> To: solr-user@lucene.apache.org
> Subject: FW: SolrCloud App Unit Testing
> 
> 
> Hi,
> 
> I am writing a Solr Application, can anyone please let me know how to Unit test the application?
> 
> I see we have MiniSolrCloudCluster class available in Solr, but I am confused about how to use that for Unit testing.
> 
> How should I create a embedded server for unit testing?
> 
> 
> 
> Thanks,
> Naveen
> ________________________________________________________
> 
> The information contained in this e-mail is confidential and/or proprietary to Capital One and/or its affiliates and may only be used solely in performance of work or services for Capital One. The information transmitted herewith is intended only for use by the individual or entity to which it is addressed. If the reader of this message is not the intended recipient, you are hereby notified that any review, retransmission, dissemination, distribution, copying or other use of, or taking of any action in reliance upon this information is strictly prohibited. If you have received this communication in error, please contact the sender and delete the material from your computer.


RE: SolrCloud App Unit Testing

Posted by "Davis, Daniel (NIH/NLM) [C]" <da...@nih.gov>.
MiniSolrCloudCluster is intended for building unit tests for cloud commands within Solr itself.

What most people do to test applications based on Solr (and their Solr configurations) is to start solr either on their CI server or in the cloud (more likely the later), and then point their application at that Solr instance through configuration for the unit tests.   They may also have separate tests to test the Solr collection/core configuration itself.

You can have your CI tool (Travis/etc.) or unit test scripts start-up Solr locally, or in the cloud, using various tools and concoctions.   Part of the core of that is the solr command-line in SOLR_HOME/bin, post tool in SOLR_HOME/bin, and zkcli in SOLR_HOME/server/scripts/cloud-scripts.

To start Solr in the cloud, you should look towards something that exists:
	https://github.com/lucidworks/solr-scale-tk 
	https://github.com/vkhatri/chef-solrcloud

Hope this helps,

-Dan

-----Original Message-----
From: Madhire, Naveen [mailto:Naveen.Madhire@capitalone.com] 
Sent: Thursday, March 17, 2016 11:24 AM
To: solr-user@lucene.apache.org
Subject: FW: SolrCloud App Unit Testing


Hi,

I am writing a Solr Application, can anyone please let me know how to Unit test the application?

I see we have MiniSolrCloudCluster class available in Solr, but I am confused about how to use that for Unit testing.

How should I create a embedded server for unit testing?



Thanks,
Naveen
________________________________________________________

The information contained in this e-mail is confidential and/or proprietary to Capital One and/or its affiliates and may only be used solely in performance of work or services for Capital One. The information transmitted herewith is intended only for use by the individual or entity to which it is addressed. If the reader of this message is not the intended recipient, you are hereby notified that any review, retransmission, dissemination, distribution, copying or other use of, or taking of any action in reliance upon this information is strictly prohibited. If you have received this communication in error, please contact the sender and delete the material from your computer.

Re: FW: SolrCloud App Unit Testing

Posted by Shawn Heisey <ap...@elyograg.org>.
On 3/19/2016 7:11 AM, GW wrote:
> I think the easiest way to write apps for Solr is with some kind of
> programming language and the REST API. Don't bother with the PHP or Perl
> modules. They are deprecated and beyond useless. just use the HTTP call
> that you see in Solr Admin. Mind the URL encoding when putting together
> your server calls.

The problem with using the REST-like API directly is that you have to
understand the API completely and construct every URL parameter
yourself.  You also have to understand the response format and write
code to extract the info you need from the response.

Using a pre-made client makes it so you don't have to do ANY of that. 
The request is built up from easily understood objects/methods, and all
the useful information from the response is loaded into data structures
that are fairly easy to understand if you know the language you're
writing in.

There are a LOT of php clients, and some of them have seen new releases
about three months ago.  I wouldn't call that deprecated.

https://wiki.apache.org/solr/IntegratingSolr#PHP

There aren't as many clients for Perl.  I haven't checked the last
update for these yet:

https://wiki.apache.org/solr/IntegratingSolr#Perl

Thanks,
Shawn


Re: FW: SolrCloud App Unit Testing

Posted by GW <th...@gmail.com>.
I think the easiest way to write apps for Solr is with some kind of
programming language and the REST API. Don't bother with the PHP or Perl
modules. They are deprecated and beyond useless. just use the HTTP call
that you see in Solr Admin. Mind the URL encoding when putting together
your server calls.

I've used Perl and PHP with Curl to create Solr Apps

PHP:

function fetchContent($URL){
                $ch = curl_init();
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                curl_setopt($ch, CURLOPT_URL, $URL);
                $data = curl_exec($ch);
                $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
                curl_close($ch);
                if ($httpCode == "404") {
                $data="nin";
                }
        return $data;
        }


switch($filters){

case "":
$url = "http://localhost:8983/solr/products/query?q=name
:".$urlsearch."^20+OR+short_description:".$urlsearch."~6&rows=13&start=".$start."&fl=*,score&wt=json";
break;

case "clothing":
$url = "http://localhost:8983/solr/products/query
?q=name:%22".$urlsearch."%22^20+OR
+short_description:%22".$urlsearch."%22~6&rows=13&start=".$start."&fl=*,score&wt=json";
break;

case "beauty cosmetics":

$url = "http://localhost:8983/solr/products/query?q=name
:".$urlsearch."^20+OR+short_description:".$urlsearch."~6&rows=13&start=".$start."&fl=*,score&wt=json";


break;


}


$my_data = fetchContent($url);


Data goes into the $my_data as a JSON string in this case.


/////////////// your forward facing App can be in Apache round robin in
front of a Solr system. This gives you insane scalability in the client app
and the Solr service.


Hope that helps.

GW


On 17 March 2016 at 11:23, Madhire, Naveen <Na...@capitalone.com>
wrote:

>
> Hi,
>
> I am writing a Solr Application, can anyone please let me know how to Unit
> test the application?
>
> I see we have MiniSolrCloudCluster class available in Solr, but I am
> confused about how to use that for Unit testing.
>
> How should I create a embedded server for unit testing?
>
>
>
> Thanks,
> Naveen
> ________________________________________________________
>
> The information contained in this e-mail is confidential and/or
> proprietary to Capital One and/or its affiliates and may only be used
> solely in performance of work or services for Capital One. The information
> transmitted herewith is intended only for use by the individual or entity
> to which it is addressed. If the reader of this message is not the intended
> recipient, you are hereby notified that any review, retransmission,
> dissemination, distribution, copying or other use of, or taking of any
> action in reliance upon this information is strictly prohibited. If you
> have received this communication in error, please contact the sender and
> delete the material from your computer.
>

FW: SolrCloud App Unit Testing

Posted by "Madhire, Naveen" <Na...@capitalone.com>.
Hi,

I am writing a Solr Application, can anyone please let me know how to Unit test the application?

I see we have MiniSolrCloudCluster class available in Solr, but I am confused about how to use that for Unit testing.

How should I create a embedded server for unit testing?



Thanks,
Naveen
________________________________________________________

The information contained in this e-mail is confidential and/or proprietary to Capital One and/or its affiliates and may only be used solely in performance of work or services for Capital One. The information transmitted herewith is intended only for use by the individual or entity to which it is addressed. If the reader of this message is not the intended recipient, you are hereby notified that any review, retransmission, dissemination, distribution, copying or other use of, or taking of any action in reliance upon this information is strictly prohibited. If you have received this communication in error, please contact the sender and delete the material from your computer.