Class WithEmbeddedOpenSearch

java.lang.Object
fr.ght1pc9kc.testy.search.WithEmbeddedOpenSearch
All Implemented Interfaces:
org.junit.jupiter.api.extension.AfterAllCallback, org.junit.jupiter.api.extension.BeforeAllCallback, org.junit.jupiter.api.extension.Extension, org.junit.jupiter.api.extension.ParameterResolver, org.junit.jupiter.api.extension.TestInstantiationAwareExtension

public class WithEmbeddedOpenSearch extends Object implements org.junit.jupiter.api.extension.BeforeAllCallback, org.junit.jupiter.api.extension.AfterAllCallback, org.junit.jupiter.api.extension.ParameterResolver
Starts a single-node OpenSearch cluster inside the test JVM, without Docker.

Uses opensearch-runner from codelibs. OpenSearch has no in-memory store, so the node writes its data in a temporary directory that is deleted once the tests are done.

This extension allows the injection of:

  • @OpenSearchPort Integer port: the HTTP port of the node
  • OpenSearchClient client: an opensearch-java client connected to the node
  • OpenSearchRunner runner: the runner itself

Usage :

With @ExtendWith


  @ExtendWith(WithEmbeddedOpenSearch.class)
  class WithEmbeddedOpenSearchTest {
      @Test
      void should_use_embedded_opensearch(OpenSearchClient client) throws IOException {
          client.index(i -> i.index("my-index").id("1").document(Map.of("name", "Luke")));
      }
  }
 

With @RegisterExtension


 @RegisterExtension
 static WithEmbeddedOpenSearch wOpenSearch = WithEmbeddedOpenSearch.builder().build();
 
See Also:
  • Nested Class Summary

    Nested classes/interfaces inherited from interface org.junit.jupiter.api.extension.TestInstantiationAwareExtension

    org.junit.jupiter.api.extension.TestInstantiationAwareExtension.ExtensionContextScope
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    afterAll(org.junit.jupiter.api.extension.ExtensionContext context)
     
    void
    beforeAll(org.junit.jupiter.api.extension.ExtensionContext context)
     
    org.opensearch.client.opensearch.OpenSearchClient
    getClient(org.junit.jupiter.api.extension.ExtensionContext context)
     
    resolveParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext)
     
    boolean
    supportsParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.junit.jupiter.api.extension.TestInstantiationAwareExtension

    getTestInstantiationExtensionContextScope
  • Constructor Details

    • WithEmbeddedOpenSearch

      public WithEmbeddedOpenSearch()
  • Method Details

    • beforeAll

      public void beforeAll(org.junit.jupiter.api.extension.ExtensionContext context) throws Exception
      Specified by:
      beforeAll in interface org.junit.jupiter.api.extension.BeforeAllCallback
      Throws:
      Exception
    • afterAll

      public void afterAll(org.junit.jupiter.api.extension.ExtensionContext context) throws Exception
      Specified by:
      afterAll in interface org.junit.jupiter.api.extension.AfterAllCallback
      Throws:
      Exception
    • getClient

      public org.opensearch.client.opensearch.OpenSearchClient getClient(org.junit.jupiter.api.extension.ExtensionContext context)
    • supportsParameter

      public boolean supportsParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) throws org.junit.jupiter.api.extension.ParameterResolutionException
      Specified by:
      supportsParameter in interface org.junit.jupiter.api.extension.ParameterResolver
      Throws:
      org.junit.jupiter.api.extension.ParameterResolutionException
    • resolveParameter

      public Object resolveParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) throws org.junit.jupiter.api.extension.ParameterResolutionException
      Specified by:
      resolveParameter in interface org.junit.jupiter.api.extension.ParameterResolver
      Throws:
      org.junit.jupiter.api.extension.ParameterResolutionException