Search in sources :

Example 36 with Registration

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

the class TraceIT method pushWithTrace.

@Test
public void pushWithTrace() throws Exception {
    TraceValidatingCommitValidationListener commitValidationListener = new TraceValidatingCommitValidationListener();
    try (Registration registration = extensionRegistry.newRegistration().add(commitValidationListener)) {
        PushOneCommit push = pushFactory.create(admin.newIdent(), testRepo);
        push.setPushOptions(ImmutableList.of("trace"));
        PushOneCommit.Result r = push.to("refs/heads/master");
        r.assertOkStatus();
        assertThat(commitValidationListener.traceId).isNotNull();
        assertThat(commitValidationListener.isLoggingForced).isTrue();
        assertThat(commitValidationListener.tags.get("project")).containsExactly(project.get());
    }
}
Also used : Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 37 with Registration

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

the class TraceIT method traceProject.

@Test
@GerritConfig(name = "tracing.issue123.projectPattern", value = "new12")
public void traceProject() throws Exception {
    TraceValidatingProjectCreationValidationListener projectCreationListener = new TraceValidatingProjectCreationValidationListener();
    try (Registration registration = extensionRegistry.newRegistration().add(projectCreationListener)) {
        RestResponse response = adminRestSession.put("/projects/new12");
        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("new12");
    }
}
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 38 with Registration

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

the class CancellationIT method handleServerDeadlineExceeded.

@Test
public void handleServerDeadlineExceeded() throws Exception {
    ProjectCreationValidationListener projectCreationListener = new ProjectCreationValidationListener() {

        @Override
        public void validateNewProject(CreateProjectArgs args) throws ValidationException {
            // Simulate an exceeded deadline by throwing RequestCancelledException.
            throw new RequestCancelledException(RequestStateProvider.Reason.SERVER_DEADLINE_EXCEEDED, /* cancellationMessage= */
            null);
        }
    };
    try (Registration registration = extensionRegistry.newRegistration().add(projectCreationListener)) {
        RestResponse response = adminRestSession.put("/projects/" + name("new"));
        assertThat(response.getStatusCode()).isEqualTo(SC_REQUEST_TIMEOUT);
        assertThat(response.getEntityContent()).isEqualTo("Server Deadline Exceeded");
    }
}
Also used : ProjectCreationValidationListener(com.google.gerrit.server.validators.ProjectCreationValidationListener) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) RestResponse(com.google.gerrit.acceptance.RestResponse) RequestCancelledException(com.google.gerrit.server.cancellation.RequestCancelledException) CreateProjectArgs(com.google.gerrit.server.project.CreateProjectArgs) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 39 with Registration

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

the class CancellationIT method handleClientDisconnectedForPush.

@Test
public void handleClientDisconnectedForPush() throws Exception {
    CommitValidationListener commitValidationListener = new CommitValidationListener() {

        @Override
        public List<CommitValidationMessage> onCommitReceived(CommitReceivedEvent receiveEvent) throws CommitValidationException {
            // to the client.
            throw new RequestCancelledException(RequestStateProvider.Reason.CLIENT_CLOSED_REQUEST, /* cancellationMessage= */
            null);
        }
    };
    try (Registration registration = extensionRegistry.newRegistration().add(commitValidationListener)) {
        PushOneCommit push = pushFactory.create(admin.newIdent(), testRepo);
        PushOneCommit.Result r = push.to("refs/heads/master");
        r.assertErrorStatus("Client Closed Request");
    }
}
Also used : CommitValidationListener(com.google.gerrit.server.git.validators.CommitValidationListener) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) CommitReceivedEvent(com.google.gerrit.server.events.CommitReceivedEvent) RequestCancelledException(com.google.gerrit.server.cancellation.RequestCancelledException) CommitValidationMessage(com.google.gerrit.server.git.validators.CommitValidationMessage) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 40 with Registration

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

the class CancellationIT method exceededDeadlineForOneRequestDoesntAbortFollowUpRequest.

@Test
@GerritConfig(name = "deadline.default.timeout", value = "500ms")
public void exceededDeadlineForOneRequestDoesntAbortFollowUpRequest() throws Exception {
    ProjectCreationValidationListener projectCreationValidationListener = new ProjectCreationValidationListener() {

        @Override
        public void validateNewProject(CreateProjectArgs args) throws ValidationException {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException("interrupted during sleep", e);
            }
        }
    };
    try (Registration registration = extensionRegistry.newRegistration().add(projectCreationValidationListener)) {
        RestResponse response = adminRestSession.putWithHeaders("/projects/" + name("new"));
        assertThat(response.getStatusCode()).isEqualTo(SC_REQUEST_TIMEOUT);
        assertThat(response.getEntityContent()).isEqualTo("Server Deadline Exceeded\n\ndefault.timeout=500ms");
    }
    // verify that the exceeded deadline for the previous request, isn't applied to a new request
    RestResponse response = adminRestSession.putWithHeaders("/projects/" + name("new2"));
    response.assertCreated();
}
Also used : ProjectCreationValidationListener(com.google.gerrit.server.validators.ProjectCreationValidationListener) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) RestResponse(com.google.gerrit.acceptance.RestResponse) CreateProjectArgs(com.google.gerrit.server.project.CreateProjectArgs) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

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