Skip to content

Commit 8e32ed7

Browse files
authored
Add tests for RemoteGlobalMetadataManager (opensearch-project#14394)
* Add tests for RemoteGlobalMetadataManager Signed-off-by: Shivansh Arora <hishiv@amazon.com> * Add TestCapturingListener Signed-off-by: Shivansh Arora <hishiv@amazon.com> * Move TestCapturingListener to test/framework Signed-off-by: Shivansh Arora <hishiv@amazon.com> * Added javadoc Signed-off-by: Shivansh Arora <hishiv@amazon.com> --------- Signed-off-by: Shivansh Arora <hishiv@amazon.com>
1 parent 8aed62e commit 8e32ed7

8 files changed

+573
-10
lines changed

server/src/test/java/org/opensearch/gateway/remote/RemoteGlobalMetadataManagerTests.java

+528-4
Large diffs are not rendered by default.

server/src/test/java/org/opensearch/gateway/remote/model/RemoteCoordinationMetadataTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ public void testSerDe() throws IOException {
229229
}
230230
}
231231

232-
private CoordinationMetadata getCoordinationMetadata() {
232+
public static CoordinationMetadata getCoordinationMetadata() {
233233
return CoordinationMetadata.builder()
234234
.term(TERM)
235235
.lastAcceptedConfiguration(new VotingConfiguration(Set.of("node1")))

server/src/test/java/org/opensearch/gateway/remote/model/RemoteCustomMetadataTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ public void testSerDe() throws IOException {
232232
}
233233
}
234234

235-
private Custom getCustomMetadata() {
235+
public static Custom getCustomMetadata() {
236236
return IndexGraveyard.builder().addTombstone(new Index("test-index", "3q2423")).build();
237237
}
238238

server/src/test/java/org/opensearch/gateway/remote/model/RemoteGlobalMetadataTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ public void testSerDe() throws IOException {
180180
}
181181
}
182182

183-
private Metadata getGlobalMetadata() {
183+
public static Metadata getGlobalMetadata() {
184184
return Metadata.builder()
185185
.templates(
186186
TemplatesMetadata.builder()

server/src/test/java/org/opensearch/gateway/remote/model/RemoteHashesOfConsistentSettingsTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ public void testSerDe() throws IOException {
185185
}
186186
}
187187

188-
private DiffableStringMap getHashesOfConsistentSettings() {
188+
public static DiffableStringMap getHashesOfConsistentSettings() {
189189
Map<String, String> hashesOfConsistentSettings = new HashMap<>();
190190
hashesOfConsistentSettings.put("secure-setting-key", "secure-setting-value");
191191
return new DiffableStringMap(hashesOfConsistentSettings);

server/src/test/java/org/opensearch/gateway/remote/model/RemotePersistentSettingsMetadataTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ public void testSerDe() throws IOException {
224224
}
225225
}
226226

227-
private Settings getSettings() {
227+
public static Settings getSettings() {
228228
return Settings.builder().put("random_index_setting_" + randomAlphaOfLength(3), randomAlphaOfLength(5)).build();
229229
}
230230
}

server/src/test/java/org/opensearch/gateway/remote/model/RemoteTemplatesMetadataTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ public void testSerDe() throws IOException {
227227
}
228228
}
229229

230-
private TemplatesMetadata getTemplatesMetadata() {
230+
public static TemplatesMetadata getTemplatesMetadata() {
231231
return TemplatesMetadata.builder()
232232
.put(
233233
IndexTemplateMetadata.builder("template" + randomAlphaOfLength(3))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
package org.opensearch.common.util;
10+
11+
import org.opensearch.core.action.ActionListener;
12+
13+
/**
14+
* A simple implementation of {@link ActionListener} that captures the response and failures used for testing purposes.
15+
*
16+
* @param <T> the result type
17+
*/
18+
public class TestCapturingListener<T> implements ActionListener<T> {
19+
private T result;
20+
private Exception failure;
21+
22+
@Override
23+
public void onResponse(T result) {
24+
this.result = result;
25+
}
26+
27+
@Override
28+
public void onFailure(Exception e) {
29+
this.failure = e;
30+
}
31+
32+
public T getResult() {
33+
return result;
34+
}
35+
36+
public Exception getFailure() {
37+
return failure;
38+
}
39+
}

0 commit comments

Comments
 (0)