/** Creates a background listener. */ public synchronized void ensureWatcher() { if (poller == null) { poller = new CloudDebugGlobalPoller(); poller.addListener(this); poller.startBackgroundListening(); } }
@Override public void run() { for (CloudDebugProcessState state : stateCollector.getBackgroundListeningStates()) { cloudDebugGlobalPoller.pollForChanges(state); } } }
/** Stop the background listener. */ public synchronized void removeWatcher() { if (poller != null) { poller.stopBackgroundListening(); poller = null; } }
"CloudDebugProcessState is listening in the background but no debugger client " + "could be retrieved => stop listening"); handleBreakpointQueryError( state, StackdriverDebuggerBundle.message( String oldToken = state.getWaitToken(); queryServerForBreakpoints(state, client); handleBreakpointQueryError(state, ex); handleBreakpointQueryError(state, ex); return; } catch (Exception ex) { LOG.error("exception listing breakpoints", ex); handleBreakpointQueryError(state, ex); return; fireBreakpointsChanged(state);
@Before public void setUp() throws Exception { cloudDebugProcessState = new CloudDebugProcessState(); cloudDebugGlobalPoller = new CloudDebugGlobalPoller(); notificationsHandler = setupNotificationHandlerForVerification(); }
private void handleBreakpointQueryError( @NotNull CloudDebugProcessState state, @NotNull Exception ex) { String message; String projectName = state.getProject().getName(); if (ex instanceof GoogleJsonResponseException) { GoogleJsonResponseException jsonResponseException = (GoogleJsonResponseException) ex; if (jsonResponseException.getStatusCode() == HttpURLConnection.HTTP_FORBIDDEN || jsonResponseException.getStatusCode() == HttpURLConnection.HTTP_UNAUTHORIZED) { message = StackdriverDebuggerBundle.message( "clouddebug.background.listener.access.error.message", projectName); } else { message = StackdriverDebuggerBundle.message( "clouddebug.background.listener.general.error.message", projectName, jsonResponseException.getDetails().getMessage()); } } else { message = StackdriverDebuggerBundle.message( "clouddebug.background.listener.general.error.message", projectName, ex.getLocalizedMessage()); } handleBreakpointQueryError(state, message); }
@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); } } }
@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(); }