Search in sources :

Example 51 with Registration

use of com.google.gerrit.acceptance.ExtensionRegistry.Registration in project gerrit by GerritCodeReview.

the class TraceIT method traceAccountInvalidId.

@Test
@GerritConfig(name = "tracing.issue123.account", value = "invalid")
public void traceAccountInvalidId() throws Exception {
    TraceValidatingProjectCreationValidationListener projectCreationListener = new TraceValidatingProjectCreationValidationListener();
    try (Registration registration = extensionRegistry.newRegistration().add(projectCreationListener)) {
        RestResponse response = adminRestSession.put("/projects/new18");
        assertThat(response.getStatusCode()).isEqualTo(SC_CREATED);
        assertThat(response.getHeader(RestApiServlet.X_GERRIT_TRACE)).isNull();
        assertThat(projectCreationListener.traceId).isNull();
        assertThat(projectCreationListener.isLoggingForced).isFalse();
        // The logging tag with the project name is also set if tracing is off.
        assertThat(projectCreationListener.tags.get("project")).containsExactly("new18");
    }
}
Also used : Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) RestResponse(com.google.gerrit.acceptance.RestResponse) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 52 with Registration

use of com.google.gerrit.acceptance.ExtensionRegistry.Registration in project gerrit by GerritCodeReview.

the class TraceIT method restCallWithTraceRequestParamAndTraceHeader.

@Test
public void restCallWithTraceRequestParamAndTraceHeader() throws Exception {
    TraceValidatingProjectCreationValidationListener projectCreationListener = new TraceValidatingProjectCreationValidationListener();
    try (Registration registration = extensionRegistry.newRegistration().add(projectCreationListener)) {
        // trace ID only specified by trace header
        RestResponse response = adminRestSession.putWithHeaders("/projects/new6?trace", new BasicHeader(RestApiServlet.X_GERRIT_TRACE, "issue/123"));
        assertThat(response.getStatusCode()).isEqualTo(SC_CREATED);
        assertThat(response.getHeader(RestApiServlet.X_GERRIT_TRACE)).isEqualTo("issue/123");
        assertThat(projectCreationListener.traceId).isEqualTo("issue/123");
        assertThat(projectCreationListener.isLoggingForced).isTrue();
        assertThat(projectCreationListener.tags.get("project")).containsExactly("new6");
        // trace ID only specified by trace request parameter
        response = adminRestSession.putWithHeaders("/projects/new7?trace=issue/123", new BasicHeader(RestApiServlet.X_GERRIT_TRACE, null));
        assertThat(response.getStatusCode()).isEqualTo(SC_CREATED);
        assertThat(response.getHeader(RestApiServlet.X_GERRIT_TRACE)).isEqualTo("issue/123");
        assertThat(projectCreationListener.traceId).isEqualTo("issue/123");
        assertThat(projectCreationListener.isLoggingForced).isTrue();
        assertThat(projectCreationListener.tags.get("project")).containsExactly("new7");
        // same trace ID specified by trace header and trace request parameter
        response = adminRestSession.putWithHeaders("/projects/new8?trace=issue/123", new BasicHeader(RestApiServlet.X_GERRIT_TRACE, "issue/123"));
        assertThat(response.getStatusCode()).isEqualTo(SC_CREATED);
        assertThat(response.getHeader(RestApiServlet.X_GERRIT_TRACE)).isEqualTo("issue/123");
        assertThat(projectCreationListener.traceId).isEqualTo("issue/123");
        assertThat(projectCreationListener.isLoggingForced).isTrue();
        assertThat(projectCreationListener.tags.get("project")).containsExactly("new8");
        // different trace IDs specified by trace header and trace request parameter
        response = adminRestSession.putWithHeaders("/projects/new9?trace=issue/123", new BasicHeader(RestApiServlet.X_GERRIT_TRACE, "issue/456"));
        assertThat(response.getStatusCode()).isEqualTo(SC_CREATED);
        assertThat(response.getHeaders(RestApiServlet.X_GERRIT_TRACE)).containsExactly("issue/123", "issue/456");
        assertThat(projectCreationListener.traceIds).containsExactly("issue/123", "issue/456");
        assertThat(projectCreationListener.isLoggingForced).isTrue();
        assertThat(projectCreationListener.tags.get("project")).containsExactly("new9");
    }
}
Also used : Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) RestResponse(com.google.gerrit.acceptance.RestResponse) BasicHeader(org.apache.http.message.BasicHeader) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 53 with Registration

