Search in sources :

Example 1 with RequestCancelledException

use of com.google.gerrit.server.cancellation.RequestCancelledException 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 2 with RequestCancelledException

use of com.google.gerrit.server.cancellation.RequestCancelledException 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 3 with RequestCancelledException

use of com.google.gerrit.server.cancellation.RequestCancelledException in project gerrit by GerritCodeReview.

the class CancellationIT method handleServerDeadlineExceededForPush.

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

        @Override
        public List<CommitValidationMessage> onCommitReceived(CommitReceivedEvent receiveEvent) throws CommitValidationException {
            // Simulate an exceeded deadline by throwing RequestCancelledException.
            throw new RequestCancelledException(RequestStateProvider.Reason.SERVER_DEADLINE_EXCEEDED, /* 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("Server Deadline Exceeded");
    }
}
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 4 with RequestCancelledException

use of com.google.gerrit.server.cancellation.RequestCancelledException in project gerrit by GerritCodeReview.

the class SshCancellationIT method handleWrappedRequestCancelledException.

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

        @Override
        public void validateNewProject(CreateProjectArgs args) throws ValidationException {
            throw new RuntimeException(new RequestCancelledException(RequestStateProvider.Reason.SERVER_DEADLINE_EXCEEDED, "deadline = 10m"));
        }
    };
    try (Registration registration = extensionRegistry.newRegistration().add(projectCreationListener)) {
        adminSshSession.exec("gerrit create-project " + name("new"));
        adminSshSession.assertFailure("Server Deadline Exceeded (deadline = 10m)");
    }
}
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 5 with RequestCancelledException

use of com.google.gerrit.server.cancellation.RequestCancelledException in project gerrit by GerritCodeReview.

the class SshCancellationIT method handleServerDeadlineExceeded.

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

        @Override
        public void validateNewProject(CreateProjectArgs args) throws ValidationException {
            throw new RequestCancelledException(RequestStateProvider.Reason.SERVER_DEADLINE_EXCEEDED, /* cancellationMessage= */
            null);
        }
    };
    try (Registration registration = extensionRegistry.newRegistration().add(projectCreationListener)) {
        adminSshSession.exec("gerrit create-project " + name("new"));
        adminSshSession.assertFailure("Server 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)

Aggregations

RequestCancelledException (com.google.gerrit.server.cancellation.RequestCancelledException)16 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)15 Registration (com.google.gerrit.acceptance.ExtensionRegistry.Registration)15 Test (org.junit.Test)15 CreateProjectArgs (com.google.gerrit.server.project.CreateProjectArgs)10 ProjectCreationValidationListener (com.google.gerrit.server.validators.ProjectCreationValidationListener)10 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)5 RestResponse (com.google.gerrit.acceptance.RestResponse)5 CommitReceivedEvent (com.google.gerrit.server.events.CommitReceivedEvent)5 CommitValidationListener (com.google.gerrit.server.git.validators.CommitValidationListener)5 CommitValidationMessage (com.google.gerrit.server.git.validators.CommitValidationMessage)5 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Joiner (com.google.common.base.Joiner)1 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 Splitter (com.google.common.base.Splitter)1 Strings (com.google.common.base.Strings)1 Throwables (com.google.common.base.Throwables)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1