CommandExecutor { @VisibleForTesting boolean lockCMS(Object command) { if (cmsDlockService == null) { return false; } if (!(command instanceof GfshCommand)) { return false; } GfshCommand gfshCommand = (GfshCommand) command; if (gfshCommand.getConfigurationPersistenceService() == null) { return false; } if (!gfshCommand.affectsClusterConfiguration()) { return false; } return cmsDlockService.lock(CMS_DLOCK_SERVICE_NAME, -1, -1); } CommandExecutor(DistributedLockService cmsDlockService); Object execute(GfshParseResult parseResult); @VisibleForTesting @SuppressWarnings("deprecation") Object execute(Object command, GfshParseResult parseResult); static final String RUN_ON_MEMBER_CHANGE_NOT_PERSISTED; static final String SERVICE_NOT_RUNNING_CHANGE_NOT_PERSISTED; }
@Test public void nullDlockServiceWillNotLock() throws Exception { CommandExecutor nullLockServiceExecutor = new CommandExecutor(null); assertThat(nullLockServiceExecutor.lockCMS(new Object())).isEqualTo(false); }
@Test public void lockCms() throws Exception { assertThat(executor.lockCMS(null)).isEqualTo(false); assertThat(executor.lockCMS(new Object())).isEqualTo(false); GfshCommand gfshCommand = mock(GfshCommand.class); when(gfshCommand.getConfigurationPersistenceService()).thenReturn(null); assertThat(executor.lockCMS(gfshCommand)).isEqualTo(false); when(gfshCommand.getConfigurationPersistenceService()).thenReturn(ccService); when(gfshCommand.affectsClusterConfiguration()).thenReturn(false); assertThat(executor.lockCMS(gfshCommand)).isEqualTo(false); when(gfshCommand.affectsClusterConfiguration()).thenReturn(true); assertThat(executor.lockCMS(gfshCommand)).isEqualTo(true); verify(dlockService).lock(any(), eq(-1L), eq(-1L)); }