logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

Search::Elasticsearch::TestServer - A helper class to launch Elasticsearch nodes

Author

       Enrico Zimuel <enrico.zimuel@elastic.co>

Description

       The Search::Elasticsearch::TestServer class can be used to launch one or more instances of Elasticsearch
       for testing purposes.  The nodes will be shutdown automatically.

Methods

new()
           my $server = Search::Elasticsearch::TestServer->new(
               es_home    => '/path/to/elasticsearch',
               es_version => '6_0',
               instances => 1,
               http_port => 9600,
               es_port   => 9700,
               conf      => ['attr.foo=bar'],
           );

       Params:

       •   "es_home"

           Required.  Must  point  to  the  Elasticsearch  home directory, which contains "./bin/elasticsearch".
           Defaults to $ENV{ES_HOME}

       •   "es_version"

           Required. Accepts a version of the client, eg  `6_0`,  `5_0`,  `2_0`,  `1_0`,  `0_90`.   Defaults  to
           $ENV{ES_VERSION}.

       •   "instances"

           The number of nodes to start. Defaults to 1

       •   "http_port"

           The  port to use for HTTP. If multiple instances are started, the "http_port" will be incremented for
           each subsequent instance. Defaults to 9600.

       •   "es_port"

           The port to use for Elasticsearch's internal  transport.  If  multiple  instances  are  started,  the
           "es_port" will be incremented for each subsequent instance.  Defaults to 9700

       •   "conf"

           An array containing any extra startup options that should be passed to Elasticsearch.

Name

       Search::Elasticsearch::TestServer - A helper class to launch Elasticsearch nodes

Shutdown()

           $server->shutdown;

       Kills the running instances.  This will be called automatically when $server goes out of scope or if  the
       program receives a "SIGINT".

Start()

           $nodes = $server->start;

       Starts  the required instances and returns an array ref containing the IP and port of each node, suitable
       for passing to "new()" in Search::Elasticsearch:

           $es = Search::Elasticsearch->new( nodes => $nodes );

Synopsis

           use Search::Elasticsearch;
           use Search::Elasticsearch::TestServer;

           my $server = Search::Elasticsearch::TestServer->new(
               es_home    => '/path/to/elasticsearch',  # defaults to $ENV{ES_HOME}
               es_version => '6_0'                      # defaults to $ENV{ES_VERSION}
           );

           my $nodes = $server->start;
           my $es    = Search::Elasticsearch->new( nodes => $nodes );
           # run tests
           $server->shutdown;

Version

       version 8.12

See Also