use of javax.net.SocketFactory in project hadoop by apache.
the class NetUtils method getSocketFactory.
/**
* Get the socket factory for the given class according to its
* configuration parameter
* <tt>hadoop.rpc.socket.factory.class.<ClassName></tt>. When no
* such parameter exists then fall back on the default socket factory as
* configured by <tt>hadoop.rpc.socket.factory.class.default</tt>. If
* this default socket factory is not configured, then fall back on the JVM
* default socket factory.
*
* @param conf the configuration
* @param clazz the class (usually a {@link VersionedProtocol})
* @return a socket factory
*/
public static SocketFactory getSocketFactory(Configuration conf, Class<?> clazz) {
SocketFactory factory = null;
String propValue = conf.get("hadoop.rpc.socket.factory.class." + clazz.getSimpleName());
if ((propValue != null) && (propValue.length() > 0))
factory = getSocketFactoryFromProperty(conf, propValue);
if (factory == null)
factory = getDefaultSocketFactory(conf);
return factory;
}
use of javax.net.SocketFactory in project hadoop by apache.
the class TestIPC method assertRetriesOnSocketTimeouts.
private void assertRetriesOnSocketTimeouts(Configuration conf, int maxTimeoutRetries) throws IOException {
SocketFactory mockFactory = Mockito.mock(SocketFactory.class);
doThrow(new ConnectTimeoutException("fake")).when(mockFactory).createSocket();
Client client = new Client(LongWritable.class, conf, mockFactory);
InetSocketAddress address = new InetSocketAddress("127.0.0.1", 9090);
try {
call(client, RANDOM.nextLong(), address, conf);
fail("Not throwing the SocketTimeoutException");
} catch (SocketTimeoutException e) {
Mockito.verify(mockFactory, Mockito.times(maxTimeoutRetries)).createSocket();
}
client.stop();
}
use of javax.net.SocketFactory in project hadoop by apache.
the class TestSocketFactory method testSocketFactoryAsKeyInMap.
@Test
public void testSocketFactoryAsKeyInMap() {
Map<SocketFactory, Integer> dummyCache = new HashMap<SocketFactory, Integer>();
int toBeCached1 = 1;
int toBeCached2 = 2;
Configuration conf = new Configuration();
conf.set(CommonConfigurationKeys.HADOOP_RPC_SOCKET_FACTORY_CLASS_DEFAULT_KEY, "org.apache.hadoop.ipc.TestSocketFactory$DummySocketFactory");
final SocketFactory dummySocketFactory = NetUtils.getDefaultSocketFactory(conf);
dummyCache.put(dummySocketFactory, toBeCached1);
conf.set(CommonConfigurationKeys.HADOOP_RPC_SOCKET_FACTORY_CLASS_DEFAULT_KEY, "org.apache.hadoop.net.StandardSocketFactory");
final SocketFactory defaultSocketFactory = NetUtils.getDefaultSocketFactory(conf);
dummyCache.put(defaultSocketFactory, toBeCached2);
Assert.assertEquals("The cache contains two elements", 2, dummyCache.size());
Assert.assertEquals("Equals of both socket factory shouldn't be same", defaultSocketFactory.equals(dummySocketFactory), false);
assertSame(toBeCached2, dummyCache.remove(defaultSocketFactory));
dummyCache.put(defaultSocketFactory, toBeCached2);
assertSame(toBeCached1, dummyCache.remove(dummySocketFactory));
}
use of javax.net.SocketFactory in project hadoop by apache.
the class TestDataNodeTcpNoDelay method testTcpNoDelayEnabled.
@Test
public void testTcpNoDelayEnabled() throws Exception {
Configuration testConf = new Configuration(baseConf);
// here we do not have to config TCP_NDELAY settings, since they should be
// active by default
testConf.set(HADOOP_RPC_SOCKET_FACTORY_CLASS_DEFAULT_KEY, SocketFactoryWrapper.class.getName());
SocketFactory defaultFactory = NetUtils.getDefaultSocketFactory(testConf);
LOG.info("Socket factory is " + defaultFactory.getClass().getName());
MiniDFSCluster dfsCluster = new MiniDFSCluster.Builder(testConf).numDataNodes(3).build();
dfsCluster.waitActive();
DistributedFileSystem dfs = dfsCluster.getFileSystem();
try {
createData(dfs);
transferBlock(dfs);
// check that TCP_NODELAY has been set on all sockets
assertTrue(SocketFactoryWrapper.wasTcpNoDelayActive());
} finally {
SocketFactoryWrapper.reset();
dfsCluster.shutdown();
}
}
use of javax.net.SocketFactory in project hadoop by apache.
the class TestDataNodeTcpNoDelay method testTcpNoDelayDisabled.
@Test
public void testTcpNoDelayDisabled() throws Exception {
Configuration testConf = new Configuration(baseConf);
// disable TCP_NODELAY in settings
setTcpNoDelay(testConf, false);
testConf.set(HADOOP_RPC_SOCKET_FACTORY_CLASS_DEFAULT_KEY, SocketFactoryWrapper.class.getName());
SocketFactory defaultFactory = NetUtils.getDefaultSocketFactory(testConf);
LOG.info("Socket factory is " + defaultFactory.getClass().getName());
MiniDFSCluster dfsCluster = new MiniDFSCluster.Builder(testConf).numDataNodes(3).build();
dfsCluster.waitActive();
DistributedFileSystem dfs = dfsCluster.getFileSystem();
try {
createData(dfs);
transferBlock(dfs);
// we can only check that TCP_NODELAY was disabled on some sockets,
// since part of the client write path always enables TCP_NODELAY
// by necessity
assertFalse(SocketFactoryWrapper.wasTcpNoDelayActive());
} finally {
SocketFactoryWrapper.reset();
dfsCluster.shutdown();
}
}
Aggregations