|
@@ -28,14 +28,19 @@ import org.apache.hadoop.hdfs.server.aliasmap.InMemoryAliasMap;
|
|
|
import org.apache.hadoop.hdfs.server.aliasmap.InMemoryLevelDBAliasMapServer;
|
|
|
import org.apache.hadoop.hdfs.server.common.blockaliasmap.BlockAliasMap;
|
|
|
import org.apache.hadoop.hdfs.server.common.FileRegion;
|
|
|
+import org.apache.hadoop.test.LambdaTestUtils;
|
|
|
import org.junit.After;
|
|
|
import org.junit.Before;
|
|
|
+import org.junit.Rule;
|
|
|
import org.junit.Test;
|
|
|
+import org.junit.rules.ExpectedException;
|
|
|
|
|
|
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_SERVICE_RPC_BIND_HOST_KEY;
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
|
import static org.junit.Assert.assertArrayEquals;
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
+import static org.junit.Assert.assertTrue;
|
|
|
+import static org.junit.Assert.fail;
|
|
|
|
|
|
import java.io.File;
|
|
|
import java.io.IOException;
|
|
@@ -59,6 +64,9 @@ public class TestInMemoryLevelDBAliasMapClient {
|
|
|
private Configuration conf;
|
|
|
private final static String BPID = "BPID-0";
|
|
|
|
|
|
+ @Rule
|
|
|
+ public final ExpectedException exception = ExpectedException.none();
|
|
|
+
|
|
|
@Before
|
|
|
public void setUp() throws IOException {
|
|
|
conf = new Configuration();
|
|
@@ -348,4 +356,35 @@ public class TestInMemoryLevelDBAliasMapClient {
|
|
|
conf.set(DFS_NAMENODE_SERVICE_RPC_BIND_HOST_KEY, "0.0.0.0");
|
|
|
writeRead();
|
|
|
}
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testNonExistentFile() throws Exception {
|
|
|
+ // delete alias map location
|
|
|
+ FileUtils.deleteDirectory(tempDir);
|
|
|
+ // expect a RuntimeException when the aliasmap is started.
|
|
|
+ exception.expect(RuntimeException.class);
|
|
|
+ levelDBAliasMapServer.setConf(conf);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testNonExistentBlock() throws Exception {
|
|
|
+ inMemoryLevelDBAliasMapClient.setConf(conf);
|
|
|
+ levelDBAliasMapServer.setConf(conf);
|
|
|
+ levelDBAliasMapServer.start();
|
|
|
+ Block block1 = new Block(100, 43, 44);
|
|
|
+ ProvidedStorageLocation providedStorageLocation1 = null;
|
|
|
+ BlockAliasMap.Writer<FileRegion> writer1 =
|
|
|
+ inMemoryLevelDBAliasMapClient.getWriter(null, BPID);
|
|
|
+ try {
|
|
|
+ writer1.store(new FileRegion(block1, providedStorageLocation1));
|
|
|
+ fail("Should fail on writing a region with null ProvidedLocation");
|
|
|
+ } catch (IOException | IllegalArgumentException e) {
|
|
|
+ assertTrue(e.getMessage().contains("not be null"));
|
|
|
+ }
|
|
|
+
|
|
|
+ BlockAliasMap.Reader<FileRegion> reader =
|
|
|
+ inMemoryLevelDBAliasMapClient.getReader(null, BPID);
|
|
|
+ LambdaTestUtils.assertOptionalUnset("Expected empty BlockAlias",
|
|
|
+ reader.resolve(block1));
|
|
|
+ }
|
|
|
}
|