private void handleBreakpointQueryError(@NotNull CloudDebugProcessState state, String message) { state.setListenInBackground(false); String title = StackdriverDebuggerBundle.message("clouddebug.background.listener.error.title"); Notification notification = new Notification( CLOUD_DEBUGGER_ERROR_NOTIFICATIONS_DISPLAY_GROUP, title, message, NotificationType.ERROR); Notifications.Bus.notify(notification, state.getProject()); } }
/** * CloudDebugProcessState can be initialized with partial state to indicate preferences on the * {@link CloudDebugRunConfiguration}. When the process state is partial, the attach dialog is * used to make it complete. isValidDebuggee must be true for the attach to continue. * * @param userEmail the user's email which corresponds to a login {@link CredentialedUser} * @param debuggeeId a String Id that represents a target application to debug (debuggee) * @param projectName a alpha-numeric String name identifying a GCP project that owns the target * debuggee * @param projectNumber a numeric String identifying the same GCP project that owns the target * debuggee * @param project the intelliJ IDE project */ public CloudDebugProcessState( @Nullable String userEmail, @Nullable String debuggeeId, @Nullable String projectName, @Nullable String projectNumber, @Nullable Project project) { setUserEmail(userEmail); setDebuggeeId(debuggeeId); setProjectName(projectName); setProjectNumber(projectNumber); setProject(project); setListenInBackground(false); }
private void ensureSingleDebugSession(Project project) throws RunCanceledByUserException { List<CloudDebugProcessState> backgroundSessions = getBackgroundDebugStates(project); if (backgroundSessions.size() > 0) { for (CloudDebugProcessState cdps : backgroundSessions) { cdps.setListenInBackground(false); } } List<CloudDebugProcess> activeDebugProcesses = getActiveDebugProcesses(project); if (activeDebugProcesses.size() > 0) { int result = Messages.showOkCancelDialog( project, StackdriverDebuggerBundle.getString("clouddebug.stop.and.create.new.session"), StackdriverDebuggerBundle.getString("clouddebug.message.title"), StackdriverDebuggerIcons.STACKDRIVER_DEBUGGER); if (result == Messages.OK) { for (CloudDebugProcess cdb : activeDebugProcesses) { cdb.getProcessHandler().detachProcess(); } } else { throw new RunCanceledByUserException(); } } }
private XDebugSession createDebugSettingsAndAddToRunnerSettings( List<RunnerAndConfigurationSettings> runnerSettings, boolean isStopped, boolean hasDebugSession, Boolean listenInBackground) { CloudDebugRunConfiguration runConfiguration = mock(CloudDebugRunConfiguration.class); if (listenInBackground != null) { CloudDebugProcessState processState = new CloudDebugProcessState(); processState.setListenInBackground(listenInBackground); when(runConfiguration.getProcessState()).thenReturn(processState); } RunnerAndConfigurationSettings configurationSettings = mock(RunnerAndConfigurationSettings.class); when(configurationSettings.getConfiguration()).thenReturn(runConfiguration); runnerSettings.add(configurationSettings); if (hasDebugSession) { return createMockSession(isStopped, runConfiguration); } else { return null; } }
@Test public void testListensInBackground_returnsFalseIfStateDoesNotListenInBackground() throws Exception { CloudDebugProcessState state = new CloudDebugProcessState(); state.setListenInBackground(false); assertFalse(new CloudDebugProcessStateCollector().listensInBackground(state)); }
@Test public void testListensInBackground_returnsTrueIfStateListensInBackground() throws Exception { CloudDebugProcessState state = new CloudDebugProcessState(); state.setListenInBackground(true); assertTrue(new CloudDebugProcessStateCollector().listensInBackground(state)); }
@Override public void actionPerformed(AnActionEvent event) { int result = Messages.showOkCancelDialog( event.getProject(), StackdriverDebuggerBundle.getString("clouddebug.continue.listening"), StackdriverDebuggerBundle.getString("clouddebug.message.title"), StackdriverDebuggerBundle.getString("clouddebug.continue"), StackdriverDebuggerBundle.getString("clouddebug.stop.listening"), Messages.getQuestionIcon()); if (result == Messages.OK) { // continue processState.setListenInBackground(true); UsageTrackerService.getInstance() .trackEvent(GctTracking.CLOUD_DEBUGGER_CLOSE_CONTINUE_LISTEN) .ping(); } else { processState.setListenInBackground(false); UsageTrackerService.getInstance() .trackEvent(GctTracking.CLOUD_DEBUGGER_CLOSE_STOP_LISTEN) .ping(); } ActionManager.getInstance().getAction(IdeActions.ACTION_STOP_PROGRAM).actionPerformed(event); ActionManager.getInstance().getAction(IdeActions.ACTION_CLOSE).actionPerformed(event); }
@Test public void testPollForChanges_firesNotificationOnIOException() throws IOException { cloudDebugProcessState.setListenInBackground(true); cloudDebugProcessState.setUserEmail(FAKE_USER_EMAIL); cloudDebugProcessState.setDebuggeeId(FAKE_DEBUGGEE_ID); cloudDebugProcessState.setProject(getProject()); setupCloudDebuggerBackendMockWithException(FAKE_USER_EMAIL, new IOException()); cloudDebugGlobalPoller.pollForChanges(cloudDebugProcessState); assertFalse(cloudDebugProcessState.isListenInBackground()); verifyNotificationFired(); }
@Test public void testPollForChanges_firesNotificationIfNoDebugClientObtained() { cloudDebugProcessState.setListenInBackground(true); cloudDebugProcessState.setProject(getProject()); cloudDebugGlobalPoller.pollForChanges(cloudDebugProcessState); assertFalse(cloudDebugProcessState.isListenInBackground()); verifyNotificationFired(); }