Package fr.ght1pc9kc.testy.search
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.
With
With
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 nodeOpenSearchClient client: an opensearch-java client connected to the nodeOpenSearchRunner 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 -
Method Summary
Modifier and TypeMethodDescriptionvoidafterAll(org.junit.jupiter.api.extension.ExtensionContext context) voidbeforeAll(org.junit.jupiter.api.extension.ExtensionContext context) org.opensearch.client.opensearch.OpenSearchClientgetClient(org.junit.jupiter.api.extension.ExtensionContext context) resolveParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) booleansupportsParameter(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, waitMethods inherited from interface org.junit.jupiter.api.extension.TestInstantiationAwareExtension
getTestInstantiationExtensionContextScope
-
Constructor Details
-
WithEmbeddedOpenSearch
public WithEmbeddedOpenSearch()
-
-
Method Details
-
beforeAll
- Specified by:
beforeAllin interfaceorg.junit.jupiter.api.extension.BeforeAllCallback- Throws:
Exception
-
afterAll
- Specified by:
afterAllin interfaceorg.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:
supportsParameterin interfaceorg.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:
resolveParameterin interfaceorg.junit.jupiter.api.extension.ParameterResolver- Throws:
org.junit.jupiter.api.extension.ParameterResolutionException
-