Skip to content

Commit

Permalink
Fixes ServiceStatusCmdTest and removed unused code (apache#5249)
Browse files Browse the repository at this point in the history
Removes unused method from ServiceStatusCmd and modified
ServiceStatusCmdTest to correctly get the number of resource groups for
compactors.

Adds dead compactor for testing ServiceStatusCmd output for compactor
details.
  • Loading branch information
ddanielr authored Jan 14, 2025
1 parent 4217116 commit 12530c7
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,30 +182,6 @@ private StatusSummary getStatusSummary(ServiceStatusReport.ReportKey displayName
return new StatusSummary(displayNames, byGroup.keySet(), byGroup, result.getErrorCount());
}

/**
* Read the node names from ZooKeeper. Exceptions are counted but ignored.
*
* @return Result with error count, Set of the node names.
*/
@VisibleForTesting
Result<Set<String>> readNodeNames(final ZooReader zooReader, final String path) {
Set<String> nodeNames = new TreeSet<>();
final AtomicInteger errorCount = new AtomicInteger(0);
try {
var children = zooReader.getChildren(path);
if (children != null) {
nodeNames.addAll(children);
}
} catch (KeeperException | InterruptedException ex) {
if (Thread.currentThread().isInterrupted()) {
Thread.currentThread().interrupt();
throw new IllegalStateException(ex);
}
errorCount.incrementAndGet();
}
return new Result<>(errorCount.get(), nodeNames);
}

/**
* Read the data from a ZooKeeper node, tracking if an error occurred. ZooKeeper's exceptions are
* counted but otherwise ignored.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import static java.nio.charset.StandardCharsets.UTF_8;
import static org.apache.accumulo.core.Constants.ZGC_LOCK;
import static org.easymock.EasyMock.anyObject;
import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.eq;
import static org.easymock.EasyMock.expect;
Expand Down Expand Up @@ -357,21 +358,56 @@ public void testScanServerHosts() throws Exception {
@Test
public void testCompactorStatus() throws Exception {
replay(zooReader);

UUID uuid1 = UUID.randomUUID();
String lock1Name = "zlock#" + uuid1 + "#0000000001";
UUID uuid2 = UUID.randomUUID();
String lock2Name = "zlock#" + uuid2 + "#0000000022";
UUID uuid3 = UUID.randomUUID();
String lock3Name = "zlock#" + uuid3 + "#0000000033";
UUID uuid4 = UUID.randomUUID();
String lock4Name = "zlock#" + uuid4 + "#0000000044";

String lock1data =
"{\"descriptors\":[{\"uuid\":\"6effb690-c29c-4e0b-92ff-f6b308385a42\",\"service\":\"COMPACTOR\",\"address\":\"hostA:8080\",\"group\":\"q1\"}]}";
String lock2data =
"{\"descriptors\":[{\"uuid\":\"6effb690-c29c-4e0b-92ff-f6b308385a42\",\"service\":\"COMPACTOR\",\"address\":\"hostC:8081\",\"group\":\"q1\"}]}";
String lock3data =
"{\"descriptors\":[{\"uuid\":\"6effb690-c29c-4e0b-92ff-f6b308385a42\",\"service\":\"COMPACTOR\",\"address\":\"hostB:9090\",\"group\":\"q2\"}]}";
String lock4data =
"{\"descriptors\":[{\"uuid\":\"6effb690-c29c-4e0b-92ff-f6b308385a42\",\"service\":\"COMPACTOR\",\"address\":\"hostD:9091\",\"group\":\"q2\"}]}";

String lockPath = zRoot + Constants.ZCOMPACTORS;
expect(zooCache.getChildren(lockPath)).andReturn(List.of("q1", "q2"));
expect(zooCache.getChildren(lockPath)).andReturn(List.of("q1", "q2", "q3"));
expect(zooCache.getChildren(lockPath + "/q1")).andReturn(List.of("hostA:8080", "hostC:8081"));
expect(zooCache.getChildren(lockPath + "/q2")).andReturn(List.of("hostB:9090", "hostD:9091"));
expect(zooCache.getChildren(lockPath + "/q1/hostA:8080")).andReturn(List.of());
expect(zooCache.getChildren(lockPath + "/q1/hostC:8081")).andReturn(List.of());
expect(zooCache.getChildren(lockPath + "/q2/hostB:9090")).andReturn(List.of());
expect(zooCache.getChildren(lockPath + "/q2/hostD:9091")).andReturn(List.of());
// Create compactor group with dead compactor
expect(zooCache.getChildren(lockPath + "/q3")).andReturn(List.of("deadHost:8080"));

expect(zooCache.getChildren(lockPath + "/q1/hostA:8080")).andReturn(List.of(lock1Name));
expect(zooCache.get(eq(lockPath + "/q1/hostA:8080/" + lock1Name), anyObject(ZcStat.class)))
.andReturn(lock1data.getBytes(UTF_8));
expect(zooCache.getChildren(lockPath + "/q1/hostC:8081")).andReturn(List.of(lock2Name));
expect(zooCache.get(eq(lockPath + "/q1/hostC:8081/" + lock2Name), anyObject(ZcStat.class)))
.andReturn(lock2data.getBytes(UTF_8));
expect(zooCache.getChildren(lockPath + "/q2/hostB:9090")).andReturn(List.of(lock3Name));
expect(zooCache.get(eq(lockPath + "/q2/hostB:9090/" + lock3Name), anyObject(ZcStat.class)))
.andReturn(lock3data.getBytes(UTF_8));
expect(zooCache.getChildren(lockPath + "/q2/hostD:9091")).andReturn(List.of(lock4Name));
expect(zooCache.get(eq(lockPath + "/q2/hostD:9091/" + lock4Name), anyObject(ZcStat.class)))
.andReturn(lock4data.getBytes(UTF_8));
expect(zooCache.getChildren(lockPath + "/q3/deadHost:8080")).andReturn(List.of());

replay(zooCache);

ServiceStatusCmd cmd = new ServiceStatusCmd();
StatusSummary status = cmd.getCompactorStatus(context);

LOG.info("compactor group counts: {}", status);
assertEquals(0, status.getResourceGroups().size());
assertEquals(2, status.getResourceGroups().size());

LOG.info("Live compactor counts: {}", status.getServiceCount());
assertEquals(4, status.getServiceCount());
}

@Test
Expand Down

0 comments on commit 12530c7

Please sign in to comment.