Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.apache.hadoop.ozone.container.common.volume;

import com.google.common.annotations.VisibleForTesting;
import org.apache.hadoop.hdds.conf.ConfigurationException;
import org.apache.hadoop.hdds.conf.ConfigurationSource;
import org.apache.hadoop.hdds.conf.StorageSize;
import org.apache.hadoop.hdds.conf.StorageUnit;
Expand Down Expand Up @@ -222,7 +223,7 @@ private static long getReserved(ConfigurationSource conf, String rootDir,
if (words.length < 2) {
LOG.error("Reserved space should be configured in a pair, but current value is {}",
reserve);
continue;
throw new ConfigurationException("Reserved space should be configured in a pair");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's mention the name of the property and what current value is

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

}

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import org.apache.hadoop.conf.StorageUnit;
import org.apache.hadoop.hdds.HddsConfigKeys;
import org.apache.hadoop.hdds.conf.ConfigurationException;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.hdds.fs.MockSpaceUsageCheckFactory;
import org.apache.hadoop.hdds.scm.ScmConfigKeys;
Expand All @@ -36,6 +37,7 @@
import static org.apache.hadoop.hdds.HddsConfigKeys.HDDS_DATANODE_VOLUME_MIN_FREE_SPACE_PERCENT;
import static org.apache.hadoop.hdds.scm.ScmConfigKeys.HDDS_DATANODE_DIR_DU_RESERVED_PERCENT;
import static org.apache.hadoop.hdds.scm.ScmConfigKeys.HDDS_DATANODE_DIR_DU_RESERVED_PERCENT_DEFAULT;
import static org.apache.ozone.test.GenericTestUtils.assertThrows;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;

Expand Down Expand Up @@ -164,6 +166,15 @@ public void testInvalidConfig() throws Exception {
long reservedFromVolume2 = hddsVolume2.getVolumeInfo().get()
.getReservedInBytes();
assertEquals(getExpectedDefaultReserved(hddsVolume2), reservedFromVolume2);

OzoneConfiguration conf3 = new OzoneConfiguration();

conf3.set(ScmConfigKeys.HDDS_DATANODE_DIR_DU_RESERVED, "15GB");
Copy link
Contributor

@myskov myskov Oct 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be either a separate test case or a parameterized test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed


assertThrows(ConfigurationException.class, () -> {
HddsVolume hddsVolume3 = volumeBuilder.conf(conf3).build();
return null;
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assertThrows(ConfigurationException.class, () -> volumeBuilder.conf(conf).build());

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and let's also check exception message

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Contributor

@myskov myskov Oct 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be written like this:
assertThrows(ConfigurationException.class, () -> volumeBuilder.conf(conf).build());

}

@Test
Expand Down