UpgradeCatalog220 extends AbstractUpgradeCatalog { protected void executeUpgradePreDMLUpdates() throws AmbariException, SQLException { UpgradeDAO upgradeDAO = injector.getInstance(UpgradeDAO.class); List<UpgradeEntity> upgrades = upgradeDAO.findAll(); for (UpgradeEntity upgrade: upgrades){ if (upgrade.isDowngradeAllowed() == null) { upgrade.setDowngradeAllowed(true); } upgrade.setAutoSkipComponentFailures(false); upgrade.setAutoSkipServiceCheckFailures(false); upgradeDAO.merge(upgrade); LOG.info(String.format("Updated upgrade id %s, upgrade pack %s from version %s to %s", upgrade.getId(), upgrade.getUpgradePackage(), upgrade.getFromVersion(), upgrade.getToVersion())); } dbAccessor.setColumnNullable(UPGRADE_TABLE, DOWNGRADE_ALLOWED_COLUMN, false); dbAccessor.setColumnNullable(UPGRADE_TABLE, UPGRADE_SKIP_FAILURE_COLUMN, false); dbAccessor.setColumnNullable(UPGRADE_TABLE, UPGRADE_SKIP_SC_FAILURE_COLUMN, false); } @Inject  UpgradeCatalog220(Injector injector); @Override String getTargetVersion(); @Override String getSourceVersion(); @Transactional void bootstrapRepoVersionForHDP21(); static final String UPGRADE_PACKAGE_COL; static final String UPGRADE_TYPE_COL; static final String REPO_VERSION_TABLE; }
@Test public void testExecuteUpgradePreDMLUpdates() throws Exception { Method executeStackPreDMLUpdates = UpgradeCatalog220.class.getDeclaredMethod("executeUpgradePreDMLUpdates"); Method executeStackUpgradeDDLUpdates = UpgradeCatalog220.class.getDeclaredMethod("executeStackUpgradeDDLUpdates"); Method bootstrapRepoVersionForHDP21 = UpgradeCatalog220.class.getDeclaredMethod("bootstrapRepoVersionForHDP21"); final UpgradeCatalog220 upgradeCatalog220 = createMockBuilder(UpgradeCatalog220.class) .addMockedMethod(executeStackUpgradeDDLUpdates) .addMockedMethod(bootstrapRepoVersionForHDP21) .addMockedMethod(executeStackPreDMLUpdates).createMock(); final Injector mockInjector = Guice.createInjector(new AbstractModule() { @Override protected void configure() { bind(UpgradeCatalog220.class).toInstance(upgradeCatalog220); bind(DBAccessor.class).toInstance(createNiceMock(DBAccessor.class)); bind(OsFamily.class).toInstance(createNiceMock(OsFamily.class)); bind(EntityManager.class).toInstance(entityManager); } }); upgradeCatalog220.executeUpgradePreDMLUpdates(); expectLastCall().once(); upgradeCatalog220.executeStackUpgradeDDLUpdates(); expectLastCall().once(); upgradeCatalog220.bootstrapRepoVersionForHDP21(); expectLastCall().once(); replay(upgradeCatalog220); mockInjector.getInstance(UpgradeCatalog220.class).executePreDMLUpdates(); verify(upgradeCatalog220); }