Repository: flume Updated Branches: refs/heads/flume-1.6 d5c2cdac0 -> 5600b70a0
FLUME-2488: TestElasticSearchRestClient fails on Oracle JDK 8 (Johny Rufus via Jarek Jarcec Cecho) Project: http://git-wip-us.apache.org/repos/asf/flume/repo Commit: http://git-wip-us.apache.org/repos/asf/flume/commit/5600b70a Tree: http://git-wip-us.apache.org/repos/asf/flume/tree/5600b70a Diff: http://git-wip-us.apache.org/repos/asf/flume/diff/5600b70a Branch: refs/heads/flume-1.6 Commit: 5600b70a09558e84c487c6a8f9f926337ca6c163 Parents: d5c2cda Author: Jarek Jarcec Cecho <[email protected]> Authored: Fri Nov 21 17:28:37 2014 -0800 Committer: Jarek Jarcec Cecho <[email protected]> Committed: Fri Nov 21 17:29:16 2014 -0800 ---------------------------------------------------------------------- .../client/TestElasticSearchRestClient.java | 23 ++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flume/blob/5600b70a/flume-ng-sinks/flume-ng-elasticsearch-sink/src/test/java/org/apache/flume/sink/elasticsearch/client/TestElasticSearchRestClient.java ---------------------------------------------------------------------- diff --git a/flume-ng-sinks/flume-ng-elasticsearch-sink/src/test/java/org/apache/flume/sink/elasticsearch/client/TestElasticSearchRestClient.java b/flume-ng-sinks/flume-ng-elasticsearch-sink/src/test/java/org/apache/flume/sink/elasticsearch/client/TestElasticSearchRestClient.java index b7d8822..1fe983a 100644 --- a/flume-ng-sinks/flume-ng-elasticsearch-sink/src/test/java/org/apache/flume/sink/elasticsearch/client/TestElasticSearchRestClient.java +++ b/flume-ng-sinks/flume-ng-elasticsearch-sink/src/test/java/org/apache/flume/sink/elasticsearch/client/TestElasticSearchRestClient.java @@ -18,6 +18,9 @@ */ package org.apache.flume.sink.elasticsearch.client; +import com.google.common.base.Splitter; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; import org.apache.flume.Event; import org.apache.flume.EventDeliveryException; import org.apache.flume.sink.elasticsearch.ElasticSearchEventSerializer; @@ -30,9 +33,11 @@ import org.mockito.ArgumentCaptor; import org.mockito.Mock; import java.io.IOException; +import java.util.Iterator; import java.util.List; import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertTrue; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.HttpStatus; @@ -102,8 +107,8 @@ public class TestElasticSearchRestClient { verify(httpClient).execute(argument.capture()); assertEquals("http://host1/_bulk", argument.getValue().getURI().toString()); - assertEquals("{\"index\":{\"_type\":\"bar_type\",\"_index\":\"foo_index\"}}\n" + MESSAGE_CONTENT + "\n", - EntityUtils.toString(argument.getValue().getEntity())); + assertTrue(verifyJsonEvents("{\"index\":{\"_type\":\"bar_type\", \"_index\":\"foo_index\"}}\n", + MESSAGE_CONTENT, EntityUtils.toString(argument.getValue().getEntity()))); } @Test @@ -121,8 +126,18 @@ public class TestElasticSearchRestClient { verify(httpClient).execute(argument.capture()); assertEquals("http://host1/_bulk", argument.getValue().getURI().toString()); - assertEquals("{\"index\":{\"_type\":\"bar_type\",\"_index\":\"foo_index\",\"_ttl\":\"123\"}}\n" + - MESSAGE_CONTENT + "\n", EntityUtils.toString(argument.getValue().getEntity())); + assertTrue(verifyJsonEvents("{\"index\":{\"_type\":\"bar_type\",\"_index\":\"foo_index\",\"_ttl\":\"123\"}}\n", + MESSAGE_CONTENT, EntityUtils.toString(argument.getValue().getEntity()))); + } + + private boolean verifyJsonEvents(String expectedIndex, String expectedBody, String actual) { + Iterator<String> it = Splitter.on("\n").split(actual).iterator(); + JsonParser parser = new JsonParser(); + JsonObject[] arr = new JsonObject[2]; + for(int i = 0; i < 2; i++) { + arr[i] = (JsonObject) parser.parse(it.next()); + } + return arr[0].equals(parser.parse(expectedIndex)) && arr[1].equals(parser.parse(expectedBody)); } @Test(expected = EventDeliveryException.class)
