Search in sources :

Example 1 with CommitValidationListener

use of com.google.gerrit.server.git.validators.CommitValidationListener 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 2 with CommitValidationListener

use of com.google.gerrit.server.git.validators.CommitValidationListener 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 3 with CommitValidationListener

use of com.google.gerrit.server.git.validators.CommitValidationListener in project gerrit by GerritCodeReview.

the class CancellationIT method handleWrappedRequestCancelledExceptionForPush.

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

        @Override
        public List<CommitValidationMessage> onCommitReceived(CommitReceivedEvent receiveEvent) throws CommitValidationException {
            // 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(commitValidationListener)) {
        PushOneCommit push = pushFactory.create(admin.newIdent(), testRepo);
        PushOneCommit.Result r = push.to("refs/heads/master");
        r.assertErrorStatus("Server Deadline Exceeded (deadline = 10m)");
    }
}
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 CommitValidationListener

use of com.google.gerrit.server.git.validators.CommitValidationListener in project gerrit by GerritCodeReview.

the class CancellationIT method handleClientDeadlineExceededForPush.

@Test
public void handleClientDeadlineExceededForPush() 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.CLIENT_PROVIDED_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("Client Provided 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 5 with CommitValidationListener

use of com.google.gerrit.server.git.validators.CommitValidationListener in project gerrit by GerritCodeReview.

the class CancellationIT method handleRequestCancellationWithMessageForPush.

@Test
public void handleRequestCancellationWithMessageForPush() 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, "deadline = 10m");
        }
    };
    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 (deadline = 10m)");
    }
}
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)

Aggregations

AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)5 Registration (com.google.gerrit.acceptance.ExtensionRegistry.Registration)5 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)5 RequestCancelledException (com.google.gerrit.server.cancellation.RequestCancelledException)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 Test (org.junit.Test)5