diff --git a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/shell/TestReconfigShell.java b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/shell/TestReconfigShell.java index de55a9e2233d..e66742a2a75f 100644 --- a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/shell/TestReconfigShell.java +++ b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/shell/TestReconfigShell.java @@ -26,8 +26,8 @@ import java.util.Collection; import java.util.List; import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; import org.apache.hadoop.conf.ReconfigurationException; -import org.apache.hadoop.hdds.conf.OzoneConfiguration; import org.apache.hadoop.hdds.conf.ReconfigurableBase; import org.apache.hadoop.hdds.conf.ReconfigurationHandler; import org.apache.hadoop.hdds.protocol.DatanodeDetails; @@ -54,7 +54,6 @@ public abstract class TestReconfigShell implements NonHATests.TestCase { private OzoneAdmin ozoneAdmin; - private OzoneConfiguration conf; private ReconfigurationHandler reconfigurationHandler; private GenericTestUtils.PrintStreamCapturer out; private GenericTestUtils.PrintStreamCapturer err; @@ -64,7 +63,6 @@ void capture() { out = GenericTestUtils.captureOut(); err = GenericTestUtils.captureErr(); ozoneAdmin = new OzoneAdmin(); - conf = new OzoneConfiguration(); reconfigurationHandler = cluster().getOzoneManager().getReconfigurationHandler(); } @@ -89,10 +87,12 @@ void testOzoneManagerGetReconfigurationProperties() { } @Test - void testDirectoryDeletingServiceIntervalReconfiguration() throws ReconfigurationException { + void testDirectoryDeletingServiceIntervalReconfiguration() throws ReconfigurationException, + InterruptedException, TimeoutException { OzoneManager om = cluster().getOzoneManager(); InetSocketAddress socket = om.getOmRpcServerAddr(); - LogCapturer logCapturer = LogCapturer.captureLogs(DirectoryDeletingService.class); + LogCapturer dirDeletingServiceLog = LogCapturer.captureLogs(DirectoryDeletingService.class); + LogCapturer reconfigHandlerLog = LogCapturer.captureLogs(ReconfigurationHandler.class); String initialInterval = "1m"; String intervalFromXML = "2m"; //config value set in ozone-site.xml @@ -103,18 +103,20 @@ void testDirectoryDeletingServiceIntervalReconfiguration() throws Reconfiguratio //Start the reconfiguration task executeAndAssertStart("OM", socket); - //If config value is set in ozone-site.xml then it is picked up during reconfiguration - assertThat(conf.get(OZONE_DIR_DELETING_SERVICE_INTERVAL)).isEqualTo(intervalFromXML); - - executeAndAssertStatus("OM", socket); - assertThat(reconfigurationHandler.getConf().get(OZONE_DIR_DELETING_SERVICE_INTERVAL)).isEqualTo(intervalFromXML); - assertThat(out.get()).contains( - String.format("SUCCESS: Changed property %s", OZONE_DIR_DELETING_SERVICE_INTERVAL) - ); - assertThat(logCapturer.getOutput()).contains( + GenericTestUtils.waitFor(() -> reconfigHandlerLog.getOutput().contains("Reconfiguration completed"), + 1000, 20000); + assertThat(dirDeletingServiceLog.getOutput()).contains( String.format("Updating and restarting DirectoryDeletingService with interval %d %s", - intervalFromXMLInSeconds, TimeUnit.SECONDS.name().toLowerCase()) - ); + intervalFromXMLInSeconds, TimeUnit.SECONDS.name().toLowerCase())); + assertThat(reconfigurationHandler.getConf().get(OZONE_DIR_DELETING_SERVICE_INTERVAL)).isEqualTo(intervalFromXML); + + String address = socket.getHostString() + ":" + socket.getPort(); + GenericTestUtils.waitFor(() -> { + ozoneAdmin.getCmd().execute("reconfig", "--service", "OM", "--address", address, "status"); + String output = out.get(); + return output.contains("finished") && + output.contains(String.format("SUCCESS: Changed property %s", OZONE_DIR_DELETING_SERVICE_INTERVAL)); + }, 1000, 20000); } @Test @@ -177,10 +179,4 @@ private void executeAndAssertStart(String service, InetSocketAddress socket) { assertThat(out.get()).contains(service + ": Started reconfiguration task on node [" + address + "]"); } - private void executeAndAssertStatus(String service, InetSocketAddress socket) { - String address = socket.getHostString() + ":" + socket.getPort(); - ozoneAdmin.getCmd().execute("reconfig", "--service", service, "--address", address, "status"); - assertThat(out.get()).contains(service + ": Reconfiguring status for node [" + address + "]: started"); - } - }