Search in sources :

Example 11 with CreateProjectArgs

use of com.google.gerrit.server.project.CreateProjectArgs in project gerrit by GerritCodeReview.

the class SshCancellationIT method handleClientDeadlineExceeded.

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

        @Override
        public void validateNewProject(CreateProjectArgs args) throws ValidationException {
            throw new RequestCancelledException(RequestStateProvider.Reason.CLIENT_PROVIDED_DEADLINE_EXCEEDED, /* cancellationMessage= */
            null);
        }
    };
    try (Registration registration = extensionRegistry.newRegistration().add(projectCreationListener)) {
        adminSshSession.exec("gerrit create-project " + name("new"));
        adminSshSession.assertFailure("Client Provided Deadline Exceeded");
    }
}
Also used : ProjectCreationValidationListener(com.google.gerrit.server.validators.ProjectCreationValidationListener) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) RequestCancelledException(com.google.gerrit.server.cancellation.RequestCancelledException) CreateProjectArgs(com.google.gerrit.server.project.CreateProjectArgs) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 12 with CreateProjectArgs

use of com.google.gerrit.server.project.CreateProjectArgs in project gerrit by GerritCodeReview.

the class CancellationIT method handleClientDeadlineExceeded.

@Test
public void handleClientDeadlineExceeded() 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.CLIENT_PROVIDED_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("Client Provided 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 13 with CreateProjectArgs

use of com.google.gerrit.server.project.CreateProjectArgs in project gerrit by GerritCodeReview.

the class CancellationIT method handleWrappedRequestCancelledException.

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

        @Override
        public void validateNewProject(CreateProjectArgs args) throws ValidationException {
            // Simulate an exceeded deadline by throwing RequestCancelledException.
            throw new RuntimeException(new RequestCancelledException(RequestStateProvider.Reason.SERVER_DEADLINE_EXCEEDED, "deadline = 10m"));
        }
    };
    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\n\ndeadline = 10m");
    }
}
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)

Aggregations

CreateProjectArgs (com.google.gerrit.server.project.CreateProjectArgs)13 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)11 Registration (com.google.gerrit.acceptance.ExtensionRegistry.Registration)11 ProjectCreationValidationListener (com.google.gerrit.server.validators.ProjectCreationValidationListener)11 Test (org.junit.Test)11 RequestCancelledException (com.google.gerrit.server.cancellation.RequestCancelledException)10 RestResponse (com.google.gerrit.acceptance.RestResponse)6 GerritConfig (com.google.gerrit.acceptance.config.GerritConfig)1 RefNames (com.google.gerrit.entities.RefNames)1 ConfigInput (com.google.gerrit.extensions.api.projects.ConfigInput)1 ProjectInput (com.google.gerrit.extensions.api.projects.ProjectInput)1 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)1 IdString (com.google.gerrit.extensions.restapi.IdString)1 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)1 ProjectState (com.google.gerrit.server.project.ProjectState)1 ValidationException (com.google.gerrit.server.validators.ValidationException)1 Lock (java.util.concurrent.locks.Lock)1 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)1