Repository: flume Updated Branches: refs/heads/flume-1.6 266f48b5f -> 1c6775c56
FLUME-1793. Unit test TestElasticSearchLogStashEventSerializer fails with IBM JDK (Li Xiang via Hari Shreedharan. Reviewed by Edward Sargisson) Project: http://git-wip-us.apache.org/repos/asf/flume/repo Commit: http://git-wip-us.apache.org/repos/asf/flume/commit/1c6775c5 Tree: http://git-wip-us.apache.org/repos/asf/flume/tree/1c6775c5 Diff: http://git-wip-us.apache.org/repos/asf/flume/diff/1c6775c5 Branch: refs/heads/flume-1.6 Commit: 1c6775c56d5b88d29ee238d2dc9c5127c5880bf7 Parents: 266f48b Author: Hari Shreedharan <[email protected]> Authored: Thu Jul 17 17:33:26 2014 -0700 Committer: Hari Shreedharan <[email protected]> Committed: Thu Jul 17 17:34:55 2014 -0700 ---------------------------------------------------------------------- ...estElasticSearchLogStashEventSerializer.java | 89 +++++++++++--------- 1 file changed, 49 insertions(+), 40 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flume/blob/1c6775c5/flume-ng-sinks/flume-ng-elasticsearch-sink/src/test/java/org/apache/flume/sink/elasticsearch/TestElasticSearchLogStashEventSerializer.java ---------------------------------------------------------------------- diff --git a/flume-ng-sinks/flume-ng-elasticsearch-sink/src/test/java/org/apache/flume/sink/elasticsearch/TestElasticSearchLogStashEventSerializer.java b/flume-ng-sinks/flume-ng-elasticsearch-sink/src/test/java/org/apache/flume/sink/elasticsearch/TestElasticSearchLogStashEventSerializer.java index d2c9543..ab9587d 100644 --- a/flume-ng-sinks/flume-ng-elasticsearch-sink/src/test/java/org/apache/flume/sink/elasticsearch/TestElasticSearchLogStashEventSerializer.java +++ b/flume-ng-sinks/flume-ng-elasticsearch-sink/src/test/java/org/apache/flume/sink/elasticsearch/TestElasticSearchLogStashEventSerializer.java @@ -28,6 +28,9 @@ import org.junit.Test; import java.util.Date; import java.util.Map; +import com.google.gson.JsonParser; +import com.google.gson.JsonElement; + import static org.apache.flume.sink.elasticsearch.ElasticSearchEventSerializer.charset; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import static org.junit.Assert.assertEquals; @@ -53,28 +56,31 @@ public class TestElasticSearchLogStashEventSerializer { Event event = EventBuilder.withBody(message.getBytes(charset)); event.setHeaders(headers); - XContentBuilder expected = jsonBuilder().startObject(); - expected.field("@message", new String(message.getBytes(), charset)); - expected.field("@timestamp", new Date(timestamp)); - expected.field("@source", "flume_tail_src"); - expected.field("@type", "sometype"); - expected.field("@source_host", "test@localhost"); - expected.field("@source_path", "/tmp/test"); - expected.startObject("@fields"); - expected.field("timestamp", String.valueOf(timestamp)); - expected.field("src_path", "/tmp/test"); - expected.field("host", "test@localhost"); - expected.field("headerNameTwo", "headerValueTwo"); - expected.field("source", "flume_tail_src"); - expected.field("headerNameOne", "headerValueOne"); - expected.field("type", "sometype"); - expected.endObject(); - - expected.endObject(); + XContentBuilder expected = jsonBuilder() + .startObject(); + expected.field("@message", new String(message.getBytes(), charset)); + expected.field("@timestamp", new Date(timestamp)); + expected.field("@source", "flume_tail_src"); + expected.field("@type", "sometype"); + expected.field("@source_host", "test@localhost"); + expected.field("@source_path", "/tmp/test"); + + expected.startObject("@fields"); + expected.field("timestamp", String.valueOf(timestamp)); + expected.field("src_path", "/tmp/test"); + expected.field("host", "test@localhost"); + expected.field("headerNameTwo", "headerValueTwo"); + expected.field("source", "flume_tail_src"); + expected.field("headerNameOne", "headerValueOne"); + expected.field("type", "sometype"); + expected.endObject(); + + expected.endObject(); XContentBuilder actual = fixture.getContentBuilder(event); - assertEquals(new String(expected.bytes().array()), new String(actual - .bytes().array())); + + JsonParser parser = new JsonParser(); + assertEquals(parser.parse(expected.string()),parser.parse(actual.string())); } @Test @@ -96,27 +102,30 @@ public class TestElasticSearchLogStashEventSerializer { Event event = EventBuilder.withBody(message.getBytes(charset)); event.setHeaders(headers); - XContentBuilder expected = jsonBuilder().startObject(); - expected.field("@message", new String(message.getBytes(), charset)); - expected.field("@timestamp", new Date(timestamp)); - expected.field("@source", "flume_tail_src"); - expected.field("@type", "sometype"); - expected.field("@source_host", "test@localhost"); - expected.field("@source_path", "/tmp/test"); - expected.startObject("@fields"); - expected.field("timestamp", String.valueOf(timestamp)); - expected.field("src_path", "/tmp/test"); - expected.field("host", "test@localhost"); - expected.field("headerNameTwo", "headerValueTwo"); - expected.field("source", "flume_tail_src"); - expected.field("headerNameOne", "headerValueOne"); - expected.field("type", "sometype"); - expected.endObject(); - - expected.endObject(); + XContentBuilder expected = jsonBuilder(). + startObject(); + expected.field("@message", new String(message.getBytes(), charset)); + expected.field("@timestamp", new Date(timestamp)); + expected.field("@source", "flume_tail_src"); + expected.field("@type", "sometype"); + expected.field("@source_host", "test@localhost"); + expected.field("@source_path", "/tmp/test"); + + expected.startObject("@fields"); + expected.field("timestamp", String.valueOf(timestamp)); + expected.field("src_path", "/tmp/test"); + expected.field("host", "test@localhost"); + expected.field("headerNameTwo", "headerValueTwo"); + expected.field("source", "flume_tail_src"); + expected.field("headerNameOne", "headerValueOne"); + expected.field("type", "sometype"); + expected.endObject(); + + expected.endObject(); XContentBuilder actual = fixture.getContentBuilder(event); - assertEquals(new String(expected.bytes().array()), new String(actual - .bytes().array())); + + JsonParser parser = new JsonParser(); + assertEquals(parser.parse(expected.string()),parser.parse(actual.string())); } }
