diff --git a/management-api-server/src/main/java/com/datastax/mgmtapi/resources/v2/RepairResourcesV2.java b/management-api-server/src/main/java/com/datastax/mgmtapi/resources/v2/RepairResourcesV2.java index b05a40bc..ba29a9ad 100644 --- a/management-api-server/src/main/java/com/datastax/mgmtapi/resources/v2/RepairResourcesV2.java +++ b/management-api-server/src/main/java/com/datastax/mgmtapi/resources/v2/RepairResourcesV2.java @@ -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; @@ -123,11 +124,12 @@ private String getParallelismName(RepairParallelism parallelism) { return parallelism != null ? parallelism.getName() : null; } - private String getRingRangeString(List associatedTokens) { - if (associatedTokens != null && !associatedTokens.isEmpty()) { - return associatedTokens.stream().map(this::toRangeString).collect(Collectors.joining(",")); + @VisibleForTesting + String getRingRangeString(List 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) { diff --git a/management-api-server/src/test/java/com/datastax/mgmtapi/resources/v2/RepairResourcesV2Test.java b/management-api-server/src/test/java/com/datastax/mgmtapi/resources/v2/RepairResourcesV2Test.java index c0607fe2..0eb7353a 100644 --- a/management-api-server/src/test/java/com/datastax/mgmtapi/resources/v2/RepairResourcesV2Test.java +++ b/management-api-server/src/test/java/com/datastax/mgmtapi/resources/v2/RepairResourcesV2Test.java @@ -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 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)); + } }