|
@@ -28,6 +28,7 @@ import static org.hamcrest.CoreMatchers.equalTo;
|
|
|
|
|
|
import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
+import java.net.InetSocketAddress;
|
|
|
import java.nio.channels.ClosedByInterruptException;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.HashMap;
|
|
@@ -53,6 +54,7 @@ import org.apache.hadoop.hdfs.protocol.DatanodeInfo.DatanodeInfoBuilder;
|
|
|
import org.apache.hadoop.hdfs.protocol.LocatedBlock;
|
|
|
import org.apache.hadoop.hdfs.shortcircuit.DfsClientShmManager.PerDatanodeVisitorInfo;
|
|
|
import org.apache.hadoop.hdfs.shortcircuit.DfsClientShmManager.Visitor;
|
|
|
+import org.apache.hadoop.hdfs.shortcircuit.DomainSocketFactory;
|
|
|
import org.apache.hadoop.hdfs.shortcircuit.ShortCircuitCache;
|
|
|
import org.apache.hadoop.hdfs.shortcircuit.ShortCircuitReplicaInfo;
|
|
|
import org.apache.hadoop.io.IOUtils;
|
|
@@ -68,6 +70,7 @@ import org.junit.Rule;
|
|
|
import org.junit.Test;
|
|
|
|
|
|
import com.google.common.util.concurrent.Uninterruptibles;
|
|
|
+import org.junit.rules.ExpectedException;
|
|
|
import org.junit.rules.Timeout;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -79,6 +82,9 @@ public class TestBlockReaderFactory {
|
|
|
@Rule
|
|
|
public final Timeout globalTimeout = new Timeout(180000);
|
|
|
|
|
|
+ @Rule
|
|
|
+ public ExpectedException thrown = ExpectedException.none();
|
|
|
+
|
|
|
@Before
|
|
|
public void init() {
|
|
|
DomainSocket.disableBindPathValidation();
|
|
@@ -144,6 +150,33 @@ public class TestBlockReaderFactory {
|
|
|
sockDir.close();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Test the case where address passed to DomainSocketFactory#getPathInfo is
|
|
|
+ * unresolved. In such a case an exception should be thrown.
|
|
|
+ */
|
|
|
+ @Test(timeout=60000)
|
|
|
+ public void testGetPathInfoWithUnresolvedHost() throws Exception {
|
|
|
+ TemporarySocketDirectory sockDir = new TemporarySocketDirectory();
|
|
|
+
|
|
|
+ Configuration conf =
|
|
|
+ createShortCircuitConf("testGetPathInfoWithUnresolvedHost", sockDir);
|
|
|
+ conf.set(DFS_CLIENT_CONTEXT,
|
|
|
+ "testGetPathInfoWithUnresolvedHost_Context");
|
|
|
+ conf.setBoolean(DFS_CLIENT_DOMAIN_SOCKET_DATA_TRAFFIC, true);
|
|
|
+
|
|
|
+ DfsClientConf.ShortCircuitConf shortCircuitConf =
|
|
|
+ new DfsClientConf.ShortCircuitConf(conf);
|
|
|
+ DomainSocketFactory domainSocketFactory =
|
|
|
+ new DomainSocketFactory(shortCircuitConf);
|
|
|
+ InetSocketAddress targetAddr =
|
|
|
+ InetSocketAddress.createUnresolved("random", 32456);
|
|
|
+
|
|
|
+ thrown.expect(IOException.class);
|
|
|
+ thrown.expectMessage("Unresolved host: " + targetAddr);
|
|
|
+ domainSocketFactory.getPathInfo(targetAddr, shortCircuitConf);
|
|
|
+ sockDir.close();
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Test the case where we have multiple threads waiting on the
|
|
|
* ShortCircuitCache delivering a certain ShortCircuitReplica.
|