use of com.google.gerrit.acceptance.ExtensionRegistry.Registration in project gerrit by GerritCodeReview.

the class TraceIT method performanceLoggingForPush.

@Test
public void performanceLoggingForPush() throws Exception {
    PerformanceLogger testPerformanceLogger = mock(PerformanceLogger.class);
    try (Registration registration = extensionRegistry.newRegistration().add(testPerformanceLogger)) {
        PushOneCommit push = pushFactory.create(admin.newIdent(), testRepo);
        PushOneCommit.Result r = push.to("refs/heads/master");
        r.assertOkStatus();
        verify(testPerformanceLogger, timeout(5000).atLeastOnce()).log(anyString(), anyLong(), any());
    }
}
Also used : PerformanceLogger(com.google.gerrit.server.logging.PerformanceLogger) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 54 with Registration

use of com.google.gerrit.acceptance.ExtensionRegistry.Registration in project gerrit by GerritCodeReview.

the class TraceIT method traceProjectMatchRegEx.

@Test
@GerritConfig(name = "tracing.issue123.projectPattern", value = "new.*")
public void traceProjectMatchRegEx() throws Exception {
    TraceValidatingProjectCreationValidationListener projectCreationListener = new TraceValidatingProjectCreationValidationListener();
    try (Registration registration = extensionRegistry.newRegistration().add(projectCreationListener)) {
        RestResponse response = adminRestSession.put("/projects/new13");
        assertThat(response.getStatusCode()).isEqualTo(SC_CREATED);
        assertThat(response.getHeader(RestApiServlet.X_GERRIT_TRACE)).isNull();
        assertThat(projectCreationListener.traceId).isEqualTo("issue123");
        assertThat(projectCreationListener.isLoggingForced).isTrue();
        assertThat(projectCreationListener.tags.get("project")).containsExactly("new13");
    }
}
Also used : Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) RestResponse(com.google.gerrit.acceptance.RestResponse) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 55 with Registration

use of com.google.gerrit.acceptance.ExtensionRegistry.Registration in project gerrit by GerritCodeReview.

the class TraceIT method traceAccountNoMatch.

@Test
@GerritConfig(name = "tracing.issue123.account", value = "1000001")
public void traceAccountNoMatch() throws Exception {
    TraceValidatingProjectCreationValidationListener projectCreationListener = new TraceValidatingProjectCreationValidationListener();
    try (Registration registration = extensionRegistry.newRegistration().add(projectCreationListener)) {
        RestResponse response = adminRestSession.put("/projects/new16");
        assertThat(response.getStatusCode()).isEqualTo(SC_CREATED);
        assertThat(response.getHeader(RestApiServlet.X_GERRIT_TRACE)).isNull();
        assertThat(projectCreationListener.traceId).isNull();
        assertThat(projectCreationListener.isLoggingForced).isFalse();
        // The logging tag with the project name is also set if tracing is off.
        assertThat(projectCreationListener.tags.get("project")).containsExactly("new16");
    }
}
Also used : Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) RestResponse(com.google.gerrit.acceptance.RestResponse) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

Registration (com.google.gerrit.acceptance.ExtensionRegistry.Registration)205 Test (org.junit.Test)200 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)194 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)90 AccountIndexedCounter (com.google.gerrit.acceptance.AccountIndexedCounter)47 RestResponse (com.google.gerrit.acceptance.RestResponse)39 GerritConfig (com.google.gerrit.acceptance.config.GerritConfig)38 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)31 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)23 InMemoryRepository (org.eclipse.jgit.internal.storage.dfs.InMemoryRepository)22 TestAccount (com.google.gerrit.acceptance.TestAccount)19 PublicKeyStore.keyToString (com.google.gerrit.gpg.PublicKeyStore.keyToString)19 AccountInfo (com.google.gerrit.extensions.common.AccountInfo)16 RequestCancelledException (com.google.gerrit.server.cancellation.RequestCancelledException)15 Config (org.eclipse.jgit.lib.Config)14 BranchInput (com.google.gerrit.extensions.api.projects.BranchInput)12 CreateProjectArgs (com.google.gerrit.server.project.CreateProjectArgs)11 ProjectCreationValidationListener (com.google.gerrit.server.validators.ProjectCreationValidationListener)11 RevCommit (org.eclipse.jgit.revwalk.RevCommit)11 ImmutableList (com.google.common.collect.ImmutableList)10