public void testShouldSetMigrationStrategyToDistributedJdbcMigrationLauncherFromProperties( ) throws MigrationException { DistributedJdbcMigrationLauncherFactory factory = new DistributedJdbcMigrationLauncherFactory(); IMocksControl control = createNiceControl(); DistributedJdbcMigrationLauncher distributedLauncher = control.createMock(DistributedJdbcMigrationLauncher.class); String systemName="mysystem"; String propertyFileName="migration.properties"; Properties properties = MockBuilder.getPropertiesWithDistributedSystemConfiguration("mysystem", "mystrategy", "orders"); distributedLauncher.setMigrationStrategy("mystrategy"); DistributedMigrationProcess migrationProcess=new DistributedMigrationProcess(); expect(distributedLauncher.getMigrationProcess() ).andReturn(migrationProcess).anyTimes(); control.replay(); factory.configureFromMigrationProperties(distributedLauncher, systemName,properties, propertyFileName); control.verify(); }
public void testShouldRunMigrationsForcingRollback() throws Exception { IMocksControl mockControl = createStrictControl(); MigrationUtil migrationUtil = mockControl.createMock(MigrationUtil.class); StandaloneMigrationLauncher migrationLauncher = new StandaloneMigrationLauncher(migrationUtil); String[] arguments = new String[]{"orders","migration.properties","-force", "-rollback", "1"}; migrationUtil.doRollbacks(eq("orders"), eq("migration.properties"), EasyMock.<int[]>anyObject(), eq(true)); mockControl.replay(); migrationLauncher.setMigrationUtil(migrationUtil); migrationLauncher.run(arguments); mockControl.verify(); }
public void testShouldRunMigrationsMultipleRollbacks() throws Exception { IMocksControl mockControl = createStrictControl(); MigrationUtil migrationUtil = mockControl.createMock(MigrationUtil.class); StandaloneMigrationLauncher migrationLauncher = new StandaloneMigrationLauncher(migrationUtil); String[] arguments = new String[]{"orders","migration.properties","-force", "-rollback", "1,2,3,4,5,6"}; migrationUtil.doRollbacks(eq("orders"), eq("migration.properties"), EasyMock.<int[]>anyObject(), eq(true)); mockControl.replay(); migrationLauncher.run(arguments); mockControl.verify(); }
public void testShouldRunMigrationsMultipleRollbacksInvalidRollbackLevels() throws Exception { IMocksControl mockControl = createStrictControl(); MigrationUtil migrationUtil = mockControl.createMock(MigrationUtil.class); StandaloneMigrationLauncher migrationLauncher = new StandaloneMigrationLauncher(migrationUtil); String[] arguments = new String[]{"orders","migration.properties","-force", "-rollback", "1,2C,3B,4D,5A,600"}; try { migrationLauncher.run(arguments); fail("Should have thrown migration exception"); } catch (MigrationException me) { assertEquals("The rollbacklevels should be integers separated by a comma", me.getMessage()); } }
public static PatchInfoStore getPatchInfoStore(int patchLevel, Set<Integer> patchesApplied) throws MigrationException { IMocksControl patchInfoStoreControl = createStrictControl(); PatchInfoStore patchInfoStoreMock = patchInfoStoreControl.createMock(PatchInfoStore.class); expect(patchInfoStoreMock.getPatchLevel()).andReturn(patchLevel).anyTimes(); expect(patchInfoStoreMock.getPatchesApplied()).andReturn(patchesApplied); patchInfoStoreControl.replay(); return patchInfoStoreMock; }
public void testDoRollbacksActionMockingAsIfOrderedStrategyWereUsed() throws MigrationException { String systemName = "system1"; JdbcMigrationLauncher launcher = new JdbcMigrationLauncher(); int[] rollbackLevels = new int[]{9}; IMocksControl mockControl = createControl(); JdbcMigrationContext migrationContextMock = mockControl.createMock(JdbcMigrationContext.class); MigrationRunnerStrategy migrationRunnerStrategyMock = mockControl.createMock(MigrationRunnerStrategy.class); TestRollbackableTask3 rollbackableTask3 = new TestRollbackableTask3(); TestRollbackableTask4 rollbackableTask4 = new TestRollbackableTask4(); TestRollbackableTask5 rollbackableTask5 = new TestRollbackableTask5(); List<MigrationTask> migrationTaskList = new ArrayList<MigrationTask>(); migrationTaskList.add(new TestRollbackableTask1()); migrationTaskList.add(new TestRollbackableTask2()); migrationTaskList.add(rollbackableTask3); migrationTaskList.add(rollbackableTask4); migrationTaskList.add(rollbackableTask5); MigrationProcess migrationProcessMock = mockControl.createMock(MigrationProcess.class); expect(migrationProcessMock.getMigrationTasks()).andReturn(migrationTaskList); HashMap controlledSystems = new HashMap(); controlledSystems.put(systemName, launcher); launcher.setMigrationProcess(migrationProcessMock); PatchInfoStore patchInfoStoreMock = mockControl.createMock(PatchInfoStore.class); expect(patchInfoStoreMock.getPatchLevel()).andReturn(12); expect(migrationRunnerStrategyMock.isSynchronized(eq(currentPatchInfoStore), EasyMock.<PatchInfoStore>anyObject())).andReturn(true).anyTimes(); List<MigrationTask> rollbackCandidates = new ArrayList<MigrationTask>(); rollbackCandidates.add(rollbackableTask5); rollbackCandidates.add(rollbackableTask4); rollbackCandidates.add(rollbackableTask3); expect(migrationRunnerStrategyMock.getRollbackCandidates(migrationTaskList, rollbackLevels, patchInfoStoreMock)).andReturn(rollbackCandidates); expect(migrationRunnerStrategyMock.getRollbackCandidates(rollbackCandidates, rollbackLevels, patchInfoStoreMock)).andReturn(Collections.EMPTY_LIST); mockControl.replay(); DistributedMigrationProcess distributedMigrationProcess = new DistributedMigrationProcess(); distributedMigrationProcess.setMigrationRunnerStrategy(migrationRunnerStrategyMock); distributedMigrationProcess.setControlledSystems(controlledSystems); boolean forceRollback=false; int rollbacksApplied = distributedMigrationProcess.doRollbacks(patchInfoStoreMock,rollbackLevels,migrationContextMock,forceRollback); assertEquals("Two rollbacks should be applied", 3, rollbacksApplied); }
public void testConfigureMigrationLauncherFactorySetsMigrationStrategy() throws MigrationException { factory = new JdbcMigrationLauncherFactory(); IMocksControl launcherControl = createNiceControl(); JdbcMigrationLauncher launcher = launcherControl.createMock(JdbcMigrationLauncher.class); launcher.setMigrationStrategy(MIGRATION_STRATEGY); MigrationProcess migrationProcess = new MigrationProcess(); expect(launcher.getMigrationProcess()).andReturn(migrationProcess); launcherControl.replay(); String system = "anySystem"; Properties properties = MockBuilder.getPropertiesWithSystemConfiguration("anySystem",MIGRATION_STRATEGY); factory.configureFromMigrationProperties(launcher, system, properties); launcherControl.verify(); }
/** * Make sure we get notified of patch application * * @exception Exception if anything goes wrong */ public void testDistributedRollbackEvents() throws Exception { IMocksControl mockControl = createControl(); // There should be five listener on the main process // 1) the distributed launcher // 2) this test object // 3-5) the three sub-launchers assertEquals(5, getLauncher().getMigrationProcess().getListeners().size()); // The sub-MigrationProcesses should have one listener each - the // sub-launcher HashMap controlledSystems = ((DistributedMigrationProcess) getLauncher() .getMigrationProcess()).getControlledSystems(); List<MigrationTask> migrationTasks = new ArrayList<MigrationTask>(); for (Iterator controlledSystemIter = controlledSystems.keySet().iterator(); controlledSystemIter.hasNext();) { String controlledSystemName = (String) controlledSystemIter.next(); JdbcMigrationLauncher subLauncher = (JdbcMigrationLauncher) controlledSystems.get(controlledSystemName); MigrationProcess subProcess = subLauncher.getMigrationProcess(); List<MigrationTask> migrationTasksList = subProcess.getMigrationTasks(); migrationTasks.addAll(migrationTasksList); assertEquals(1, subProcess.getListeners().size()); MigrationProcess migrationProcessMock = mockControl.createMock(MigrationProcess.class); expect(migrationProcessMock.getMigrationTasks()).andReturn(migrationTasksList); subLauncher.setMigrationProcess(migrationProcessMock); } // Now do the migrations, and make sure we get the right number of // events DistributedMigrationProcess process = (DistributedMigrationProcess) getLauncher().getMigrationProcess(); List<MigrationTask> rollbackCandidates = new ArrayList<MigrationTask>(); for (MigrationTask migrationTask : migrationTasks) { if (migrationTask instanceof TestRollbackableTask2 || migrationTask instanceof TestRollbackableTask3 || migrationTask instanceof TestRollbackableTask4 || migrationTask instanceof TestRollbackableTask5) { rollbackCandidates.add(migrationTask); } } MigrationRunnerStrategy migrationRunnerStrategyMock = mockControl.createMock(MigrationRunnerStrategy.class); expect(migrationRunnerStrategyMock.getRollbackCandidates(EasyMock.<List<MigrationTask>>anyObject(), eq(ROLLBACK_LEVELS), eq(currentPatchInfoStore))).andReturn(rollbackCandidates); expect(migrationRunnerStrategyMock.getRollbackCandidates(rollbackCandidates, ROLLBACK_LEVELS, currentPatchInfoStore)).andReturn(Collections.EMPTY_LIST); expect(migrationRunnerStrategyMock.isSynchronized(eq(currentPatchInfoStore), EasyMock.<PatchInfoStore>anyObject())).andReturn(true).anyTimes(); process.setMigrationRunnerStrategy(migrationRunnerStrategyMock); mockControl.replay(); int currentPatchlevel = 12; setReportedPatchLevel(process.getControlledSystems().values(), currentPatchlevel); int patches = process.doRollbacks(currentPatchInfoStore, ROLLBACK_LEVELS, getContext(), false); assertEquals(4, patches); assertEquals(4, getRollbackStartedCount()); assertEquals(4, getRollbackSuccessCount()); }