|
22 | 22 | import org.junit.Test; |
23 | 23 | import org.junit.jupiter.api.Assertions; |
24 | 24 |
|
| 25 | +import java.lang.reflect.Field; |
25 | 26 | import java.nio.file.Files; |
26 | 27 | import java.nio.file.Path; |
27 | 28 | import java.util.List; |
28 | 29 | import java.util.Map; |
29 | 30 |
|
30 | 31 | public class ConfigTest { |
| 32 | + private static final String[] EXTERNAL_SCAN_SCHEDULER_CONFIGS = { |
| 33 | + "external_scan_split_threads", "external_scan_metadata_threads", "external_scan_task_queue_capacity" |
| 34 | + }; |
| 35 | + |
31 | 36 | @BeforeClass |
32 | 37 | public static void setUp() throws Exception { |
33 | 38 | Config config = new Config(); |
@@ -153,6 +158,64 @@ public void testOptionsConfigIsValidatedInCustomStartupFile() throws Exception { |
153 | 158 | } |
154 | 159 | } |
155 | 160 |
|
| 161 | + @Test |
| 162 | + public void testExternalScanSchedulerRejectsNonPositiveStartupValues() throws Exception { |
| 163 | + assertExternalScanSchedulerRejectsNonPositiveValues(false); |
| 164 | + } |
| 165 | + |
| 166 | + @Test |
| 167 | + public void testExternalScanSchedulerRejectsNonPositiveCustomStartupValues() throws Exception { |
| 168 | + assertExternalScanSchedulerRejectsNonPositiveValues(true); |
| 169 | + } |
| 170 | + |
| 171 | + private void assertExternalScanSchedulerRejectsNonPositiveValues(boolean custom) throws Exception { |
| 172 | + Config config = new Config(); |
| 173 | + config.init(configFile("").toString()); |
| 174 | + for (String name : EXTERNAL_SCAN_SCHEDULER_CONFIGS) { |
| 175 | + Field field = Config.class.getField(name); |
| 176 | + int original = field.getInt(null); |
| 177 | + try { |
| 178 | + for (String value : new String[] {"0", "-1"}) { |
| 179 | + Path invalid = configFile(name + "=" + value + "\n"); |
| 180 | + IllegalArgumentException error = Assertions.assertThrows(IllegalArgumentException.class, () -> { |
| 181 | + if (custom) { |
| 182 | + config.initCustom(invalid.toString()); |
| 183 | + } else { |
| 184 | + config.init(invalid.toString()); |
| 185 | + } |
| 186 | + }); |
| 187 | + Assertions.assertTrue(error.getMessage().contains(name)); |
| 188 | + Assertions.assertInstanceOf(ConfigException.class, error.getCause()); |
| 189 | + Assertions.assertTrue(error.getCause().getMessage().contains("must be greater than 0")); |
| 190 | + Assertions.assertEquals(original, field.getInt(null)); |
| 191 | + } |
| 192 | + } finally { |
| 193 | + field.setInt(null, original); |
| 194 | + } |
| 195 | + } |
| 196 | + } |
| 197 | + |
| 198 | + @Test |
| 199 | + public void testExternalScanSchedulerAcceptsPositiveStartupValuesAndStaysImmutable() throws Exception { |
| 200 | + Config config = new Config(); |
| 201 | + for (String name : EXTERNAL_SCAN_SCHEDULER_CONFIGS) { |
| 202 | + Field field = Config.class.getField(name); |
| 203 | + int original = field.getInt(null); |
| 204 | + try { |
| 205 | + config.init(configFile(name + "=1\n").toString()); |
| 206 | + Assertions.assertEquals(1, field.getInt(null)); |
| 207 | + config.initCustom(configFile(name + "= 128 \n").toString()); |
| 208 | + Assertions.assertEquals(128, field.getInt(null)); |
| 209 | + config.init(configFile(name + "=\n").toString()); |
| 210 | + Assertions.assertEquals(128, field.getInt(null)); |
| 211 | + Assertions.assertThrows(ConfigException.class, () -> ConfigBase.setMutableConfig(name, "8")); |
| 212 | + Assertions.assertEquals(128, field.getInt(null)); |
| 213 | + } finally { |
| 214 | + field.setInt(null, original); |
| 215 | + } |
| 216 | + } |
| 217 | + } |
| 218 | + |
156 | 219 | private static Path configFile(String contents) throws Exception { |
157 | 220 | Path file = Files.createTempFile("fe_ut_options_", ".conf"); |
158 | 221 | file.toFile().deleteOnExit(); |
|
0 commit comments