diff --git a/src/main/java/org/opensearch/sdk/ExtensionsRunner.java b/src/main/java/org/opensearch/sdk/ExtensionsRunner.java index 1751cac0..3449df72 100644 --- a/src/main/java/org/opensearch/sdk/ExtensionsRunner.java +++ b/src/main/java/org/opensearch/sdk/ExtensionsRunner.java @@ -303,7 +303,6 @@ public void updateNamedWriteableRegistry() { this.sdkNamedWriteableRegistry.updateNamedWriteableRegistry(this); } - /** * Gets the NamedXContentRegistry. Only valid if {@link #isInitialized()} returns true. * diff --git a/src/main/java/org/opensearch/sdk/NettyTransport.java b/src/main/java/org/opensearch/sdk/NettyTransport.java index 82d1c0c8..ba6f2baa 100644 --- a/src/main/java/org/opensearch/sdk/NettyTransport.java +++ b/src/main/java/org/opensearch/sdk/NettyTransport.java @@ -13,7 +13,6 @@ import org.opensearch.Version; import org.opensearch.cluster.node.DiscoveryNode; -import org.opensearch.common.io.stream.NamedWriteableRegistry; import org.opensearch.common.network.NetworkService; import org.opensearch.common.settings.Settings; import org.opensearch.common.util.PageCacheRecycler; diff --git a/src/main/java/org/opensearch/sdk/ScriptExtension.java b/src/main/java/org/opensearch/sdk/ScriptExtension.java index 326fde73..e336fa13 100644 --- a/src/main/java/org/opensearch/sdk/ScriptExtension.java +++ b/src/main/java/org/opensearch/sdk/ScriptExtension.java @@ -38,4 +38,4 @@ default ScriptEngine getScriptEngine(Settings settings, Collection> getContexts() { return Collections.emptyList(); } -} \ No newline at end of file +} diff --git a/src/test/java/org/opensearch/sdk/TestSDKNamedWriteableRegistry.java b/src/test/java/org/opensearch/sdk/TestSDKNamedWriteableRegistry.java index 85c039e2..eadbfaf6 100644 --- a/src/test/java/org/opensearch/sdk/TestSDKNamedWriteableRegistry.java +++ b/src/test/java/org/opensearch/sdk/TestSDKNamedWriteableRegistry.java @@ -1,3 +1,12 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + package org.opensearch.sdk; import org.junit.jupiter.api.BeforeEach; @@ -12,8 +21,6 @@ import java.io.IOException; import java.util.Collections; import java.util.List; -import java.util.Objects; - public class TestSDKNamedWriteableRegistry extends OpenSearchTestCase { private TestSDKNamedWriteableRegistry.ExampleRunnerForTest runner; @@ -21,9 +28,9 @@ public class TestSDKNamedWriteableRegistry extends OpenSearchTestCase { private static class Example implements NamedWriteable { public static final String NAME = "Example"; public static final NamedWriteableRegistry.Entry WRITEABLE_REGISTRY = new NamedWriteableRegistry.Entry( - TestSDKNamedWriteableRegistry.Example.class, - NAME, - null + TestSDKNamedWriteableRegistry.Example.class, + NAME, + null ); private final String name; @@ -32,29 +39,13 @@ public Example(String name) { this.name = name; } - - @Override - public boolean equals(Object o) { - if (o == null || getClass() != o.getClass()) { - return false; - } - TestSDKNamedWriteableRegistry.Example that = (TestSDKNamedWriteableRegistry.Example) o; - return Objects.equals(name, that.name); - } - - @Override - public int hashCode() { - return Objects.hash(name); - } - @Override public String getWriteableName() { - return null; + return name; } @Override - public void writeTo(StreamOutput out) throws IOException { - } + public void writeTo(StreamOutput out) throws IOException {} } private static class ExampleRunnerForTest extends ExtensionsRunnerForTest { @@ -94,10 +85,19 @@ public void testDefaultNamedWriteableRegistry() throws IOException { NamedWriteableRegistry registry = runner.sdkNamedWriteableRegistry.getRegistry(); XContentParseException ex = assertThrows( - XContentParseException.class, - () -> registry.getReader(TestSDKNamedWriteableRegistry.Example.class, TestSDKNamedWriteableRegistry.Example.NAME) + XContentParseException.class, + () -> registry.getReader(TestSDKNamedWriteableRegistry.Example.class, TestSDKNamedWriteableRegistry.Example.NAME) ); - assertEquals("unknown named object category [" + TestSDKNamedWriteableRegistry.Example.class.getName() + "]", ex.getMessage()); + assertEquals("Unknown NamedWriteable category [" + TestSDKNamedWriteableRegistry.Example.class.getName() + "]", ex.getMessage()); } + @Test + public void testCustomNamedWriteableRegistryParse() throws IOException { + // Update the runner before testing + runner.updateNamedWriteableRegistry(); + NamedWriteableRegistry registry = runner.sdkNamedWriteableRegistry.getRegistry(); + + TestSDKNamedWriteableRegistry.Example example = (Example) registry.getReader(Example.class, Example.NAME); + assertEquals(TestSDKNamedWriteableRegistry.Example.NAME, example.getWriteableName()); + } }