@Test(timeout = 50000) public void testStartStopServer() throws Exception { Configuration config = new YarnConfiguration(); UserGroupInformation ugi = UserGroupInformation.createUserForTesting("ambari", new String[] {"ambari"}); mockStatic(UserGroupInformation.class); expect(UserGroupInformation.getCurrentUser()).andReturn(ugi).anyTimes(); expect(UserGroupInformation.isSecurityEnabled()).andReturn(false).anyTimes(); config.set(YarnConfiguration.APPLICATION_HISTORY_STORE, "org.apache.hadoop.yarn.server.applicationhistoryservice.NullApplicationHistoryStore"); Configuration hbaseConf = new Configuration(); hbaseConf.set("hbase.zookeeper.quorum", "localhost"); TimelineMetricConfiguration metricConfiguration = PowerMock.createNiceMock(TimelineMetricConfiguration.class); expectNew(TimelineMetricConfiguration.class).andReturn(metricConfiguration); expect(metricConfiguration.getHbaseConf()).andReturn(hbaseConf); Configuration metricsConf = new Configuration(); expect(metricConfiguration.getMetricsConf()).andReturn(metricsConf).anyTimes(); expect(metricConfiguration.isTimelineMetricsServiceWatcherDisabled()).andReturn(true); expect(metricConfiguration.getTimelineMetricsServiceHandlerThreadCount()).andReturn(20).anyTimes(); expect(metricConfiguration.getWebappAddress()).andReturn("localhost:9990").anyTimes(); expect(metricConfiguration.getTimelineServiceRpcAddress()).andReturn("localhost:10299").anyTimes(); expect(metricConfiguration.getClusterZKQuorum()).andReturn("localhost").anyTimes(); expect(metricConfiguration.getClusterZKClientPort()).andReturn("2181").anyTimes(); Connection connection = createNiceMock(Connection.class); Statement stmt = createNiceMock(Statement.class); PreparedStatement preparedStatement = createNiceMock(PreparedStatement.class); ResultSet rs = createNiceMock(ResultSet.class); mockStatic(DriverManager.class); expect(DriverManager.getConnection("jdbc:phoenix:localhost:2181:/ams-hbase-unsecure")) .andReturn(connection).anyTimes(); expect(connection.createStatement()).andReturn(stmt).anyTimes(); expect(connection.prepareStatement(anyString())).andReturn(preparedStatement).anyTimes(); suppress(method(Statement.class, "executeUpdate", String.class)); expect(preparedStatement.executeQuery()).andReturn(rs).anyTimes(); expect(rs.next()).andReturn(false).anyTimes(); preparedStatement.close(); expectLastCall().anyTimes(); connection.close(); expectLastCall(); MetricCollectorHAController haControllerMock = PowerMock.createMock(MetricCollectorHAController.class); expectNew(MetricCollectorHAController.class, metricConfiguration) .andReturn(haControllerMock); haControllerMock.initializeHAController(); expectLastCall().once(); expect(haControllerMock.isInitialized()).andReturn(false).anyTimes(); org.apache.hadoop.hbase.client.Connection conn = createNiceMock(org.apache.hadoop.hbase.client.Connection.class); mockStatic(ConnectionFactory.class); expect(ConnectionFactory.createConnection((Configuration) anyObject())).andReturn(conn); expect(conn.getAdmin()).andReturn(null); EasyMock.replay(connection, stmt, preparedStatement, rs); replayAll(); historyServer = new ApplicationHistoryServer(); historyServer.init(config); verifyAll(); assertEquals(STATE.INITED, historyServer.getServiceState()); assertEquals(4, historyServer.getServices().size()); ApplicationHistoryClientService historyService = historyServer.getClientService(); assertNotNull(historyServer.getClientService()); assertEquals(STATE.INITED, historyService.getServiceState()); historyServer.start(); assertEquals(STATE.STARTED, historyServer.getServiceState()); assertEquals(STATE.STARTED, historyService.getServiceState()); historyServer.stop(); assertEquals(STATE.STOPPED, historyServer.getServiceState()); }
@Private @VisibleForTesting public ApplicationHistoryClientService getClientService() { return this.ahsClientService; }
ApplicationHistoryServer extends CompositeService { @Private @VisibleForTesting public ApplicationHistoryClientService getClientService() { return this.ahsClientService; } }
ApplicationHistoryServer extends CompositeService { @Private @VisibleForTesting public ApplicationHistoryClientService getClientService() { return this.ahsClientService; } ApplicationHistoryServer(); }
ApplicationHistoryServer extends CompositeService { @Private @VisibleForTesting public ApplicationHistoryClientService getClientService() { return this.ahsClientService; } ApplicationHistoryServer(); @Private @VisibleForTesting ApplicationHistoryClientService getClientService(); static void main(String[] args); @Private @VisibleForTesting TimelineStore getTimelineStore(); }
ApplicationHistoryServer extends CompositeService { @Private @VisibleForTesting public ApplicationHistoryClientService getClientService() { return this.ahsClientService; } ApplicationHistoryServer(); @Private @VisibleForTesting ApplicationHistoryClientService getClientService(); static void main(String[] args); @Private @VisibleForTesting TimelineStore getTimelineStore(); static final int SHUTDOWN_HOOK_PRIORITY; }