Search in sources :

Example 16 with Breakpoint

use of com.google.api.services.clouddebugger.v2.model.Breakpoint in project google-cloud-intellij by GoogleCloudPlatform.

the class CloudDebugProcessStateController method pruneBreakpointCache.

private void pruneBreakpointCache(List<Breakpoint> currentList) {
    // Clear out the obsolete breakpoint cache for old items.
    HashSet<String> toRemoveSet = new HashSet<>();
    toRemoveSet.addAll(fullFinalBreakpoints.keySet());
    if (!toRemoveSet.isEmpty() && currentList != null) {
        for (Breakpoint bp : currentList) {
            toRemoveSet.remove(bp.getId());
        }
    }
    for (String idToRemove : toRemoveSet) {
        fullFinalBreakpoints.remove(idToRemove);
    }
}
Also used : Breakpoint(com.google.api.services.clouddebugger.v2.model.Breakpoint) HashSet(com.intellij.util.containers.HashSet)

Example 17 with Breakpoint

use of com.google.api.services.clouddebugger.v2.model.Breakpoint 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 18 with Breakpoint

use of com.google.api.services.clouddebugger.v2.model.Breakpoint in project google-cloud-intellij by GoogleCloudPlatform.

the class CloudBreakpointHandlerTest method testUnregisterBreakpoint_shouldSetAddedOnServerToFalseAfterHitOnBackend.

@SuppressWarnings("unchecked")
public void testUnregisterBreakpoint_shouldSetAddedOnServerToFalseAfterHitOnBackend() throws Exception {
    XLineBreakpointImpl breakpoint = registerMockBreakpoint(NO_WATCHES, NO_CONDITION, 13, "fileName", "packageName", false, "12abc");
    handler.setStateToDisabled(new Breakpoint().setId("12abc"));
    assertNotNull(breakpoint.getProperties());
    assertTrue(((CloudLineBreakpointProperties) breakpoint.getProperties()).isAddedOnServer());
    handler.unregisterBreakpoint(breakpoint, false);
    assertFalse(((CloudLineBreakpointProperties) breakpoint.getProperties()).isAddedOnServer());
    verify(stateController, never()).deleteBreakpointAsync("12abc");
}
Also used : Breakpoint(com.google.api.services.clouddebugger.v2.model.Breakpoint) XBreakpoint(com.intellij.xdebugger.breakpoints.XBreakpoint) CloudLineBreakpoint(com.google.cloud.tools.intellij.debugger.CloudLineBreakpointType.CloudLineBreakpoint) XLineBreakpoint(com.intellij.xdebugger.breakpoints.XLineBreakpoint) XLineBreakpointImpl(com.intellij.xdebugger.impl.breakpoints.XLineBreakpointImpl)

Example 19 with Breakpoint

use of com.google.api.services.clouddebugger.v2.model.Breakpoint in project google-cloud-intellij by GoogleCloudPlatform.

the class CloudBreakpointHandlerTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    fixture = IdeaTestFixtureFactory.getFixtureFactory().createFixtureBuilder(getTestName(true)).getFixture();
    fixture.setUp();
    project = new MockProjectEx(getTestRootDisposable());
    psiManager = mock(PsiManager.class);
    project.registerService(PsiManager.class, psiManager);
    XDebugSession session = mock(XDebugSession.class);
    when(session.getProject()).thenReturn(project);
    process = mock(CloudDebugProcess.class);
    when(process.getXDebugSession()).thenReturn(session);
    CloudDebugProcessState processState = mock(CloudDebugProcessState.class);
    existingBreakpoints = new ArrayList<Breakpoint>();
    when(processState.getCurrentServerBreakpointList()).thenReturn(ContainerUtil.immutableList(existingBreakpoints));
    when(process.getProcessState()).thenReturn(processState);
    stateController = mock(CloudDebugProcessStateController.class);
    when(process.getStateController()).thenReturn(stateController);
    registrationShouldSucceed = true;
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            addedBp.set((Breakpoint) invocation.getArguments()[0]);
            SetBreakpointHandler handler = (SetBreakpointHandler) invocation.getArguments()[1];
            if (registrationShouldSucceed) {
                handler.onSuccess(desiredResultId);
            } else {
                handler.onError("Registration failed");
            }
            return null;
        }
    }).when(stateController).setBreakpointAsync(any(Breakpoint.class), any(SetBreakpointHandler.class));
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            removedBp.set((String) invocation.getArguments()[0]);
            return null;
        }
    }).when(stateController).deleteBreakpointAsync(anyString());
    fileResolver = mock(ServerToIdeFileResolver.class);
    handler = new CloudBreakpointHandler(process, fileResolver);
    XDebuggerManager debuggerManager = mock(XDebuggerManager.class);
    project.addComponent(XDebuggerManager.class, debuggerManager);
    breakpointManager = mock(XBreakpointManager.class);
    when(debuggerManager.getBreakpointManager()).thenReturn(breakpointManager);
}
Also used : XDebugSession(com.intellij.xdebugger.XDebugSession) Breakpoint(com.google.api.services.clouddebugger.v2.model.Breakpoint) XBreakpoint(com.intellij.xdebugger.breakpoints.XBreakpoint) CloudLineBreakpoint(com.google.cloud.tools.intellij.debugger.CloudLineBreakpointType.CloudLineBreakpoint) XLineBreakpoint(com.intellij.xdebugger.breakpoints.XLineBreakpoint) PsiManager(com.intellij.psi.PsiManager) SetBreakpointHandler(com.google.cloud.tools.intellij.debugger.CloudDebugProcessStateController.SetBreakpointHandler) XDebuggerManager(com.intellij.xdebugger.XDebuggerManager) Matchers.anyString(org.mockito.Matchers.anyString) MockProjectEx(com.intellij.mock.MockProjectEx) Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) XBreakpointManager(com.intellij.xdebugger.breakpoints.XBreakpointManager) InvocationOnMock(org.mockito.invocation.InvocationOnMock)

