@Test public void testRunDatabaseConsistencyCheck() throws Exception { EasyMockSupport easyMockSupport = new EasyMockSupport(); final AmbariMetaInfo mockAmbariMetainfo = easyMockSupport.createNiceMock(AmbariMetaInfo.class); final DBAccessor mockDBDbAccessor = easyMockSupport.createNiceMock(DBAccessor.class); final Connection mockConnection = easyMockSupport.createNiceMock(Connection.class); final Statement mockStatement = easyMockSupport.createNiceMock(Statement.class); final OsFamily mockOSFamily = easyMockSupport.createNiceMock(OsFamily.class); final StackManagerFactory mockStackManagerFactory = easyMockSupport.createNiceMock(StackManagerFactory.class); final EntityManager mockEntityManager = easyMockSupport.createNiceMock(EntityManager.class); final Clusters mockClusters = easyMockSupport.createNiceMock(Clusters.class); AmbariServer ambariServer = new AmbariServer(); final Configuration mockConfiguration = partialMockBuilder(Configuration.class).withConstructor() .addMockedMethod("getDatabaseType").createMock(); final TypedQuery mockQuery = easyMockSupport.createNiceMock(TypedQuery.class); expect(mockConfiguration.getDatabaseType()).andReturn(null).anyTimes(); expect(mockEntityManager.createNamedQuery(anyString(),anyObject(Class.class))).andReturn(mockQuery); expect(mockQuery.getResultList()).andReturn(new ArrayList()); replay(mockConfiguration); final Injector mockInjector = Guice.createInjector(new AbstractModule() { @Override protected void configure() { bind(StackManagerFactory.class).toInstance(mockStackManagerFactory); bind(AmbariMetaInfo.class).toInstance(mockAmbariMetainfo); bind(DBAccessor.class).toInstance(mockDBDbAccessor); bind(OsFamily.class).toInstance(mockOSFamily); bind(EntityManager.class).toInstance(mockEntityManager); bind(Clusters.class).toInstance(mockClusters); bind(Configuration.class).toInstance(mockConfiguration); } }); expect(mockDBDbAccessor.getConnection()).andReturn(mockConnection).atLeastOnce(); expect(mockConnection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE)).andReturn(mockStatement).atLeastOnce(); expect(mockStatement.executeQuery(anyString())).andReturn(null).atLeastOnce(); DatabaseConsistencyCheckHelper.setInjector(mockInjector); easyMockSupport.replayAll(); mockAmbariMetainfo.init(); ambariServer.runDatabaseConsistencyCheck(); easyMockSupport.verifyAll(); }
protected void runDatabaseConsistencyCheck() throws Exception { if (System.getProperty("skipDatabaseConsistencyCheck") == null) { boolean fixIssues = (System.getProperty("fixDatabaseConsistency") != null); try { DatabaseConsistencyCheckResult checkResult = DatabaseConsistencyCheckHelper.runAllDBChecks(fixIssues); System.out.println("Database consistency check result: " + checkResult); if (checkResult.isError()) { System.exit(1); } } catch (Throwable ex) { System.out.println("Database consistency check result: " + DatabaseConsistencyCheckResult.DB_CHECK_ERROR); throw new Exception(ex); } } }
AmbariServer { protected void runDatabaseConsistencyCheck() throws Exception { if (System.getProperty("skipDatabaseConsistencyCheck") == null) { boolean fixIssues = (System.getProperty("fixDatabaseConsistency") != null); try { DatabaseConsistencyCheckResult checkResult = DatabaseConsistencyCheckHelper.runAllDBChecks(fixIssues); System.out.println("Database consistency check result: " + checkResult); if (checkResult.isError()) { System.exit(1); } } catch (Throwable ex) { System.out.println("Database consistency check result: " + DatabaseConsistencyCheckResult.DB_CHECK_ERROR); throw new Exception(ex); } } } }
AmbariServer { protected void runDatabaseConsistencyCheck() throws Exception { if (System.getProperty("skipDatabaseConsistencyCheck") == null) { boolean fixIssues = (System.getProperty("fixDatabaseConsistency") != null); try { DatabaseConsistencyCheckResult checkResult = DatabaseConsistencyCheckHelper.runAllDBChecks(fixIssues); System.out.println("Database consistency check result: " + checkResult); if (checkResult.isError()) { System.exit(1); } } catch (Throwable ex) { System.out.println("Database consistency check result: " + DatabaseConsistencyCheckResult.DB_CHECK_ERROR); throw new Exception(ex); } } }  }
AmbariServer { protected void runDatabaseConsistencyCheck() throws Exception { if (System.getProperty("skipDatabaseConsistencyCheck") == null) { boolean fixIssues = (System.getProperty("fixDatabaseConsistency") != null); try { DatabaseConsistencyCheckResult checkResult = DatabaseConsistencyCheckHelper.runAllDBChecks(fixIssues); System.out.println("Database consistency check result: " + checkResult); if (checkResult.isError()) { System.exit(1); } } catch (Throwable ex) { System.out.println("Database consistency check result: " + DatabaseConsistencyCheckResult.DB_CHECK_ERROR); throw new Exception(ex); } } }  String getServerOsType(); static AmbariManagementController getController(); @SuppressWarnings("deprecation") void run(); void stop(); @Deprecated void performStaticInjection(); void initViewRegistry(); static void setupProxyAuth(); static void enableLog4jMonitor(Map<String, String> configsMap); static void main(String[] args); }
AmbariServer { protected void runDatabaseConsistencyCheck() throws Exception { if (System.getProperty("skipDatabaseConsistencyCheck") == null) { boolean fixIssues = (System.getProperty("fixDatabaseConsistency") != null); try { DatabaseConsistencyCheckResult checkResult = DatabaseConsistencyCheckHelper.runAllDBChecks(fixIssues); System.out.println("Database consistency check result: " + checkResult); if (checkResult.isError()) { System.exit(1); } } catch (Throwable ex) { System.out.println("Database consistency check result: " + DatabaseConsistencyCheckResult.DB_CHECK_ERROR); throw new Exception(ex); } } }  String getServerOsType(); static AmbariManagementController getController(); @SuppressWarnings("deprecation") void run(); void stop(); @Deprecated void performStaticInjection(); void initViewRegistry(); static void setupProxyAuth(); static void enableLog4jMonitor(Map<String, String> configsMap); static void main(String[] args); static final String VIEWS_URL_PATTERN; static final EnumSet<DispatcherType> DISPATCHER_TYPES; volatile boolean running; }