@Test public void testApplicationDeletion() throws Exception { Manager manager = Mockito.spy( new Manager()); manager.configurationMngr().setWorkingDirectory( this.folder.newFolder()); final String cmdName = "cmd"; final Application app1 = new TestApplication().name( "app1" ).directory( this.folder.newFolder()); final Application app2 = new TestApplication().name( "app2" ).directory( this.folder.newFolder()); TestManagerWrapper wrapper = new TestManagerWrapper( manager ); wrapper.addManagedApplication( new ManagedApplication( app1 )); wrapper.addManagedApplication( new ManagedApplication( app2 )); manager.commandsMngr().createOrUpdateCommand( app1, cmdName, "" ); manager.commandsMngr().createOrUpdateCommand( app2, cmdName, "" ); RoboconfScheduler scheduler = new RoboconfScheduler(); scheduler.manager = manager; Mockito.reset( manager ); try { scheduler.start(); Assert.assertNotNull( scheduler.saveJob( null, "job11", cmdName, "0 0 0 ? 1 *", app1.getName())); Assert.assertNotNull( scheduler.saveJob( null, "job12", cmdName, "0 0 0 ? 1 *", app1.getName())); Assert.assertNotNull( scheduler.saveJob( null, "job13", cmdName, "0 0 0 ? 1 *", app1.getName())); String jobId21 = scheduler.saveJob( null, "job21", cmdName, "0 0 0 ? 1 *", app2.getName()); Assert.assertNotNull( jobId21 ); String jobId22 = scheduler.saveJob( null, "job22", cmdName, "0 0 0 ? 1 *", app2.getName()); Assert.assertNotNull( jobId22 ); File schedulerDirectory = scheduler.getSchedulerDirectory(); Set<JobKey> jobKeys = scheduler.scheduler.getJobKeys( GroupMatcher.anyJobGroup()); Assert.assertEquals( 5, jobKeys.size()); Assert.assertEquals( 5, Utils.listAllFiles( schedulerDirectory ).size()); scheduler.dmListener.application( app1, EventType.CREATED ); jobKeys = scheduler.scheduler.getJobKeys( GroupMatcher.anyJobGroup()); Assert.assertEquals( 5, jobKeys.size()); Assert.assertEquals( 5, Utils.listAllFiles( schedulerDirectory ).size()); scheduler.dmListener.application( app1, EventType.CHANGED ); jobKeys = scheduler.scheduler.getJobKeys( GroupMatcher.anyJobGroup()); Assert.assertEquals( 5, jobKeys.size()); Assert.assertEquals( 5, Utils.listAllFiles( schedulerDirectory ).size()); scheduler.dmListener.application( app1, EventType.DELETED ); jobKeys = scheduler.scheduler.getJobKeys( GroupMatcher.anyJobGroup()); Assert.assertEquals( 2, jobKeys.size()); Assert.assertEquals( 2, Utils.listAllFiles( schedulerDirectory ).size()); Assert.assertTrue( jobKeys.contains( new JobKey( jobId21, "app2" ))); Assert.assertTrue( jobKeys.contains( new JobKey( jobId22, "app2" ))); } finally { scheduler.stop(); } }
@Override public void application( Application application, EventType eventType ) { if( eventType == EventType.DELETED ) { this.logger.fine( "Application " + application + " was deleted. Associated jobs are about to be deleted." ); try { Set<TriggerKey> tks = this.scheduler.scheduler.getTriggerKeys( GroupMatcher.triggerGroupEquals( application.getName())); for( TriggerKey tk : tks ) { try { this.scheduler.deleteJob( tk.getName()); } catch( Exception e ) { this.logger.warning( "An error occurred while unscheduling job " + tk.getName() + ". " + e.getMessage()); Utils.logException( this.logger, e ); } } } catch( Exception e ) { this.logger.warning( "An error occurred while listing jobs for application " + application + ". " + e.getMessage()); Utils.logException( this.logger, e ); } } }
ManagerListener implements IDmListener { @Override public void application( Application application, EventType eventType ) { if( eventType == EventType.DELETED ) { this.logger.fine( "Application " + application + " was deleted. Associated jobs are about to be deleted." ); try { Set<TriggerKey> tks = this.scheduler.scheduler.getTriggerKeys( GroupMatcher.triggerGroupEquals( application.getName())); for( TriggerKey tk : tks ) { try { this.scheduler.deleteJob( tk.getName()); } catch( Exception e ) { this.logger.warning( "An error occurred while unscheduling job " + tk.getName() + ". " + e.getMessage()); Utils.logException( this.logger, e ); } } } catch( Exception e ) { this.logger.warning( "An error occurred while listing jobs for application " + application + ". " + e.getMessage()); Utils.logException( this.logger, e ); } } } }
ManagerListener implements IDmListener { @Override public void application( Application application, EventType eventType ) { if( eventType == EventType.DELETED ) { this.logger.fine( "Application " + application + " was deleted. Associated jobs are about to be deleted." ); try { Set<TriggerKey> tks = this.scheduler.scheduler.getTriggerKeys( GroupMatcher.triggerGroupEquals( application.getName())); for( TriggerKey tk : tks ) { try { this.scheduler.deleteJob( tk.getName()); } catch( Exception e ) { this.logger.warning( "An error occurred while unscheduling job " + tk.getName() + ". " + e.getMessage()); Utils.logException( this.logger, e ); } } } catch( Exception e ) { this.logger.warning( "An error occurred while listing jobs for application " + application + ". " + e.getMessage()); Utils.logException( this.logger, e ); } } } ManagerListener( RoboconfScheduler scheduler ); }
ManagerListener implements IDmListener { @Override public void application( Application application, EventType eventType ) { if( eventType == EventType.DELETED ) { this.logger.fine( "Application " + application + " was deleted. Associated jobs are about to be deleted." ); try { Set<TriggerKey> tks = this.scheduler.scheduler.getTriggerKeys( GroupMatcher.triggerGroupEquals( application.getName())); for( TriggerKey tk : tks ) { try { this.scheduler.deleteJob( tk.getName()); } catch( Exception e ) { this.logger.warning( "An error occurred while unscheduling job " + tk.getName() + ". " + e.getMessage()); Utils.logException( this.logger, e ); } } } catch( Exception e ) { this.logger.warning( "An error occurred while listing jobs for application " + application + ". " + e.getMessage()); Utils.logException( this.logger, e ); } } } ManagerListener( RoboconfScheduler scheduler ); @Override String getId(); @Override void enableNotifications(); @Override void disableNotifications(); @Override void applicationTemplate( ApplicationTemplate tpl, EventType eventType ); @Override void instance( Instance instance, Application application, EventType eventType ); @Override void raw( String message, Object... data ); @Override void application( Application application, EventType eventType ); }
ManagerListener implements IDmListener { @Override public void application( Application application, EventType eventType ) { if( eventType == EventType.DELETED ) { this.logger.fine( "Application " + application + " was deleted. Associated jobs are about to be deleted." ); try { Set<TriggerKey> tks = this.scheduler.scheduler.getTriggerKeys( GroupMatcher.triggerGroupEquals( application.getName())); for( TriggerKey tk : tks ) { try { this.scheduler.deleteJob( tk.getName()); } catch( Exception e ) { this.logger.warning( "An error occurred while unscheduling job " + tk.getName() + ". " + e.getMessage()); Utils.logException( this.logger, e ); } } } catch( Exception e ) { this.logger.warning( "An error occurred while listing jobs for application " + application + ". " + e.getMessage()); Utils.logException( this.logger, e ); } } } ManagerListener( RoboconfScheduler scheduler ); @Override String getId(); @Override void enableNotifications(); @Override void disableNotifications(); @Override void applicationTemplate( ApplicationTemplate tpl, EventType eventType ); @Override void instance( Instance instance, Application application, EventType eventType ); @Override void raw( String message, Object... data ); @Override void application( Application application, EventType eventType );  }