Search in sources :

Example 11 with Breakpoints

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());
        }
    });
}
Also used : Debugger(com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger) Breakpoint(com.google.api.services.clouddebugger.v2.model.Breakpoint) IOException(java.io.IOException) GetBreakpointResponse(com.google.api.services.clouddebugger.v2.model.GetBreakpointResponse)

Example 12 with Breakpoints

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;
}
Also used : Breakpoint(com.google.api.services.clouddebugger.v2.model.Breakpoint) ListBreakpointsResponse(com.google.api.services.clouddebugger.v2.model.ListBreakpointsResponse) PluginInfoService(com.google.cloud.tools.intellij.service.PluginInfoService)

Example 13 with Breakpoints

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();
}
Also used : Breakpoint(com.google.api.services.clouddebugger.v2.model.Breakpoint) CloudLineBreakpoint(com.google.cloud.tools.intellij.debugger.CloudLineBreakpointType.CloudLineBreakpoint) XLineBreakpoint(com.intellij.xdebugger.breakpoints.XLineBreakpoint) XBreakpointManager(com.intellij.xdebugger.breakpoints.XBreakpointManager) XLineBreakpointImpl(com.intellij.xdebugger.impl.breakpoints.XLineBreakpointImpl) CloudLineBreakpoint(com.google.cloud.tools.intellij.debugger.CloudLineBreakpointType.CloudLineBreakpoint) ProjectImpl(com.intellij.openapi.project.impl.ProjectImpl) ArrayList(java.util.ArrayList) XDebuggerManager(com.intellij.xdebugger.XDebuggerManager) Icon(javax.swing.Icon) StatusMessage(com.google.api.services.clouddebugger.v2.model.StatusMessage)

Example 14 with Breakpoints

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;
}
Also used : Debugger(com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger) Breakpoint(com.google.api.services.clouddebugger.v2.model.Breakpoint) ListBreakpointsResponse(com.google.api.services.clouddebugger.v2.model.ListBreakpointsResponse) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ArrayList(java.util.ArrayList) List(java.util.List)

Example 15 with Breakpoints

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"));
}
Also used : Debugger(com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger) Breakpoint(com.google.api.services.clouddebugger.v2.model.Breakpoint) ArrayList(java.util.ArrayList)

Aggregations

Breakpoint (com.google.api.services.clouddebugger.v2.model.Breakpoint)13 Debugger (com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger)9 IOException (java.io.IOException)5 CloudLineBreakpoint (com.google.cloud.tools.intellij.debugger.CloudLineBreakpointType.CloudLineBreakpoint)4 XLineBreakpoint (com.intellij.xdebugger.breakpoints.XLineBreakpoint)4 ArrayList (java.util.ArrayList)4 ListBreakpointsResponse (com.google.api.services.clouddebugger.v2.model.ListBreakpointsResponse)3 SourceLocation (com.google.api.services.clouddebugger.v2.model.SourceLocation)3 PluginInfoService (com.google.cloud.tools.intellij.service.PluginInfoService)3 Project (com.intellij.openapi.project.Project)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 XBreakpoint (com.intellij.xdebugger.breakpoints.XBreakpoint)3 XBreakpointManager (com.intellij.xdebugger.breakpoints.XBreakpointManager)3 GoogleJsonResponseException (com.google.api.client.googleapis.json.GoogleJsonResponseException)2 Debuggees (com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger.Debuggees)2 Breakpoints (com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger.Debuggees.Breakpoints)2 SocketTimeoutException (java.net.SocketTimeoutException)2 Test (org.junit.Test)2 GetBreakpointResponse (com.google.api.services.clouddebugger.v2.model.GetBreakpointResponse)1 SetBreakpointResponse (com.google.api.services.clouddebugger.v2.model.SetBreakpointResponse)1