You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kafka.apache.org by ij...@apache.org on 2018/01/08 12:14:56 UTC

[kafka] branch trunk updated (9b32639 -> a7e4902)

This is an automated email from the ASF dual-hosted git repository.

ijuma pushed a change to branch trunk
in repository https://gitbox.apache.org/repos/asf/kafka.git.


    omit 9b32639  MINOR: Catch JsonMappingException subclass (#3821)
    omit 3c79527  Catch JsonMappingException subclass
     new a7e4902  MINOR: Catch JsonMappingException subclass (#3821)

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (9b32639)
            \
             N -- N -- N   refs/heads/trunk (a7e4902)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:

-- 
To stop receiving notification emails like this one, please contact
['"commits@kafka.apache.org" <co...@kafka.apache.org>'].

[kafka] 01/01: MINOR: Catch JsonMappingException subclass (#3821)

Posted by ij...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ijuma pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/kafka.git

commit a7e49027b2b95bc8656ee9f419306c559ad1cb5c
Author: Romain Hardouin <ro...@yahoo.fr>
AuthorDate: Sat Sep 9 00:21:00 2017 +0200

    MINOR: Catch JsonMappingException subclass (#3821)
    
    Handle InvalidTypeIdException as NOT_IMPLEMENTED and add unit tests for all exceptions.
    
    Reviewers: Colin P. Mccabe <cm...@confluent.io>, Rajini Sivaram <ra...@googlemail.com>
---
 .../kafka/trogdor/rest/RestExceptionMapper.java    |  4 +-
 .../trogdor/rest/RestExceptionMapperTest.java      | 96 ++++++++++++++++++++++
 2 files changed, 98 insertions(+), 2 deletions(-)

diff --git a/tools/src/main/java/org/apache/kafka/trogdor/rest/RestExceptionMapper.java b/tools/src/main/java/org/apache/kafka/trogdor/rest/RestExceptionMapper.java
index b063a9a..f62a775 100644
--- a/tools/src/main/java/org/apache/kafka/trogdor/rest/RestExceptionMapper.java
+++ b/tools/src/main/java/org/apache/kafka/trogdor/rest/RestExceptionMapper.java
@@ -38,12 +38,12 @@ public class RestExceptionMapper implements ExceptionMapper<Throwable> {
         }
         if (e instanceof NotFoundException) {
             return buildResponse(Response.Status.NOT_FOUND, e);
+        } else if (e instanceof InvalidTypeIdException) {
+            return buildResponse(Response.Status.NOT_IMPLEMENTED, e);
         } else if (e instanceof JsonMappingException) {
             return buildResponse(Response.Status.BAD_REQUEST, e);
         } else if (e instanceof ClassNotFoundException) {
             return buildResponse(Response.Status.NOT_IMPLEMENTED, e);
-        } else if (e instanceof InvalidTypeIdException) {
-            return buildResponse(Response.Status.NOT_IMPLEMENTED, e);
         } else if (e instanceof SerializationException) {
             return buildResponse(Response.Status.BAD_REQUEST, e);
         } else {
diff --git a/tools/src/test/java/org/apache/kafka/trogdor/rest/RestExceptionMapperTest.java b/tools/src/test/java/org/apache/kafka/trogdor/rest/RestExceptionMapperTest.java
new file mode 100644
index 0000000..c40f958
--- /dev/null
+++ b/tools/src/test/java/org/apache/kafka/trogdor/rest/RestExceptionMapperTest.java
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.trogdor.rest;
+
+import static org.junit.Assert.assertEquals;
+
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.databind.JavaType;
+import com.fasterxml.jackson.databind.JsonMappingException;
+import com.fasterxml.jackson.databind.exc.InvalidTypeIdException;
+import javax.ws.rs.NotFoundException;
+import javax.ws.rs.core.Response;
+import org.apache.kafka.common.errors.SerializationException;
+import org.junit.Test;
+
+public class RestExceptionMapperTest {
+
+    @Test
+    public void testToResponseNotFound() {
+        RestExceptionMapper mapper = new RestExceptionMapper();
+        Response resp = mapper.toResponse(new NotFoundException());
+        assertEquals(resp.getStatus(), Response.Status.NOT_FOUND.getStatusCode());
+    }
+
+    @Test
+    public void testToResponseInvalidTypeIdException() {
+        RestExceptionMapper mapper = new RestExceptionMapper();
+        JsonParser parser = null;
+        JavaType type = null;
+        Response resp = mapper.toResponse(InvalidTypeIdException.from(parser, "dummy msg", type, "dummy typeId"));
+        assertEquals(resp.getStatus(), Response.Status.NOT_IMPLEMENTED.getStatusCode());
+    }
+
+    @Test
+    public void testToResponseJsonMappingException() {
+        RestExceptionMapper mapper = new RestExceptionMapper();
+        JsonParser parser = null;
+        Response resp = mapper.toResponse(JsonMappingException.from(parser, "dummy msg"));
+        assertEquals(resp.getStatus(), Response.Status.BAD_REQUEST.getStatusCode());
+    }
+
+    @Test
+    public void testToResponseClassNotFoundException() {
+        RestExceptionMapper mapper = new RestExceptionMapper();
+        Response resp = mapper.toResponse(new ClassNotFoundException());
+        assertEquals(resp.getStatus(), Response.Status.NOT_IMPLEMENTED.getStatusCode());
+    }
+
+    @Test
+    public void testToResponseSerializationException() {
+        RestExceptionMapper mapper = new RestExceptionMapper();
+        Response resp = mapper.toResponse(new SerializationException());
+        assertEquals(resp.getStatus(), Response.Status.BAD_REQUEST.getStatusCode());
+    }
+
+    @Test
+    public void testToResponseUnknownException() {
+        RestExceptionMapper mapper = new RestExceptionMapper();
+        Response resp = mapper.toResponse(new Exception("Unkown exception"));
+        assertEquals(resp.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
+    }
+
+    @Test(expected = NotFoundException.class)
+    public void testToExceptionNotFoundException() throws Exception {
+        RestExceptionMapper.toException(Response.Status.NOT_FOUND.getStatusCode(), "Not Found");
+    }
+
+    @Test(expected = ClassNotFoundException.class)
+    public void testToExceptionClassNotFoundException() throws Exception {
+        RestExceptionMapper.toException(Response.Status.NOT_IMPLEMENTED.getStatusCode(), "Not Implemented");
+    }
+
+    @Test(expected = SerializationException.class)
+    public void testToExceptionSerializationException() throws Exception {
+        RestExceptionMapper.toException(Response.Status.BAD_REQUEST.getStatusCode(), "Bad Request");
+    }
+
+    @Test(expected = RuntimeException.class)
+    public void testToExceptionRuntimeException() throws Exception {
+        RestExceptionMapper.toException(-1, "Unkown status code");
+    }
+}

-- 
To stop receiving notification emails like this one, please contact
"commits@kafka.apache.org" <co...@kafka.apache.org>.