Skip to content

Commit

Permalink
Fix RingRange string method
Browse files Browse the repository at this point in the history
  • Loading branch information
emerkle826 committed Sep 14, 2023
1 parent 3727fab commit 9e10a39
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.datastax.mgmtapi.resources.v2.models.RingRange;
import com.datastax.oss.driver.api.core.cql.ResultSet;
import com.datastax.oss.driver.api.core.cql.Row;
import com.google.common.annotations.VisibleForTesting;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.ExampleObject;
Expand Down Expand Up @@ -122,14 +123,15 @@ private String getParallelismName(RepairParallelism parallelism) {
return parallelism != null ? parallelism.getName() : null;
}

private String getRingRangeString(List<RingRange> associatedTokens) {
@VisibleForTesting
String getRingRangeString(List<RingRange> associatedTokens) {
if (associatedTokens != null && !associatedTokens.isEmpty()) {
StringBuilder sb = new StringBuilder();
for (RingRange ringRange : associatedTokens) {
sb.append(toRangeString(ringRange)).append(",");
}
// remove trailing comma
return sb.substring(0, sb.length() - 2);
return sb.substring(0, sb.length() - 1);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.datastax.mgmtapi.resources.v2.models.RepairParallelism;
import com.datastax.mgmtapi.resources.v2.models.RepairRequest;
import com.datastax.mgmtapi.resources.v2.models.RepairRequestResponse;
import com.datastax.mgmtapi.resources.v2.models.RingRange;
import com.datastax.oss.driver.api.core.cql.ResultSet;
import com.datastax.oss.driver.api.core.cql.Row;
import java.io.File;
Expand Down Expand Up @@ -112,4 +113,33 @@ public void testCancelAllRepairs() throws Exception {
assertEquals(202, resp.getStatus());
verify(mockCqlService).executePreparedStatement(any(), eq("CALL NodeOps.stopAllRepairs()"));
}

@Test
public void testGetRingRangeString() throws Exception {
CqlService mockCqlService = mock(CqlService.class);
ManagementApplication app =
new ManagementApplication(
null, null, new File("/tmp/cassandra.sock"), mockCqlService, null);
RepairResourcesV2 unit = new RepairResourcesV2(app);
List<RingRange> associatedTokens = new ArrayList<>();
// add some random token ranges
associatedTokens.add(new RingRange(-1506836194468667463l, -633835238802072494l));
associatedTokens.add(new RingRange(-2976249057732638160l, -1506836194468667463l));
associatedTokens.add(new RingRange(-6235755542119343496l, -2976249057732638160l));
associatedTokens.add(new RingRange(-633835238802072494l, 660806372122351317l));
associatedTokens.add(new RingRange(-7075332291273605506l, -6235755542119343496l));
associatedTokens.add(new RingRange(2303998418447223636l, 7727458699102386551l));
associatedTokens.add(new RingRange(660806372122351317l, 2303998418447223636l));
associatedTokens.add(new RingRange(7727458699102386551l, -7075332291273605506l));
assertEquals(
"-1506836194468667463:-633835238802072494,"
+ "-2976249057732638160:-1506836194468667463,"
+ "-6235755542119343496:-2976249057732638160,"
+ "-633835238802072494:660806372122351317,"
+ "-7075332291273605506:-6235755542119343496,"
+ "2303998418447223636:7727458699102386551,"
+ "660806372122351317:2303998418447223636,"
+ "7727458699102386551:-7075332291273605506",
unit.getRingRangeString(associatedTokens));
}
}

0 comments on commit 9e10a39

Please sign in to comment.