Search...tServer(3pm)

πŸ“¦
version 8.12 Β· 5 versions
, in debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– Search::Elasticsearch::TestServer β€” the manual page, but make it cute πŸ’–

Search::Elasticsearch::TestServer(3pm) β€” from the User Contributed Perl Documentation, bestie. This is the one that spins up whole Elasticsearch nodes for you like it's nothing. ✨


🌸 NAME 🌸

Search::Elasticsearch::TestServer</purl> β€” a lil helper class whose entire job is launching Elasticsearch nodes for you. That's it. That's the girlboss. πŸ’…

⭐ VERSION ⭐

version 8.12

πŸ¦‹ SYNOPSIS πŸ¦‹

okay so here's the whole vibe in one go:

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;

like. it starts the servers, you point your client at them, you run your tests, you shut it down. effortless. πŸ”₯

🌈 DESCRIPTION 🌈

The Search::Elasticsearch::TestServer class is here to launch one or more instances of Elasticsearch purely for testing purposes. Yes, multiple. Yes, whenever you want. And the nodes? They get shut down automatically, so you don't have to chase after them. no cap. 🫢


πŸŽ€ 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, bestie:

  • es_home β€” Required, no skipping. It has to point at the Elasticsearch home directory, the one that contains ./bin/elasticsearch. Defaults to $ENV{ES_HOME}.
  • es_version β€” also Required. Takes a version of the client, eg 6_0, 5_0, 2_0, 1_0, 0_90. Defaults to $ENV{ES_VERSION}.
  • instances β€” how many nodes to start. Defaults to 1.
  • http_port β€” the port used for HTTP. If you start multiple instances, the http_port gets incremented for each subsequent instance. Defaults to 9600.
  • es_port β€” the port used for Elasticsearch's internal transport. Same deal: multiple instances means the es_port gets incremented for each subsequent instance. Defaults to 9700.
  • conf β€” an array holding any extra startup options you want passed straight to Elasticsearch.

✨ start()

$nodes = $server->start;

Starts up all the instances you asked for and hands you back an array ref with the IP and port of each node β€” formatted exactly so you can pass it straight to new() in Search::Elasticsearch:

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

it's giving plug-and-play honestly. πŸ‘‘

🧚 shutdown()

$server->shutdown;

Kills the running instances. periodt. πŸ’€

And the best part? This gets called automatically when $server goes out of scope, or if the program catches a SIGINT. so you literally cannot forget. iconic behaviour fr fr.


πŸ‘‘ AUTHOR πŸ‘‘

Enrico Zimuel <enrico.zimuel@elastic.co>

This software is Copyright (c) 2024 by Elasticsearch BV.

This is free software, licensed under:

The Apache License, Version 2.0, January 2004

and that's the whole page, bestie πŸ₯° this was Search...tServer(3pm) β€” shipped as part of perl v5.38.2, dated 2024-02-04. go forth and spin up nodes. slay. πŸ’…βœ¨

πŸ“¦ where this page comes from