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 @@ -220,9 +221,8 @@ private static long getReserved(ConfigurationSource conf, String rootDir,
for (String reserve : reserveList) {
String[] words = reserve.split(":");
if (words.length < 2) {
LOG.error("Reserved space should be configured in a pair, but current value is {}",
reserve);
continue;
throw new ConfigurationException("hdds.datanode.dir.du.reserved - " +
"Reserved space should be configured in a pair, but current value is " + reserve);
}

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,8 @@
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.apache.ratis.util.Preconditions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;

Expand Down Expand Up @@ -166,6 +169,18 @@ public void testInvalidConfig() throws Exception {
assertEquals(getExpectedDefaultReserved(hddsVolume2), reservedFromVolume2);
}

@Test
public void testInvalidConfigThrowsException() {
OzoneConfiguration conf = new OzoneConfiguration();
conf.set(ScmConfigKeys.HDDS_DATANODE_DIR_DU_RESERVED, "15GB");

ConfigurationException exception = assertThrows(ConfigurationException.class, () -> {
volumeBuilder.conf(conf).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());

assertTrue(exception.getMessage().contains("Reserved space should be configured in a pair"));
}

@Test
public void testPathsCanonicalized() throws Exception {
OzoneConfiguration conf = new OzoneConfiguration();
Expand Down