use of com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger.Debuggees.Breakpoints in project google-cloud-intellij by GoogleCloudPlatform.
the class CloudDebugProcessStateController method resolveBreakpointAsync.
/**
* Returns a fully realized {@link Breakpoint} with all results possibly asynchronously.
*/
@SuppressWarnings("FutureReturnValueIgnored")
public void resolveBreakpointAsync(@NotNull final String id, @NotNull final ResolveBreakpointHandler handler) {
if (fullFinalBreakpoints.containsKey(id)) {
handler.onSuccess(fullFinalBreakpoints.get(id));
return;
}
if (state == null) {
handler.onError(GctBundle.getString("clouddebug.invalid.state"));
return;
}
final Debugger client = CloudDebuggerClient.getLongTimeoutClient(state);
if (client == null) {
LOG.warn("no client available attempting to resolveBreakpointAsync");
handler.onError(GctBundle.getString("clouddebug.bad.login.message"));
return;
}
List<Breakpoint> currentList = state.getCurrentServerBreakpointList();
for (Breakpoint serverBreakpointCandidate : currentList) {
if (serverBreakpointCandidate.getId().equals(id) && !Boolean.TRUE.equals(serverBreakpointCandidate.getIsFinalState())) {
handler.onSuccess(serverBreakpointCandidate);
return;
}
}
ApplicationManager.getApplication().executeOnPooledThread(() -> {
// At this point, the user has selected a final state breakpoint which is not yet
// hydrated.
// So we query the server to get this final on a worker thread and then run the
// runnable
// back on ui
GetBreakpointResponse response;
try {
response = client.debuggees().breakpoints().get(state.getDebuggeeId(), id).setClientVersion(ServiceManager.getService(PluginInfoService.class).getClientVersionForCloudDebugger()).execute();
Breakpoint result = response.getBreakpoint();
if (result != null) {
fullFinalBreakpoints.put(id, result);
handler.onSuccess(result);
} else {
handler.onError(GctBundle.getString("clouddebug.no.response"));
}
} catch (IOException ex) {
LOG.warn("IOException hydrating a snapshot. User may have deleted the snapshot", ex);
handler.onError(ex.toString());
}
});
}
use of com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger.Debuggees.Breakpoints in project google-cloud-intellij by GoogleCloudPlatform.
the class CloudDebugProcessStateController method queryServerForBreakpoints.
private List<Breakpoint> queryServerForBreakpoints(CloudDebugProcessState state, Debugger client, String tokenToSend) throws IOException {
List<Breakpoint> currentList = null;
String responseWaitToken = tokenToSend;
while (tokenToSend == null || tokenToSend.equals(responseWaitToken)) {
if (tokenToSend != null && !isBackgroundListening()) {
return null;
}
ListBreakpointsResponse response = client.debuggees().breakpoints().list(state.getDebuggeeId()).setIncludeInactive(Boolean.TRUE).setActionValue("CAPTURE").setStripResults(Boolean.TRUE).setWaitToken(CloudDebugConfigType.useWaitToken() ? tokenToSend : null).setClientVersion(ServiceManager.getService(PluginInfoService.class).getClientVersionForCloudDebugger()).execute();
// up the background watcher.
if (tokenToSend != null && !isBackgroundListening()) {
return null;
}
currentList = response.getBreakpoints();
responseWaitToken = response.getNextWaitToken();
if (tokenToSend == null) {
break;
}
if (!CloudDebugConfigType.useWaitToken() && tokenToSend.equals(responseWaitToken)) {
try {
// our fallback polling mode has a 1 second loop.
Thread.currentThread().sleep(1000);
} catch (InterruptedException ex) {
return null;
}
}
}
state.setWaitToken(responseWaitToken);
if (currentList != null) {
Collections.sort(currentList, BreakpointComparer.getDefaultInstance());
}
state.setCurrentServerBreakpointList(currentList != null ? ContainerUtil.immutableList(currentList) : ContainerUtil.immutableList(new ArrayList<>()));
return currentList;
}
use of com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger.Debuggees.Breakpoints in project google-cloud-intellij by GoogleCloudPlatform.
the class CloudDebugProcessTest method testOnBreakpointListChangedSetsErrorMessageAndUpdatesBreakpointPresentation.
public void testOnBreakpointListChangedSetsErrorMessageAndUpdatesBreakpointPresentation() throws Exception {
// override the default XBreakpointManager implementation with mock to use Mockito.verify()
XBreakpointManager breakpointManager = mock(XBreakpointManager.class);
XDebuggerManager debuggerManager = mock(XDebuggerManager.class);
when(debuggerManager.getBreakpointManager()).thenReturn(breakpointManager);
((ProjectImpl) getProject()).registerComponentInstance(XDebuggerManager.class, debuggerManager);
ArrayList<Breakpoint> breakpoints = new ArrayList<Breakpoint>();
Breakpoint breakpoint = new Breakpoint();
breakpoint.setId("breakpointId").setIsFinalState(Boolean.TRUE).setStatus(new StatusMessage().setIsError(Boolean.TRUE));
breakpoints.add(breakpoint);
CloudDebugProcessState processState = mock(CloudDebugProcessState.class);
when(processState.getCurrentServerBreakpointList()).thenReturn(ContainerUtil.immutableList(breakpoints));
XLineBreakpointImpl xLineBreakpointImpl = mock(XLineBreakpointImpl.class);
CloudLineBreakpoint cloudLineBreakpoint = mockCloudLineBreakpoint("mock error message", xLineBreakpointImpl);
when(xLineBreakpointImpl.getUserData(com.intellij.debugger.ui.breakpoints.Breakpoint.DATA_KEY)).thenReturn(cloudLineBreakpoint);
CloudBreakpointHandler breakpointHandler = mock(CloudBreakpointHandler.class);
when(breakpointHandler.getEnabledXBreakpoint(breakpoint)).thenReturn(xLineBreakpointImpl);
process.setBreakpointHandler(breakpointHandler);
process.initialize(processState);
process.onBreakpointListChanged(mock(CloudDebugProcessState.class));
verify(cloudLineBreakpoint).setErrorMessage(eq("General error"));
verify(cloudLineBreakpoint).getXBreakpoint();
verify(cloudLineBreakpoint).getSetIcon(Matchers.anyBoolean());
verify(cloudLineBreakpoint).getErrorMessage();
verify(breakpointManager).updateBreakpointPresentation(same(xLineBreakpointImpl), any(Icon.class), eq("General error"));
process.getStateController().stopBackgroundListening();
}
use of com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger.Debuggees.Breakpoints in project google-cloud-intellij by GoogleCloudPlatform.
the class CloudDebugProcessStateTest method createMockClient.
private Debugger createMockClient(final List<Breakpoint> returnedBreakpoints) throws IOException {
Debugger client = Mockito.mock(Debugger.class);
Debugger.Debuggees debuggees = Mockito.mock(Debugger.Debuggees.class);
Debugger.Debuggees.Breakpoints breakpoints = Mockito.mock(Debugger.Debuggees.Breakpoints.class);
Debugger.Debuggees.Breakpoints.List list = Mockito.mock(Debugger.Debuggees.Breakpoints.List.class);
when(client.debuggees()).thenReturn(debuggees);
when(debuggees.breakpoints()).thenReturn(breakpoints);
when(breakpoints.list(DEBUGEE_ID)).thenReturn(list);
when(list.setIncludeInactive(Boolean.TRUE)).thenReturn(list);
when(list.setActionValue("CAPTURE")).thenReturn(list);
when(list.setStripResults(Boolean.TRUE)).thenReturn(list);
when(list.setWaitToken(null)).thenReturn(list);
when(list.setClientVersion(ServiceManager.getService(PluginInfoService.class).getClientVersionForCloudDebugger())).thenReturn(list);
when(list.execute()).thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
ListBreakpointsResponse response = new ListBreakpointsResponse();
List<Breakpoint> copy = new ArrayList<Breakpoint>(returnedBreakpoints);
response.setBreakpoints(copy);
return response;
}
});
return client;
}
use of com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger.Debuggees.Breakpoints in project google-cloud-intellij by GoogleCloudPlatform.
the class CloudDebugProcessStateTest method testFirstSync.
public void testFirstSync() throws IOException {
List<Breakpoint> returnedBreakpoints = new ArrayList<Breakpoint>();
returnedBreakpoints.add(createBreakpoint("bp1", Boolean.TRUE, 1000, "com/google/ex1.java", 15, null, null));
returnedBreakpoints.add(createBreakpoint("bp2", Boolean.TRUE, 2000, "com/google/ex1.java", 15, null, null));
returnedBreakpoints.add(createBreakpoint("bp3", Boolean.TRUE, 2200, "com/google/ex1.java", 15, Boolean.TRUE, "foo!"));
returnedBreakpoints.add(createBreakpoint("bp4", Boolean.FALSE, 0, "com/google/ex2.java", 12, null, null));
returnedBreakpoints.add(createBreakpoint("bp5", Boolean.FALSE, 0, "com/google/ex1.java", 15, null, null));
returnedBreakpoints.add(createBreakpoint("bp6", null, 0, "com/google/ex1.java", 16, null, null));
returnedBreakpoints.add(createBreakpoint("bp7", Boolean.FALSE, 0, "com/google/ex1.java", 17, null, null));
returnedBreakpoints.add(createBreakpoint("bp8", Boolean.FALSE, 0, "com/google/ex3.java", 18, null, null));
Debugger client = createMockClient(returnedBreakpoints);
CloudDebugProcessState state = new CloudDebugProcessState(USER, DEBUGEE_ID, PROJECT_NAME, PROJECT_NUMBER, null);
assertEquals(USER, state.getUserEmail());
// Danger: static global state
CloudDebuggerClient.setClient(state.getUserEmail() + 120000, client);
CloudDebugProcessStateController controller = new CloudDebugProcessStateController();
controller.initialize(state);
verify(client.debuggees().breakpoints().list(DEBUGEE_ID), times(1)).setIncludeInactive(Boolean.TRUE);
List<Breakpoint> currentList = state.getCurrentServerBreakpointList();
assertNotEmpty(currentList);
// verifies the sort order...
assertTrue(verifyList(currentList, "bp5", "bp6", "bp7", "bp4", "bp8", "bp3", "bp2", "bp1"));
}
Aggregations