use of org.apache.hadoop.hdds.scm.client.ScmClient in project ozone by apache.
the class TestInfoSubCommand method testReplicasIncludedInOutput.
@Test
public void testReplicasIncludedInOutput() throws Exception {
Mockito.when(scmClient.getContainerReplicas(anyLong())).thenReturn(getReplicas());
cmd = new InfoSubcommand();
CommandLine c = new CommandLine(cmd);
c.parseArgs("1");
cmd.execute(scmClient);
// Ensure we have a line for Replicas:
List<LoggingEvent> logs = appender.getLog();
List<LoggingEvent> replica = logs.stream().filter(m -> m.getRenderedMessage().matches("(?s)^Replicas:.*")).collect(Collectors.toList());
Assert.assertEquals(1, replica.size());
// Ensure each DN UUID is mentioned in the message:
for (DatanodeDetails dn : datanodes) {
Pattern pattern = Pattern.compile(".*" + dn.getUuid().toString() + ".*", Pattern.DOTALL);
Matcher matcher = pattern.matcher(replica.get(0).getRenderedMessage());
Assert.assertTrue(matcher.matches());
}
}
use of org.apache.hadoop.hdds.scm.client.ScmClient in project ozone by apache.
the class TestReportSubCommand method testCorrectValuesAppearInEmptyReport.
@Test
public void testCorrectValuesAppearInEmptyReport() throws IOException {
ScmClient scmClient = mock(ScmClient.class);
Mockito.when(scmClient.getReplicationManagerReport()).thenAnswer(invocation -> new ReplicationManagerReport());
cmd.execute(scmClient);
for (HddsProtos.LifeCycleState state : HddsProtos.LifeCycleState.values()) {
Pattern p = Pattern.compile("^" + state.toString() + ": 0$", Pattern.MULTILINE);
Matcher m = p.matcher(outContent.toString(DEFAULT_ENCODING));
assertTrue(m.find());
}
for (ReplicationManagerReport.HealthState state : ReplicationManagerReport.HealthState.values()) {
Pattern p = Pattern.compile("^" + state.toString() + ": 0$", Pattern.MULTILINE);
Matcher m = p.matcher(outContent.toString(DEFAULT_ENCODING));
assertTrue(m.find());
}
}
use of org.apache.hadoop.hdds.scm.client.ScmClient in project ozone by apache.
the class TestReportSubCommand method testValidJsonOutput.
@Test
public void testValidJsonOutput() throws IOException {
// More complete testing of the Report JSON output is in
// TestReplicationManagerReport.
ScmClient scmClient = mock(ScmClient.class);
Mockito.when(scmClient.getReplicationManagerReport()).thenAnswer(invocation -> new ReplicationManagerReport());
CommandLine c = new CommandLine(cmd);
c.parseArgs("--json");
cmd.execute(scmClient);
ObjectMapper mapper = new ObjectMapper();
JsonNode json = mapper.readTree(outContent.toString("UTF-8"));
assertNotNull(json.get("reportTimeStamp"));
assertNotNull(json.get("stats"));
assertNotNull(json.get("samples"));
}
use of org.apache.hadoop.hdds.scm.client.ScmClient in project ozone by apache.
the class TestReportSubCommand method testCorrectValuesAppearInReport.
@Test
public void testCorrectValuesAppearInReport() throws IOException {
ScmClient scmClient = mock(ScmClient.class);
Mockito.when(scmClient.getReplicationManagerReport()).thenAnswer(invocation -> createReport());
cmd.execute(scmClient);
int counter = SEED;
for (HddsProtos.LifeCycleState state : HddsProtos.LifeCycleState.values()) {
Pattern p = Pattern.compile("^" + state.toString() + ": " + counter + "$", Pattern.MULTILINE);
Matcher m = p.matcher(outContent.toString(DEFAULT_ENCODING));
assertTrue(m.find());
counter++;
}
counter = SEED;
for (ReplicationManagerReport.HealthState state : ReplicationManagerReport.HealthState.values()) {
Pattern p = Pattern.compile("^" + state.toString() + ": " + counter + "$", Pattern.MULTILINE);
Matcher m = p.matcher(outContent.toString(DEFAULT_ENCODING));
assertTrue(m.find());
// Check the correct samples are returned
p = Pattern.compile("^First 100 " + state + " containers:\n" + containerList(0, counter) + "$", Pattern.MULTILINE);
m = p.matcher(outContent.toString(DEFAULT_ENCODING));
assertTrue(m.find());
counter++;
}
}
use of org.apache.hadoop.hdds.scm.client.ScmClient in project ozone by apache.
the class TestContainerBalancerSubCommand method testContainerBalancerStatusSubcommandNotRunning.
@Test
public void testContainerBalancerStatusSubcommandNotRunning() throws IOException {
ScmClient scmClient = mock(ScmClient.class);
Mockito.when(scmClient.getContainerBalancerStatus()).thenAnswer(invocation -> false);
statusCmd.execute(scmClient);
Pattern p = Pattern.compile("^ContainerBalancer\\sis\\sNot\\sRunning.");
Matcher m = p.matcher(outContent.toString(DEFAULT_ENCODING));
assertTrue(m.find());
}
Aggregations