This is an automated email from the ASF dual-hosted git repository.
yufei pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/polaris.git
The following commit(s) were added to refs/heads/main by this push:
new 2f53f77 Using record to simplify class RequestThrottlingErrorResponse
(#320)
2f53f77 is described below
commit 2f53f7746046baea11a3297ee6fb9414ad4004dd
Author: Yufei Gu <[email protected]>
AuthorDate: Wed Sep 25 13:51:26 2024 -0700
Using record to simplify class RequestThrottlingErrorResponse (#320)
---
.../throttling/RequestThrottlingErrorResponse.java | 16 ++--------------
.../throttling/StreamReadConstraintsExceptionMapper.java | 6 +++---
.../service/PolarisApplicationIntegrationTest.java | 7 +++----
3 files changed, 8 insertions(+), 21 deletions(-)
diff --git
a/polaris-service/src/main/java/org/apache/polaris/service/throttling/RequestThrottlingErrorResponse.java
b/polaris-service/src/main/java/org/apache/polaris/service/throttling/RequestThrottlingErrorResponse.java
index 8b1b560..1378753 100644
---
a/polaris-service/src/main/java/org/apache/polaris/service/throttling/RequestThrottlingErrorResponse.java
+++
b/polaris-service/src/main/java/org/apache/polaris/service/throttling/RequestThrottlingErrorResponse.java
@@ -18,28 +18,16 @@
*/
package org.apache.polaris.service.throttling;
-import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
/**
* Response object for errors caused by DoS-prevention throttling mechanisms,
such as request size
* limits
*/
-public class RequestThrottlingErrorResponse {
+public record RequestThrottlingErrorResponse(
+ @JsonProperty("error_type") RequestThrottlingErrorType errorType) {
public enum RequestThrottlingErrorType {
REQUEST_TOO_LARGE,
;
}
-
- private final RequestThrottlingErrorType errorType;
-
- @JsonCreator
- public RequestThrottlingErrorResponse(
- @JsonProperty("error_type") RequestThrottlingErrorType errorType) {
- this.errorType = errorType;
- }
-
- public RequestThrottlingErrorType getErrorType() {
- return errorType;
- }
}
diff --git
a/polaris-service/src/main/java/org/apache/polaris/service/throttling/StreamReadConstraintsExceptionMapper.java
b/polaris-service/src/main/java/org/apache/polaris/service/throttling/StreamReadConstraintsExceptionMapper.java
index b01dca0..27a4f07 100644
---
a/polaris-service/src/main/java/org/apache/polaris/service/throttling/StreamReadConstraintsExceptionMapper.java
+++
b/polaris-service/src/main/java/org/apache/polaris/service/throttling/StreamReadConstraintsExceptionMapper.java
@@ -18,6 +18,8 @@
*/
package org.apache.polaris.service.throttling;
+import static
org.apache.polaris.service.throttling.RequestThrottlingErrorResponse.RequestThrottlingErrorType.REQUEST_TOO_LARGE;
+
import com.fasterxml.jackson.core.exc.StreamConstraintsException;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
@@ -34,9 +36,7 @@ public class StreamReadConstraintsExceptionMapper
public Response toResponse(StreamConstraintsException exception) {
return Response.status(Response.Status.BAD_REQUEST)
.type(MediaType.APPLICATION_JSON_TYPE)
- .entity(
- new RequestThrottlingErrorResponse(
-
RequestThrottlingErrorResponse.RequestThrottlingErrorType.REQUEST_TOO_LARGE))
+ .entity(new RequestThrottlingErrorResponse(REQUEST_TOO_LARGE))
.build();
}
}
diff --git
a/polaris-service/src/test/java/org/apache/polaris/service/PolarisApplicationIntegrationTest.java
b/polaris-service/src/test/java/org/apache/polaris/service/PolarisApplicationIntegrationTest.java
index f116e0e..3795bdd 100644
---
a/polaris-service/src/test/java/org/apache/polaris/service/PolarisApplicationIntegrationTest.java
+++
b/polaris-service/src/test/java/org/apache/polaris/service/PolarisApplicationIntegrationTest.java
@@ -19,6 +19,7 @@
package org.apache.polaris.service;
import static
org.apache.polaris.service.context.DefaultContextResolver.REALM_PROPERTY_KEY;
+import static
org.apache.polaris.service.throttling.RequestThrottlingErrorResponse.RequestThrottlingErrorType.REQUEST_TOO_LARGE;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@@ -694,10 +695,8 @@ public class PolarisApplicationIntegrationTest {
.matches(
r ->
r.readEntity(RequestThrottlingErrorResponse.class)
- .getErrorType()
- .equals(
-
RequestThrottlingErrorResponse.RequestThrottlingErrorType
- .REQUEST_TOO_LARGE));
+ .errorType()
+ .equals(REQUEST_TOO_LARGE));
}
}
}