flume-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hshreedha...@apache.org
Subject git commit: FLUME-2142. HTTPS tests for http source
Date Mon, 05 Aug 2013 22:16:29 GMT
Updated Branches:
  refs/heads/flume-1.5 19d553678 -> 3b3576ced


FLUME-2142. HTTPS tests for http source

(Ashish Paliwal via Hari Shreedharan)


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

Branch: refs/heads/flume-1.5
Commit: 3b3576ceded622d03f4660fc8a7b4b18652ea406
Parents: 19d5536
Author: Hari Shreedharan <hshreedharan@apache.org>
Authored: Mon Aug 5 15:13:22 2013 -0700
Committer: Hari Shreedharan <hshreedharan@apache.org>
Committed: Mon Aug 5 15:13:22 2013 -0700

----------------------------------------------------------------------
 .../flume/source/http/TestHTTPSource.java       | 63 ++++++++++++++++----
 1 file changed, 51 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flume/blob/3b3576ce/flume-ng-core/src/test/java/org/apache/flume/source/http/TestHTTPSource.java
----------------------------------------------------------------------
diff --git a/flume-ng-core/src/test/java/org/apache/flume/source/http/TestHTTPSource.java
b/flume-ng-core/src/test/java/org/apache/flume/source/http/TestHTTPSource.java
index 6c9fd86..9e14648 100644
--- a/flume-ng-core/src/test/java/org/apache/flume/source/http/TestHTTPSource.java
+++ b/flume-ng-core/src/test/java/org/apache/flume/source/http/TestHTTPSource.java
@@ -42,6 +42,7 @@ import javax.net.ssl.*;
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
 import java.lang.reflect.Type;
+import java.net.HttpURLConnection;
 import java.net.ServerSocket;
 import java.net.URL;
 import java.security.SecureRandom;
@@ -83,12 +84,11 @@ public class TestHTTPSource {
     channel = new MemoryChannel();
 
     httpsSource = new HTTPSource();
-//    httpsChannel = new MemoryChannel();
+    httpsSource.setName("HTTPS Source");
 
     Context ctx = new Context();
     ctx.put("capacity", "100");
     Configurables.configure(channel, ctx);
-//    Configurables.configure(httpsChannel, ctx);
 
     List<Channel> channels = new ArrayList<Channel>(1);
     channels.add(channel);
@@ -100,15 +100,7 @@ public class TestHTTPSource {
 
     channel.start();
 
-    // Channel for HTTPS source
-//    List<Channel> sslChannels = new ArrayList<Channel>(1);
-//    channels.add(httpsChannel);
-//
-//    ChannelSelector sslRcs = new ReplicatingChannelSelector();
-//    rcs.setChannels(sslChannels);
-
     httpsSource.setChannelProcessor(new ChannelProcessor(rcs));
-//    httpsChannel.start();
 
     // HTTP context
     Context context = new Context();
@@ -135,7 +127,6 @@ public class TestHTTPSource {
     source.stop();
     channel.stop();
     httpsSource.stop();
-//    httpsChannel.stop();
   }
 
   @Before
@@ -312,6 +303,7 @@ public class TestHTTPSource {
       for (int j = 0; j < 10; j++) {
         input.put(String.valueOf(i) + String.valueOf(j), String.valueOf(i));
       }
+      input.put("MsgNum", String.valueOf(i));
       JSONEvent e = new JSONEvent();
       e.setHeaders(input);
       e.setBody(String.valueOf(rand.nextGaussian()).getBytes("UTF-8"));
@@ -360,14 +352,61 @@ public class TestHTTPSource {
 
       int statusCode = httpsURLConnection.getResponseCode();
       Assert.assertEquals(200, statusCode);
+
+      Transaction transaction = channel.getTransaction();
+      transaction.begin();
+      for(int i = 0; i < 10; i++) {
+        Event e = channel.take();
+        Assert.assertNotNull(e);
+        Assert.assertEquals(String.valueOf(i), e.getHeaders().get("MsgNum"));
+      }
+
+    transaction.commit();
+    transaction.close();
     } catch (Exception exception) {
       Assert.fail("Exception not expected");
-      exception.printStackTrace();
     } finally {
       httpsURLConnection.disconnect();
     }
   }
 
+  @Test
+  public void testHttpsSourceNonHttpsClient() throws Exception {
+    Type listType = new TypeToken<List<JSONEvent>>() {
+    }.getType();
+    List<JSONEvent> events = Lists.newArrayList();
+    Random rand = new Random();
+    for (int i = 0; i < 10; i++) {
+        Map<String, String> input = Maps.newHashMap();
+        for (int j = 0; j < 10; j++) {
+            input.put(String.valueOf(i) + String.valueOf(j), String.valueOf(i));
+        }
+        input.put("MsgNum", String.valueOf(i));
+        JSONEvent e = new JSONEvent();
+        e.setHeaders(input);
+        e.setBody(String.valueOf(rand.nextGaussian()).getBytes("UTF-8"));
+        events.add(e);
+    }
+    Gson gson = new Gson();
+    String json = gson.toJson(events, listType);
+    HttpURLConnection httpURLConnection = null;
+    try {
+        URL url = new URL("http://0.0.0.0:" + sslPort);
+        httpURLConnection = (HttpURLConnection) url.openConnection();
+        httpURLConnection.setDoInput(true);
+        httpURLConnection.setDoOutput(true);
+        httpURLConnection.setRequestMethod("POST");
+        httpURLConnection.getOutputStream().write(json.getBytes());
+        httpURLConnection.getResponseCode();
+
+        Assert.fail("HTTP Client cannot connect to HTTPS source");
+    } catch (Exception exception) {
+        Assert.assertTrue("Exception expected", true);
+    } finally {
+        httpURLConnection.disconnect();
+    }
+  }
+
   private void takeWithEncoding(String encoding, int n, List<JSONEvent> events)
           throws Exception{
     Transaction tx = channel.getTransaction();


Mime
View raw message