@Override public String additionalLogoutMessage() { if (stateCollector != null && stateCollector.getBackgroundListeningStates() != null && !stateCollector.getBackgroundListeningStates().isEmpty()) { return GctBundle.message("clouddebug.logout.additional.message"); } else { return ""; } } }
public CloudDebugGlobalPollerTimerTask(CloudDebugGlobalPoller cloudDebugGlobalPoller) { this.cloudDebugGlobalPoller = cloudDebugGlobalPoller; stateCollector = CloudDebugProcessStateCollector.getInstance(); }
@NotNull @VisibleForTesting Set<RunProfile> getProfilesWithActiveDebugSession(Project project) { Set<RunProfile> debuggingProfiles = new HashSet<RunProfile>(); XDebuggerManager debugManager = XDebuggerManager.getInstance(project); for (XDebugSession session : debugManager.getDebugSessions()) { if (notStoppedAndHasRunProfile(session)) { debuggingProfiles.add(session.getRunProfile()); } } return debuggingProfiles; }
/** Get all the background snapshot states. */ public List<CloudDebugProcessState> getBackgroundListeningStates() { List<CloudDebugProcessState> states = new ArrayList<CloudDebugProcessState>(); for (Project project : ProjectManager.getInstance().getOpenProjects()) { Set<RunProfile> runningProfiles = getProfilesWithActiveDebugSession(project); RunManager manager = RunManager.getInstance(project); // find all CloudDebugRunConfiguration that do not have active debug sessions but are // listening in the background for (final RunnerAndConfigurationSettings config : manager.getAllSettings()) { if (notRunningConfiguration(runningProfiles, config.getConfiguration())) { if (config.getConfiguration() instanceof CloudDebugRunConfiguration) { final CloudDebugRunConfiguration cloudConfig = (CloudDebugRunConfiguration) config.getConfiguration(); CloudDebugProcessState state = cloudConfig.getProcessState(); if (listensInBackground(state)) { states.add(state); } } } } } return states; }
@Test public void testGetBackgroundListeningStates_returnsEmptyListWhenNoProjectIsOpen() { createMockProjectManagerWithProjects(new Project[0]); List<CloudDebugProcessState> backgroundListeningStates = new CloudDebugProcessStateCollector().getBackgroundListeningStates(); assertNotNull(backgroundListeningStates); assertThat(backgroundListeningStates).hasSize(0); }
@Test public void testNotStoppedAndHasRunProfile_returnsTrueIfNotStoppedAndHasProfile() { XDebugSession session = createMockSession(false, mock(RunProfile.class)); assertTrue(new CloudDebugProcessStateCollector().notStoppedAndHasRunProfile(session)); }
@Test public void testNotRunningConfiguration_returnsFalseIfNullConfigIsPassedIn() { assertFalse( new CloudDebugProcessStateCollector() .notRunningConfiguration(new HashSet<RunProfile>(), null)); }
@Test public void testListensInBackground_returnsFalseIfNullIsPassedIn() throws Exception { assertFalse(new CloudDebugProcessStateCollector().listensInBackground(null)); }
@Test public void testGetProfilesWithActiveDebugSession_returnsEmptySetIfNoDebugSessions() { Project project = mock(Project.class); createMockXDebuggerManager(project, new XDebugSession[0]); Set<RunProfile> profiles = new CloudDebugProcessStateCollector().getProfilesWithActiveDebugSession(project); assertNotNull(profiles); assertThat(profiles).hasSize(0); }
@Test public void testGetBackgroundListeningStates_withMultipleProjects() { int runningSessions = 1; int listeningSessions = 2; int notListeningSessions = 3; Project project1 = createProject(runningSessions, listeningSessions, notListeningSessions); Project project2 = createProject(runningSessions, listeningSessions, notListeningSessions); createMockProjectManagerWithProjects(new Project[] {project1, project2}); List<CloudDebugProcessState> backgroundListeningStates = new CloudDebugProcessStateCollector().getBackgroundListeningStates(); assertNotNull(backgroundListeningStates); assertThat(backgroundListeningStates).hasSize(2 * listeningSessions); for (CloudDebugProcessState state : backgroundListeningStates) { assertTrue(state.isListenInBackground()); } }
@Test public void testNotStoppedAndHasRunProfile_returnsFalseIfStoppedAndHasProfile() { XDebugSession session = createMockSession(true, mock(RunProfile.class)); assertFalse(new CloudDebugProcessStateCollector().notStoppedAndHasRunProfile(session)); }
@Test public void testNotRunningConfiguration_returnsFalseIfConfigIsInRunningConfigurations() { RunConfiguration config = mock(RunConfiguration.class); HashSet<RunProfile> runningConfigurations = new HashSet<RunProfile>(); runningConfigurations.add(config); assertFalse( new CloudDebugProcessStateCollector() .notRunningConfiguration(runningConfigurations, config)); }
@Test public void testListensInBackground_returnsFalseIfStateDoesNotListenInBackground() throws Exception { CloudDebugProcessState state = new CloudDebugProcessState(); state.setListenInBackground(false); assertFalse(new CloudDebugProcessStateCollector().listensInBackground(state)); }
@Test public void testGetProfilesWithActiveDebugSession_returnsNotStoppedSessionsWithRunProfile() { Project project = mock(Project.class); XDebugSession notStoppedSession = createMockSession(false, mock(CloudDebugRunConfiguration.class)); XDebugSession stoppedSession = createMockSession(true, mock(CloudDebugRunConfiguration.class)); XDebugSession stoppedSessionWithoutRunProfile = createMockSession(true, null); createMockXDebuggerManager( project, new XDebugSession[] {notStoppedSession, stoppedSession, stoppedSessionWithoutRunProfile}); Set<RunProfile> profiles = new CloudDebugProcessStateCollector().getProfilesWithActiveDebugSession(project); assertNotNull(profiles); assertThat(profiles).hasSize(1); }
@Override public void run() { for (CloudDebugProcessState state : stateCollector.getBackgroundListeningStates()) { cloudDebugGlobalPoller.pollForChanges(state); } } }
@Test public void testNotStoppedAndHasRunProfile_returnsFalseIfStoppedAndHasNoProfile() { XDebugSession session = createMockSession(true, null); assertFalse(new CloudDebugProcessStateCollector().notStoppedAndHasRunProfile(session)); }
@Test public void testNotRunningConfiguration_returnsTrueIfThereAreNoRunningConfigurations() { RunConfiguration config = mock(RunConfiguration.class); assertTrue( new CloudDebugProcessStateCollector() .notRunningConfiguration(new HashSet<RunProfile>(), config)); }
@Test public void testListensInBackground_returnsTrueIfStateListensInBackground() throws Exception { CloudDebugProcessState state = new CloudDebugProcessState(); state.setListenInBackground(true); assertTrue(new CloudDebugProcessStateCollector().listensInBackground(state)); }
public IntelliJGoogleLoginMessageExtender() { stateCollector = CloudDebugProcessStateCollector.getInstance(); }
@Test public void testRunCallsPollforChangesForAllStates() throws Exception { List<CloudDebugProcessState> states = new ArrayList<CloudDebugProcessState>(); states.add(mock(CloudDebugProcessState.class)); states.add(mock(CloudDebugProcessState.class)); when(cloudDebugProcessStateCollector.getBackgroundListeningStates()).thenReturn(states); new CloudDebugGlobalPollerTimerTask(cloudDebugGlobalPoller).run(); for (CloudDebugProcessState cloudDebugProcessState : states) { verify(cloudDebugGlobalPoller).pollForChanges(cloudDebugProcessState); } } }