steveloughran commented on code in PR #8196: URL: https://github.com/apache/hadoop/pull/8196#discussion_r2714454516
########## hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/diskbalancer/planner/TestNodePlan.java: ########## @@ -0,0 +1,170 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.apache.hadoop.hdfs.server.diskbalancer.planner; + +import com.fasterxml.jackson.annotation.JsonProperty; +import org.apache.hadoop.hdfs.server.diskbalancer.datamodel.DiskBalancerVolume; +import org.junit.jupiter.api.Test; +import sample.SampleStep; + +import java.io.IOException; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; + +public class TestNodePlan { + + @Test + public void testNodePlan() throws IOException { + NodePlan nodePlan = new NodePlan("datanode1234", 1234); + MoveStep moveStep = new MoveStep(); + moveStep.setBandwidth(12345); + moveStep.setBytesToMove(98765); + moveStep.setIdealStorage(1.234); + moveStep.setMaxDiskErrors(4567); + moveStep.setVolumeSetID("id1234"); + nodePlan.addStep(moveStep); + String json = nodePlan.toJson(); + assertNotNull(NodePlan.parseJson(json)); + } + + @Test + public void testNodePlanWithDisallowedStep() throws IOException { + NodePlan nodePlan = new NodePlan("datanode1234", 1234); + Step sampleStep = new SampleStep(); + sampleStep.setBandwidth(12345); + sampleStep.setMaxDiskErrors(4567); + nodePlan.addStep(sampleStep); + String json = nodePlan.toJson(); + IOException ex = assertThrows(IOException.class, () -> NodePlan.parseJson(json)); Review Comment: I prefer using our intercept, ``` intercept(IOException.class, "Invalid @class value in NodePlan JSON: sample.SampleStep", () -> NodePlan.parseJson(json)); ``` one key diff is that if the exception isn't raised, the assertion failure includes the string value of the lambda expression output, here what nodeplan is created. Which lines you up for actually debugging failures. ########## hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/diskbalancer/planner/TestNodePlan.java: ########## @@ -0,0 +1,170 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.apache.hadoop.hdfs.server.diskbalancer.planner; + +import com.fasterxml.jackson.annotation.JsonProperty; Review Comment: nit: import oerdering ########## hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/diskbalancer/planner/TestNodePlan.java: ########## @@ -0,0 +1,170 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.apache.hadoop.hdfs.server.diskbalancer.planner; + +import com.fasterxml.jackson.annotation.JsonProperty; +import org.apache.hadoop.hdfs.server.diskbalancer.datamodel.DiskBalancerVolume; +import org.junit.jupiter.api.Test; +import sample.SampleStep; + +import java.io.IOException; + +import static org.junit.jupiter.api.Assertions.assertEquals; Review Comment: could you use assertJ assertions? makes it fairly trivial to backport to branch-3.4 just by changing the @Test import. Otherwise, we'll need to write the assertj asserts there anyway... ########## hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/diskbalancer/planner/TestNodePlan.java: ########## @@ -0,0 +1,170 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.apache.hadoop.hdfs.server.diskbalancer.planner; + +import com.fasterxml.jackson.annotation.JsonProperty; +import org.apache.hadoop.hdfs.server.diskbalancer.datamodel.DiskBalancerVolume; +import org.junit.jupiter.api.Test; +import sample.SampleStep; + +import java.io.IOException; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; + +public class TestNodePlan { + + @Test + public void testNodePlan() throws IOException { + NodePlan nodePlan = new NodePlan("datanode1234", 1234); + MoveStep moveStep = new MoveStep(); + moveStep.setBandwidth(12345); + moveStep.setBytesToMove(98765); + moveStep.setIdealStorage(1.234); + moveStep.setMaxDiskErrors(4567); + moveStep.setVolumeSetID("id1234"); + nodePlan.addStep(moveStep); + String json = nodePlan.toJson(); + assertNotNull(NodePlan.parseJson(json)); + } + + @Test + public void testNodePlanWithDisallowedStep() throws IOException { + NodePlan nodePlan = new NodePlan("datanode1234", 1234); + Step sampleStep = new SampleStep(); + sampleStep.setBandwidth(12345); + sampleStep.setMaxDiskErrors(4567); + nodePlan.addStep(sampleStep); + String json = nodePlan.toJson(); + IOException ex = assertThrows(IOException.class, () -> NodePlan.parseJson(json)); + assertEquals("Invalid @class value in NodePlan JSON: sample.SampleStep", ex.getMessage()); + } + + @Test + public void testNodePlanWithSecondStepDisallowed() throws IOException { + NodePlan nodePlan = new NodePlan("datanode1234", 1234); + MoveStep moveStep = new MoveStep(); + moveStep.setBandwidth(12345); + moveStep.setBytesToMove(98765); + moveStep.setIdealStorage(1.234); + moveStep.setMaxDiskErrors(4567); + moveStep.setVolumeSetID("id1234"); + nodePlan.addStep(moveStep); + Step sampleStep = new SampleStep(); + sampleStep.setBandwidth(12345); + sampleStep.setMaxDiskErrors(4567); + nodePlan.addStep(sampleStep); + String json = nodePlan.toJson(); + IOException ex = assertThrows(IOException.class, () -> NodePlan.parseJson(json)); Review Comment: again, intercept() ########## hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/diskbalancer/planner/TestNodePlan.java: ########## @@ -0,0 +1,170 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.apache.hadoop.hdfs.server.diskbalancer.planner; + +import com.fasterxml.jackson.annotation.JsonProperty; +import org.apache.hadoop.hdfs.server.diskbalancer.datamodel.DiskBalancerVolume; +import org.junit.jupiter.api.Test; +import sample.SampleStep; + +import java.io.IOException; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; + +public class TestNodePlan { + + @Test + public void testNodePlan() throws IOException { + NodePlan nodePlan = new NodePlan("datanode1234", 1234); + MoveStep moveStep = new MoveStep(); + moveStep.setBandwidth(12345); + moveStep.setBytesToMove(98765); + moveStep.setIdealStorage(1.234); + moveStep.setMaxDiskErrors(4567); + moveStep.setVolumeSetID("id1234"); + nodePlan.addStep(moveStep); + String json = nodePlan.toJson(); + assertNotNull(NodePlan.parseJson(json)); + } + + @Test + public void testNodePlanWithDisallowedStep() throws IOException { + NodePlan nodePlan = new NodePlan("datanode1234", 1234); + Step sampleStep = new SampleStep(); + sampleStep.setBandwidth(12345); + sampleStep.setMaxDiskErrors(4567); + nodePlan.addStep(sampleStep); + String json = nodePlan.toJson(); + IOException ex = assertThrows(IOException.class, () -> NodePlan.parseJson(json)); + assertEquals("Invalid @class value in NodePlan JSON: sample.SampleStep", ex.getMessage()); + } + + @Test + public void testNodePlanWithSecondStepDisallowed() throws IOException { + NodePlan nodePlan = new NodePlan("datanode1234", 1234); + MoveStep moveStep = new MoveStep(); + moveStep.setBandwidth(12345); + moveStep.setBytesToMove(98765); + moveStep.setIdealStorage(1.234); + moveStep.setMaxDiskErrors(4567); + moveStep.setVolumeSetID("id1234"); + nodePlan.addStep(moveStep); + Step sampleStep = new SampleStep(); + sampleStep.setBandwidth(12345); + sampleStep.setMaxDiskErrors(4567); + nodePlan.addStep(sampleStep); + String json = nodePlan.toJson(); + IOException ex = assertThrows(IOException.class, () -> NodePlan.parseJson(json)); + assertEquals("Invalid @class value in NodePlan JSON: sample.SampleStep", ex.getMessage()); + } + + @Test + public void testNodePlanWithNestedDisallowedStep() throws IOException { + NodePlan nodePlan = new NodePlan("datanode1234", 1234); + NodePlan nodePlan2 = new NodePlan("datanode9876", 9876); + SampleStep sampleStep = new SampleStep(); + sampleStep.setBandwidth(12345); + sampleStep.setMaxDiskErrors(4567); + nodePlan2.addStep(sampleStep); + NestedStep nestedStep = new NestedStep(nodePlan2); + nestedStep.setBandwidth(1234); + nestedStep.setMaxDiskErrors(456); + nodePlan.addStep(nestedStep); + String json = nodePlan.toJson(); + IOException ex = assertThrows(IOException.class, () -> NodePlan.parseJson(json)); Review Comment: intercept() -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
