Skip to content

Commit

Permalink
Re-instate original unit tests for getRingRangeString() method.
Browse files Browse the repository at this point in the history
  • Loading branch information
Miles-Garnsey committed Sep 25, 2023
1 parent b2bccfb commit 70692f3
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 4 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 @@ -123,11 +124,12 @@ private String getParallelismName(RepairParallelism parallelism) {
return parallelism != null ? parallelism.getName() : null;
}

private String getRingRangeString(List<RingRange> associatedTokens) {
if (associatedTokens != null && !associatedTokens.isEmpty()) {
return associatedTokens.stream().map(this::toRangeString).collect(Collectors.joining(","));
@VisibleForTesting
String getRingRangeString(List<RingRange> associatedTokens) {
if (associatedTokens == null || associatedTokens.isEmpty()) {
return null;
}
return null;
return associatedTokens.stream().map(i -> toRangeString(i)).collect(Collectors.joining(","));
}

private String toRangeString(RingRange ringRange) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,55 @@ 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));
}

@Test
public void testGetRingRangeStringNull() 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);
// test a null ring range
assertEquals(null, unit.getRingRangeString(null));
}

@Test
public void testGetRingRangeStringEmpty() 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);
// test a empty ring range
assertEquals(null, unit.getRingRangeString(Collections.EMPTY_LIST));
}
}

0 comments on commit 70692f3

Please sign in to comment.