Skip to content

Commit

Permalink
Add tests for RemoteGlobalMetadataManager (opensearch-project#14394)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
shiv0408 committed Jun 19, 2024
1 parent 8aed62e commit 8e32ed7
Show file tree
Hide file tree
Showing 8 changed files with 573 additions and 10 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ public void testSerDe() throws IOException {
}
}

private CoordinationMetadata getCoordinationMetadata() {
public static CoordinationMetadata getCoordinationMetadata() {
return CoordinationMetadata.builder()
.term(TERM)
.lastAcceptedConfiguration(new VotingConfiguration(Set.of("node1")))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public void testSerDe() throws IOException {
}
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public void testSerDe() throws IOException {
}
}

private Metadata getGlobalMetadata() {
public static Metadata getGlobalMetadata() {
return Metadata.builder()
.templates(
TemplatesMetadata.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public void testSerDe() throws IOException {
}
}

private DiffableStringMap getHashesOfConsistentSettings() {
public static DiffableStringMap getHashesOfConsistentSettings() {
Map<String, String> hashesOfConsistentSettings = new HashMap<>();
hashesOfConsistentSettings.put("secure-setting-key", "secure-setting-value");
return new DiffableStringMap(hashesOfConsistentSettings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public void testSerDe() throws IOException {
}
}

private Settings getSettings() {
public static Settings getSettings() {
return Settings.builder().put("random_index_setting_" + randomAlphaOfLength(3), randomAlphaOfLength(5)).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ public void testSerDe() throws IOException {
}
}

private TemplatesMetadata getTemplatesMetadata() {
public static TemplatesMetadata getTemplatesMetadata() {
return TemplatesMetadata.builder()
.put(
IndexTemplateMetadata.builder("template" + randomAlphaOfLength(3))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* 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.common.util;

import org.opensearch.core.action.ActionListener;

/**
* A simple implementation of {@link ActionListener} that captures the response and failures used for testing purposes.
*
* @param <T> the result type
*/
public class TestCapturingListener<T> implements ActionListener<T> {
private T result;
private Exception failure;

@Override
public void onResponse(T result) {
this.result = result;
}

@Override
public void onFailure(Exception e) {
this.failure = e;
}

public T getResult() {
return result;
}

public Exception getFailure() {
return failure;
}
}

0 comments on commit 8e32ed7

Please sign in to comment.