|
24 | 24 | import static java.util.concurrent.TimeUnit.SECONDS;
|
25 | 25 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
26 | 26 | import static org.junit.jupiter.api.Assertions.assertThrows;
|
| 27 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
27 | 28 |
|
| 29 | +import java.util.Set; |
28 | 30 | import java.util.function.Function;
|
29 | 31 | import java.util.stream.Stream;
|
30 | 32 |
|
@@ -132,4 +134,52 @@ public void testGetFractionFailureCase2() {
|
132 | 134 | public void testGetFractionFailureCase3() {
|
133 | 135 | assertThrows(IllegalArgumentException.class, () -> ConfigurationTypeHelper.getFraction(".%"));
|
134 | 136 | }
|
| 137 | + |
| 138 | + @Test |
| 139 | + public void testGetVolumeUris() { |
| 140 | + // test property not set |
| 141 | + assertEquals(Set.of(), ConfigurationTypeHelper.getVolumeUris("")); |
| 142 | + |
| 143 | + // test blank cases |
| 144 | + assertThrows(NullPointerException.class, () -> ConfigurationTypeHelper.getVolumeUris(null)); |
| 145 | + for (String s : Set.of(" ", ",", ",,,", " ,,,", ",,, ", ", ,,")) { |
| 146 | + var e = assertThrows(IllegalArgumentException.class, |
| 147 | + () -> ConfigurationTypeHelper.getVolumeUris(s)); |
| 148 | + assertEquals("property contains only blank volumes", e.getMessage()); |
| 149 | + } |
| 150 | + |
| 151 | + // test 1 volume |
| 152 | + for (String s : Set.of("hdfs:/volA", ",hdfs:/volA", "hdfs:/volA,")) { |
| 153 | + var uris = ConfigurationTypeHelper.getVolumeUris(s); |
| 154 | + assertEquals(1, uris.size()); |
| 155 | + assertTrue(uris.contains("hdfs:/volA")); |
| 156 | + } |
| 157 | + |
| 158 | + // test more than 1 volume |
| 159 | + for (String s : Set.of("hdfs:/volA,file:/volB", ",hdfs:/volA,file:/volB", |
| 160 | + "hdfs:/volA,,file:/volB", "hdfs:/volA,file:/volB, ,")) { |
| 161 | + var uris = ConfigurationTypeHelper.getVolumeUris(s); |
| 162 | + assertEquals(2, uris.size()); |
| 163 | + assertTrue(uris.contains("hdfs:/volA")); |
| 164 | + assertTrue(uris.contains("file:/volB")); |
| 165 | + } |
| 166 | + |
| 167 | + // test invalid URI |
| 168 | + for (String s : Set.of("hdfs:/volA,hdfs:/volB,volA", ",volA,hdfs:/volA,hdfs:/volB", |
| 169 | + "hdfs:/volA,,volA,hdfs:/volB", "hdfs:/volA,volA,hdfs:/volB, ,")) { |
| 170 | + var iae = assertThrows(IllegalArgumentException.class, |
| 171 | + () -> ConfigurationTypeHelper.getVolumeUris(s)); |
| 172 | + assertEquals("'volA' is not a fully qualified URI", iae.getMessage()); |
| 173 | + } |
| 174 | + |
| 175 | + // test duplicates |
| 176 | + var iae = assertThrows(IllegalArgumentException.class, |
| 177 | + () -> ConfigurationTypeHelper.getVolumeUris("hdfs:/volA,hdfs:/volB,hdfs:/volA")); |
| 178 | + assertEquals("property contains duplicate volumes", iae.getMessage()); |
| 179 | + |
| 180 | + // test syntax error in URI |
| 181 | + iae = assertThrows(IllegalArgumentException.class, |
| 182 | + () -> ConfigurationTypeHelper.getVolumeUris("hdfs:/volA,hdfs :/::/volB")); |
| 183 | + assertEquals("volume contains 'hdfs :/::/volB' which has a syntax error", iae.getMessage()); |
| 184 | + } |
135 | 185 | }
|
0 commit comments