Skip to content

Commit

Permalink
Fix java doc, add test of WeightedRoundRobinRouting metadata
Browse files Browse the repository at this point in the history
Signed-off-by: Anshu Agarwal <anshukag@amazon.com>
  • Loading branch information
Anshu Agarwal committed Sep 1, 2022
1 parent 7c64537 commit 154a3b9
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
public class WeightedRoundRobinRoutingMetadata extends AbstractNamedDiffable<Metadata.Custom> implements Metadata.Custom {
private static final Logger logger = LogManager.getLogger(WeightedRoundRobinRoutingMetadata.class);
public static final String TYPE = "wrr_shard_routing";
public static final String AWARENESS = "awareness";
private WRRWeights wrrWeight;

public WRRWeights getWrrWeight() {
Expand Down Expand Up @@ -140,7 +141,7 @@ public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params par
}

public static void toXContent(WRRWeights wrrWeight, XContentBuilder builder) throws IOException {
builder.startObject("awareness");
builder.startObject(AWARENESS);
builder.startObject(wrrWeight.attributeName());
for (Map.Entry<String, Object> entry : wrrWeight.weights().entrySet()) {
builder.field(entry.getKey(), entry.getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@

import java.util.ArrayList;
import java.util.List;

/**
* Weighted Round Robin Scheduling policy
*
*/
public class WeightedRoundRobin<T> {

private List<WeightedRoundRobin.Entity<T>> entities;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* 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.cluster.metadata;

import org.opensearch.cluster.routing.WRRWeights;
import org.opensearch.common.xcontent.XContentParser;
import org.opensearch.test.AbstractXContentTestCase;

import java.io.IOException;
import java.util.Map;

public class WeightedRoundRobinRoutingMetadataTests extends AbstractXContentTestCase<WeightedRoundRobinRoutingMetadata> {
@Override
protected WeightedRoundRobinRoutingMetadata createTestInstance() {
Map<String, Object> weights = Map.of("a", "1", "b", "1", "c", "0");
WRRWeights wrrWeights = new WRRWeights("zone", weights);
WeightedRoundRobinRoutingMetadata wrrMetadata = new WeightedRoundRobinRoutingMetadata(wrrWeights);
return wrrMetadata;
}

@Override
protected WeightedRoundRobinRoutingMetadata doParseInstance(XContentParser parser) throws IOException {
return WeightedRoundRobinRoutingMetadata.fromXContent(parser);
}

@Override
protected boolean supportsUnknownFields() {
return false;
}

}

0 comments on commit 154a3b9

Please sign in to comment.