xinglin commented on code in PR #5700: URL: https://github.com/apache/hadoop/pull/5700#discussion_r1212424086
########## hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestObserverReadProxyProvider.java: ########## @@ -325,6 +357,94 @@ public void testObserverRetriableException() throws Exception { assertHandledBy(1); } + /** + * Happy case for GetHAServiceStateWithTimeout. + */ + @Test + public void testGetHAServiceStateWithTimeout() throws Exception { + setupProxyProvider(1); + final HAServiceState state = HAServiceState.STANDBY; + NNProxyInfo<ClientProtocol> dummyNNProxyInfo = + (NNProxyInfo<ClientProtocol>) mock(NNProxyInfo.class); + Future<HAServiceState> task = mock(Future.class); + when(task.get(anyLong(), any(TimeUnit.class))).thenReturn(state); + + HAServiceState state2 = + proxyProvider.getHAServiceStateWithTimeout(dummyNNProxyInfo, task); + assertEquals(state, state2); + verify(task).get(anyLong(), any(TimeUnit.class)); + verifyNoMoreInteractions(task); + verify(logger).debug(startsWith("HA State for")); + } + + /** + * Test TimeoutException for GetHAServiceStateWithTimeout. + */ + @Test + public void testTimeoutExceptionGetHAServiceStateWithTimeout() + throws Exception { + setupProxyProvider(1); + NNProxyInfo<ClientProtocol> dummyNNProxyInfo = + (NNProxyInfo<ClientProtocol>) Mockito.mock(NNProxyInfo.class); + Future<HAServiceState> task = mock(Future.class); + when(task.get(anyLong(), any(TimeUnit.class))).thenThrow( + new TimeoutException("Timeout")); + + HAServiceState state = + proxyProvider.getHAServiceStateWithTimeout(dummyNNProxyInfo, task); + assertNull(state); + verify(task).get(anyLong(), any(TimeUnit.class)); + verify(task).cancel(true); + verifyNoMoreInteractions(task); + verify(logger).debug(startsWith("Cancel NN probe task due to timeout for")); + } + + /** + * Test InterruptedException for GetHAServiceStateWithTimeout. + * Tests for the other two exceptions are the same and thus left out. + */ + @Test + public void testInterruptedExceptionGetHAServiceStateWithTimeout() + throws Exception { + setupProxyProvider(1); + NNProxyInfo<ClientProtocol> dummyNNProxyInfo = + (NNProxyInfo<ClientProtocol>) Mockito.mock(NNProxyInfo.class); + Future<HAServiceState> task = mock(Future.class); + when(task.get(anyLong(), any(TimeUnit.class))).thenThrow( + new InterruptedException("Interrupted")); + + HAServiceState state = + proxyProvider.getHAServiceStateWithTimeout(dummyNNProxyInfo, task); + assertNull(state); + verify(task).get(anyLong(), any(TimeUnit.class)); + verifyNoMoreInteractions(task); + verify(logger).debug( + startsWith("Interrupted exception in NN probe task for")); + } + + /** + * Test InterruptedException for GetHAServiceStateWithTimeout. + * Tests for the other two exceptions are the same and thus left out. Review Comment: outdated comments. removed. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org For additional commands, e-mail: common-issues-h...@hadoop.apache.org