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));