Search in sources :

Example 16 with Debugger

use of com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger 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)

Example 17 with Debugger

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

the class CloudDebuggerClientTest method testUserAgent.

@Test
public void testUserAgent() throws IOException {
    when(mockInfoService.getUserAgent()).thenReturn("userAgent");
    Debugger client = CloudDebuggerClient.getLongTimeoutClient("foo@example.com");
    HttpRequest httpRequest = client.debuggees().list().buildHttpRequestUsingHead();
    HttpHeaders headers = httpRequest.getHeaders();
    String userAgent = headers.getUserAgent();
    Assert.assertTrue(userAgent.startsWith("userAgent"));
    Assert.assertTrue(userAgent.endsWith("Google-API-Java-Client"));
}
Also used : Debugger(com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger) HttpRequest(com.google.api.client.http.HttpRequest) HttpHeaders(com.google.api.client.http.HttpHeaders) Test(org.junit.Test)

Example 18 with Debugger

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

the class CloudDebuggerClientTest method testGetShortTimeoutClient_fromUserEmail.

@Test
public void testGetShortTimeoutClient_fromUserEmail() {
    Debugger client = CloudDebuggerClient.getShortTimeoutClient("foo@example.com");
    Assert.assertNotNull(client.debuggees().breakpoints());
}
Also used : Debugger(com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger) Test(org.junit.Test)

Example 19 with Debugger

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

the class ProjectDebuggeeBinding method refreshDebugTargetList.

/**
 * Refreshes the list of attachable debug targets based on the project selection.
 */
@SuppressWarnings("FutureReturnValueIgnored")
private void refreshDebugTargetList(CloudProject cloudProject) {
    targetSelector.removeAllItems();
    ApplicationManager.getApplication().executeOnPooledThread(() -> {
        try {
            String projectNumber = Optional.ofNullable(cloudProject.projectNumber()).map(Object::toString).orElse(null);
            if (projectNumber != null && getCloudDebuggerClient() != null) {
                final ListDebuggeesResponse debuggees = getCloudDebuggerClient().debuggees().list().setProject(projectNumber).setClientVersion(ServiceManager.getService(PluginInfoService.class).getClientVersionForCloudDebugger()).execute();
                isCdbQueried = true;
                SwingUtilities.invokeLater(() -> {
                    DebugTarget targetSelection = null;
                    if (debuggees == null || debuggees.getDebuggees() == null || debuggees.getDebuggees().isEmpty()) {
                        disableTargetSelector(GctBundle.getString("clouddebug.nomodulesfound"));
                    } else {
                        targetSelector.setEnabled(true);
                        Map<String, DebugTarget> perModuleCache = new HashMap<>();
                        for (Debuggee debuggee : debuggees.getDebuggees()) {
                            DebugTarget item = new DebugTarget(debuggee, cloudProject.projectId());
                            if (!Strings.isNullOrEmpty(item.getModule()) && !Strings.isNullOrEmpty(item.getVersion())) {
                                // If we already have an existing item for that module+version,
                                // compare the minor versions and only use the latest minor version.
                                String key = String.format("%s:%s", item.getModule(), item.getVersion());
                                DebugTarget existing = perModuleCache.get(key);
                                if (existing != null && existing.getMinorVersion() > item.getMinorVersion()) {
                                    continue;
                                }
                                if (existing != null) {
                                    targetSelector.removeItem(existing);
                                }
                                perModuleCache.put(key, item);
                            }
                            if (inputState != null && !Strings.isNullOrEmpty(inputState.getDebuggeeId())) {
                                if (inputState.getDebuggeeId().equals(item.getId())) {
                                    targetSelection = item;
                                }
                            }
                            targetSelector.addItem(item);
                            okAction.setEnabled(true);
                        }
                    }
                    if (targetSelection != null) {
                        targetSelector.setSelectedItem(targetSelection);
                    }
                });
            }
        } catch (final IOException ex) {
            SwingUtilities.invokeLater(() -> disableTargetSelector(ex));
            LOG.warn("Error listing debuggees from Cloud Debugger API", ex);
        }
    });
}
Also used : HashMap(com.intellij.util.containers.HashMap) Debuggee(com.google.api.services.clouddebugger.v2.model.Debuggee) ListDebuggeesResponse(com.google.api.services.clouddebugger.v2.model.ListDebuggeesResponse) PluginInfoService(com.google.cloud.tools.intellij.service.PluginInfoService) IOException(java.io.IOException)

Aggregations

Debugger (com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger)12 IOException (java.io.IOException)10 Breakpoint (com.google.api.services.clouddebugger.v2.model.Breakpoint)9 PluginInfoService (com.google.cloud.tools.intellij.service.PluginInfoService)5 Debuggee (com.google.api.services.clouddebugger.v2.model.Debuggee)4 ListBreakpointsResponse (com.google.api.services.clouddebugger.v2.model.ListBreakpointsResponse)3 ArrayList (java.util.ArrayList)3 GoogleJsonResponseException (com.google.api.client.googleapis.json.GoogleJsonResponseException)2 HttpHeaders (com.google.api.client.http.HttpHeaders)2 HttpRequest (com.google.api.client.http.HttpRequest)2 Debuggees (com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger.Debuggees)2 Breakpoints (com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger.Debuggees.Breakpoints)2 ListDebuggeesResponse (com.google.api.services.clouddebugger.v2.model.ListDebuggeesResponse)2 RegisterDebuggeeRequest (com.google.api.services.clouddebugger.v2.model.RegisterDebuggeeRequest)2 RegisterDebuggeeResponse (com.google.api.services.clouddebugger.v2.model.RegisterDebuggeeResponse)2 SourceLocation (com.google.api.services.clouddebugger.v2.model.SourceLocation)2 SocketTimeoutException (java.net.SocketTimeoutException)2 Test (org.junit.Test)2 Credential (com.google.api.client.auth.oauth2.Credential)1 GoogleNetHttpTransport (com.google.api.client.googleapis.javanet.GoogleNetHttpTransport)1