flume-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hshreedha...@apache.org
Subject git commit: FLUME-1710. JSONEvent.getBody should not return null
Date Wed, 15 Oct 2014 01:09:31 GMT
Repository: flume
Updated Branches:
  refs/heads/flume-1.6 5093d9818 -> 93ff446ff


FLUME-1710. JSONEvent.getBody should not return null

(Ashish Paliwal via Hari)


Project: http://git-wip-us.apache.org/repos/asf/flume/repo
Commit: http://git-wip-us.apache.org/repos/asf/flume/commit/93ff446f
Tree: http://git-wip-us.apache.org/repos/asf/flume/tree/93ff446f
Diff: http://git-wip-us.apache.org/repos/asf/flume/diff/93ff446f

Branch: refs/heads/flume-1.6
Commit: 93ff446ff00f6044e4b58f4594a47c81caf16ddf
Parents: 5093d98
Author: Hari Shreedharan <hshreedharan@apache.org>
Authored: Tue Oct 14 18:08:52 2014 -0700
Committer: Hari Shreedharan <hshreedharan@apache.org>
Committed: Tue Oct 14 18:09:19 2014 -0700

----------------------------------------------------------------------
 .../src/main/java/org/apache/flume/event/JSONEvent.java   |  4 ++--
 .../java/org/apache/flume/event/TestEventBuilder.java     | 10 +++++++++-
 2 files changed, 11 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flume/blob/93ff446f/flume-ng-sdk/src/main/java/org/apache/flume/event/JSONEvent.java
----------------------------------------------------------------------
diff --git a/flume-ng-sdk/src/main/java/org/apache/flume/event/JSONEvent.java b/flume-ng-sdk/src/main/java/org/apache/flume/event/JSONEvent.java
index 5c6c0d4..0ec1678 100644
--- a/flume-ng-sdk/src/main/java/org/apache/flume/event/JSONEvent.java
+++ b/flume-ng-sdk/src/main/java/org/apache/flume/event/JSONEvent.java
@@ -21,6 +21,7 @@ package org.apache.flume.event;
 import java.io.UnsupportedEncodingException;
 import java.util.Map;
 import org.apache.flume.Event;
+import org.apache.flume.FlumeException;
 
 /**
  *
@@ -46,8 +47,7 @@ public class JSONEvent implements Event{
       try {
         return body.getBytes(charset);
       } catch (UnsupportedEncodingException ex) {
-        //Should never happen
-        return null;
+        throw new FlumeException(String.format("%s encoding not supported", charset), ex);
       }
     } else {
       return new byte[0];

http://git-wip-us.apache.org/repos/asf/flume/blob/93ff446f/flume-ng-sdk/src/test/java/org/apache/flume/event/TestEventBuilder.java
----------------------------------------------------------------------
diff --git a/flume-ng-sdk/src/test/java/org/apache/flume/event/TestEventBuilder.java b/flume-ng-sdk/src/test/java/org/apache/flume/event/TestEventBuilder.java
index 2102770..ad88ce5 100644
--- a/flume-ng-sdk/src/test/java/org/apache/flume/event/TestEventBuilder.java
+++ b/flume-ng-sdk/src/test/java/org/apache/flume/event/TestEventBuilder.java
@@ -23,6 +23,7 @@ import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.flume.Event;
+import org.apache.flume.FlumeException;
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -56,4 +57,11 @@ public class TestEventBuilder {
     Assert.assertEquals("e1 has a one key", "1", e1.getHeaders().get("one"));
   }
 
-}
+  @Test (expected = FlumeException.class)
+  public void testJsonEventUnsupportedEncoding() {
+    JSONEvent jsonEvent = new JSONEvent();
+    jsonEvent.setCharset("dummy");
+    jsonEvent.setBody("This is json event".getBytes());
+    jsonEvent.getBody();
+  }
+}
\ No newline at end of file


Mime
View raw message