Example 20 with Breakpoint

use of com.google.api.services.clouddebugger.v2.model.Breakpoint in project google-cloud-intellij by GoogleCloudPlatform.

the class CloudBreakpointHandlerTest method testCreateIdeRepresentationsIfNecessaryVerifiesNonFinalIdeBreakpoint.

public void testCreateIdeRepresentationsIfNecessaryVerifiesNonFinalIdeBreakpoint() throws Exception {
    XLineBreakpointImpl breakpoint = registerMockBreakpoint(NO_WATCHES, NO_CONDITION, 13, "fileName", "packageName", false, "12abc");
    CloudLineBreakpoint cloudLineBreakpoint = (CloudLineBreakpoint) breakpoint.getUserData(com.intellij.debugger.ui.breakpoints.Breakpoint.DATA_KEY);
    assertNotNull(cloudLineBreakpoint);
    Assert.assertFalse(cloudLineBreakpoint.isVerified());
    handler.createIdeRepresentationsIfNecessary(Lists.newArrayList(new Breakpoint().setId("12abc")));
    assertThat(cloudLineBreakpoint.getErrorMessage(), nullValue());
    Assert.assertTrue(cloudLineBreakpoint.isVerified());
}
Also used : Breakpoint(com.google.api.services.clouddebugger.v2.model.Breakpoint) XBreakpoint(com.intellij.xdebugger.breakpoints.XBreakpoint) CloudLineBreakpoint(com.google.cloud.tools.intellij.debugger.CloudLineBreakpointType.CloudLineBreakpoint) XLineBreakpoint(com.intellij.xdebugger.breakpoints.XLineBreakpoint) XLineBreakpointImpl(com.intellij.xdebugger.impl.breakpoints.XLineBreakpointImpl) CloudLineBreakpoint(com.google.cloud.tools.intellij.debugger.CloudLineBreakpointType.CloudLineBreakpoint)

Aggregations

Breakpoint (com.google.api.services.clouddebugger.v2.model.Breakpoint)27 CloudLineBreakpoint (com.google.cloud.tools.intellij.debugger.CloudLineBreakpointType.CloudLineBreakpoint)11 XLineBreakpoint (com.intellij.xdebugger.breakpoints.XLineBreakpoint)11 XBreakpoint (com.intellij.xdebugger.breakpoints.XBreakpoint)10 SourceLocation (com.google.api.services.clouddebugger.v2.model.SourceLocation)8 Debugger (com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger)7 ArrayList (java.util.ArrayList)7 XBreakpointManager (com.intellij.xdebugger.breakpoints.XBreakpointManager)4 IOException (java.io.IOException)4 ListBreakpointsResponse (com.google.api.services.clouddebugger.v2.model.ListBreakpointsResponse)3 PluginInfoService (com.google.cloud.tools.intellij.service.PluginInfoService)3 Project (com.intellij.openapi.project.Project)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 XLineBreakpointImpl (com.intellij.xdebugger.impl.breakpoints.XLineBreakpointImpl)3 Test (org.junit.Test)3 StatusMessage (com.google.api.services.clouddebugger.v2.model.StatusMessage)2 CloudBreakpointHandler (com.google.cloud.tools.intellij.debugger.CloudBreakpointHandler)2 SetBreakpointHandler (com.google.cloud.tools.intellij.debugger.CloudDebugProcessStateController.SetBreakpointHandler)2 RelativePoint (com.intellij.ui.awt.RelativePoint)2 XDebuggerManager (com.intellij.xdebugger.XDebuggerManager)2