You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2019/01/06 20:46:52 UTC

[GitHub] sijie closed pull request #3313: [Pulsar-Client] Add minor Schema fixes

sijie closed pull request #3313: [Pulsar-Client] Add minor Schema fixes
URL: https://github.com/apache/pulsar/pull/3313
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/AutoProduceBytesSchema.java b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/AutoProduceBytesSchema.java
index 517d53a2fe..6e634c86bc 100644
--- a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/AutoProduceBytesSchema.java
+++ b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/AutoProduceBytesSchema.java
@@ -18,7 +18,6 @@
  */
 package org.apache.pulsar.client.impl.schema;
 
-
 import static com.google.common.base.Preconditions.checkState;
 
 import org.apache.pulsar.client.api.Schema;
diff --git a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/JSONSchema.java b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/JSONSchema.java
index a6e9b051c0..dbcc489014 100644
--- a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/JSONSchema.java
+++ b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/JSONSchema.java
@@ -69,7 +69,6 @@ private JSONSchema(Class<T> pojo, Map<String, String> properties) {
 
     @Override
     public byte[] encode(T message) throws SchemaSerializationException {
-
         try {
             return objectMapper.writeValueAsBytes(message);
         } catch (JsonProcessingException e) {
@@ -82,7 +81,7 @@ public T decode(byte[] bytes) {
         try {
             return objectMapper.readValue(bytes, this.pojo);
         } catch (IOException e) {
-            throw new RuntimeException(new SchemaSerializationException(e));
+            throw new SchemaSerializationException(e);
         }
     }
 
@@ -102,12 +101,12 @@ public SchemaInfo getBackwardsCompatibleJsonSchemaInfo() {
         try {
             ObjectMapper objectMapper = new ObjectMapper();
             JsonSchemaGenerator schemaGen = new JsonSchemaGenerator(objectMapper);
-            JsonSchema jsonBackwardsCompatibileSchema = schemaGen.generateSchema(pojo);
+            JsonSchema jsonBackwardsCompatibleSchema = schemaGen.generateSchema(pojo);
             backwardsCompatibleSchemaInfo = new SchemaInfo();
             backwardsCompatibleSchemaInfo.setName("");
             backwardsCompatibleSchemaInfo.setProperties(properties);
             backwardsCompatibleSchemaInfo.setType(SchemaType.JSON);
-            backwardsCompatibleSchemaInfo.setSchema(objectMapper.writeValueAsBytes(jsonBackwardsCompatibileSchema));
+            backwardsCompatibleSchemaInfo.setSchema(objectMapper.writeValueAsBytes(jsonBackwardsCompatibleSchema));
         } catch (JsonProcessingException ex) {
             throw new RuntimeException(ex);
         }
diff --git a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/generic/GenericJsonSchema.java b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/generic/GenericJsonSchema.java
index d0f2b54233..a82c6c0648 100644
--- a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/generic/GenericJsonSchema.java
+++ b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/generic/GenericJsonSchema.java
@@ -47,7 +47,7 @@ public GenericJsonSchema(SchemaInfo schemaInfo) {
         try {
             return objectMapper.writeValueAsBytes(gjr.getJsonNode().toString());
         } catch (IOException ioe) {
-            throw new RuntimeException(new SchemaSerializationException(ioe));
+            throw new SchemaSerializationException(ioe);
         }
     }
 
@@ -57,7 +57,7 @@ public GenericRecord decode(byte[] bytes) {
             JsonNode jn = objectMapper.readTree(new String(bytes, UTF_8));
             return new GenericJsonRecord(fields, jn);
         } catch (IOException ioe) {
-            throw new RuntimeException(new SchemaSerializationException(ioe));
+            throw new SchemaSerializationException(ioe);
         }
     }
 }
diff --git a/pulsar-client/src/test/java/org/apache/pulsar/client/impl/schema/JSONSchemaTest.java b/pulsar-client/src/test/java/org/apache/pulsar/client/impl/schema/JSONSchemaTest.java
index 1177983501..9184faa459 100644
--- a/pulsar-client/src/test/java/org/apache/pulsar/client/impl/schema/JSONSchemaTest.java
+++ b/pulsar-client/src/test/java/org/apache/pulsar/client/impl/schema/JSONSchemaTest.java
@@ -23,6 +23,7 @@
 
 import lombok.extern.slf4j.Slf4j;
 import org.apache.avro.Schema;
+import org.apache.pulsar.client.api.SchemaSerializationException;
 import org.apache.pulsar.client.impl.schema.JSONSchema;
 import org.apache.pulsar.client.impl.schema.SchemaTestUtils.Bar;
 import org.apache.pulsar.client.impl.schema.SchemaTestUtils.DerivedFoo;
@@ -117,7 +118,6 @@ public void testNestedClasses() {
 
     @Test
     public void testCorrectPolymorphism() {
-
         Bar bar = new Bar();
         bar.setField1(true);
 
@@ -160,8 +160,11 @@ public void testCorrectPolymorphism() {
         JSONSchema<SchemaTestUtils.DerivedDerivedFoo> derivedDerivedJsonSchema
                 = JSONSchema.of(SchemaTestUtils.DerivedDerivedFoo.class);
         Assert.assertEquals(derivedDerivedJsonSchema.decode(derivedDerivedJsonSchema.encode(derivedDerivedFoo)), derivedDerivedFoo);
+    }
 
-
-
+    @Test(expectedExceptions = SchemaSerializationException.class)
+    public void testDecodeWithInvalidContent() {
+        JSONSchema<Foo> jsonSchema = JSONSchema.of(Foo.class);
+        jsonSchema.decode(new byte[0]);
     }
 }
diff --git a/pulsar-common/src/main/java/org/apache/pulsar/common/schema/SchemaInfo.java b/pulsar-common/src/main/java/org/apache/pulsar/common/schema/SchemaInfo.java
index 279b628ad2..c369a3092d 100644
--- a/pulsar-common/src/main/java/org/apache/pulsar/common/schema/SchemaInfo.java
+++ b/pulsar-common/src/main/java/org/apache/pulsar/common/schema/SchemaInfo.java
@@ -41,7 +41,6 @@
     @EqualsAndHashCode.Exclude
     private String name;
 
-
     /**
      * The schema data in AVRO JSON format
      */


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services