Source:
public void testDefaultFPPGetOneProxy() throws Exception { class TestProxy extends Proxy implements Closeable { protected TestProxy(InvocationHandler h) { super(h); } @Override public void close() throws IOException { } } Proxy mockProxy1 = new TestProxy((proxy, method, args) -> null); Class protocol = ApplicationClientProtocol.class; RMProxy mockRMProxy = mock(RMProxy.class); DefaultNoHARMFailoverProxyProvider<RMProxy> fpp = new DefaultNoHARMFailoverProxyProvider<RMProxy>(); Random rand = new Random(); int port1 = rand.nextInt(65535); InetSocketAddress mockAdd1 = new InetSocketAddress(port1); when(mockRMProxy.getRMAddress(any(YarnConfiguration.class), any(Class.class))).thenReturn(mockAdd1); when(mockRMProxy.getProxy(any(YarnConfiguration.class), any(Class.class), eq(mockAdd1))).thenReturn(mockProxy1); fpp.init(conf, mockRMProxy, protocol); FailoverProxyProvider.ProxyInfo<RMProxy> actualProxy1 = fpp.getProxy(); Assert.assertEquals( "AutoFefreshRMFailoverProxyProvider doesn't generate " + "expected proxy", mockProxy1, actualProxy1.proxy); actualProxy1 = fpp.getProxy(); Assert.assertEquals( "AutoFefreshRMFailoverProxyProvider doesn't generate " + "expected proxy", mockProxy1, actualProxy1.proxy); actualProxy1 = fpp.getProxy(); Assert.assertEquals( "AutoFefreshRMFailoverProxyProvider doesn't generate " + "expected proxy", mockProxy1, actualProxy1.proxy); verify(mockRMProxy, times(1)) .getProxy(any(YarnConfiguration.class), any(Class.class), eq(mockAdd1)); fpp.performFailover(actualProxy1.proxy); FailoverProxyProvider.ProxyInfo<RMProxy> actualProxy2 = fpp.getProxy(); Assert.assertEquals("AutoFefreshRMFailoverProxyProvider " + "doesn't generate expected proxy after failover", mockProxy1, actualProxy2.proxy); verify(mockRMProxy, times(1)) .getProxy(any(YarnConfiguration.class), any(Class.class), eq(mockAdd1)); }

Target:
public void testDefaultFPPGetOneProxy() throws Exception { Proxy mockProxy1 = new Proxy((proxy, method, args) -> null); Class protocol = ApplicationClientProtocol.class; RMProxy mockRMProxy = mock(RMProxy.class); DefaultNoHARMFailoverProxyProvider <RMProxy> fpp = new DefaultNoHARMFailoverProxyProvider<RMProxy>(); InetSocketAddress mockAdd1 = new InetSocketAddress(RM1_PORT); when(mockRMProxy.getRMAddress(any(YarnConfiguration.class), any(Class.class))).thenReturn(mockAdd1); when(mockRMProxy.getProxy(any(YarnConfiguration.class), any(Class.class), eq(mockAdd1))).thenReturn(mockProxy1); fpp.init(conf, mockRMProxy, protocol); FailoverProxyProvider.ProxyInfo<RMProxy> actualProxy1 = fpp.getProxy(); assertEquals( "AutoRefreshRMFailoverProxyProvider doesn't generate " + "expected proxy", mockProxy1, actualProxy1.proxy); actualProxy1 = fpp.getProxy(); assertEquals( "AutoRefreshRMFailoverProxyProvider doesn't generate " + "expected proxy", mockProxy1, actualProxy1.proxy); actualProxy1 = fpp.getProxy(); assertEquals( "AutoRefreshRMFailoverProxyProvider doesn't generate " + "expected proxy", mockProxy1, actualProxy1.proxy); verify(mockRMProxy, times(1)) .getProxy(any(YarnConfiguration.class), any(Class.class), eq(mockAdd1)); fpp.performFailover(actualProxy1.proxy); FailoverProxyProvider.ProxyInfo<RMProxy> actualProxy2 = fpp.getProxy(); assertEquals("AutoRefreshRMFailoverProxyProvider " + "doesn't generate expected proxy after failover", mockProxy1, actualProxy2.proxy); verify(mockRMProxy, times(1)) .getProxy(any(YarnConfiguration.class), any(Class.class), eq(mockAdd1)); }