streams-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sblack...@apache.org
Subject [3/5] incubator-streams git commit: added test for UdpMessagePersister
Date Tue, 17 Feb 2015 19:16:52 GMT
added test for UdpMessagePersister


Project: http://git-wip-us.apache.org/repos/asf/incubator-streams/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-streams/commit/db6400b5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-streams/tree/db6400b5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-streams/diff/db6400b5

Branch: refs/heads/master
Commit: db6400b517f80acf4b904d824b619e05f0d5fae3
Parents: 5667a7e
Author: sblackmon <sblackmon@apache.org>
Authored: Fri Feb 13 09:37:41 2015 -0600
Committer: sblackmon <sblackmon@apache.org>
Committed: Fri Feb 13 09:38:19 2015 -0600

----------------------------------------------------------------------
 .../impl/LogstashUdpMessagePersisterTest.java   | 75 ++++++++++++++++++++
 1 file changed, 75 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/db6400b5/streams-monitoring/src/test/java/org/apache/streams/monitoring/persist/impl/LogstashUdpMessagePersisterTest.java
----------------------------------------------------------------------
diff --git a/streams-monitoring/src/test/java/org/apache/streams/monitoring/persist/impl/LogstashUdpMessagePersisterTest.java
b/streams-monitoring/src/test/java/org/apache/streams/monitoring/persist/impl/LogstashUdpMessagePersisterTest.java
new file mode 100644
index 0000000..faa99a2
--- /dev/null
+++ b/streams-monitoring/src/test/java/org/apache/streams/monitoring/persist/impl/LogstashUdpMessagePersisterTest.java
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.streams.monitoring.persist.impl;
+
+import com.google.common.base.Splitter;
+import com.google.common.collect.Lists;
+import org.junit.Before;
+import org.junit.Test;
+import org.slf4j.Logger;
+
+import java.io.IOException;
+import java.net.DatagramPacket;
+import java.net.DatagramSocket;
+import java.net.SocketException;
+import java.util.List;
+
+import static org.junit.Assert.*;
+
+public class LogstashUdpMessagePersisterTest {
+
+    private static final Logger LOGGER = org.slf4j.LoggerFactory.getLogger(LogstashUdpMessagePersisterTest.class);
+
+    DatagramSocket socket = null;
+
+    @Before
+    public void setup() {
+        try {
+            socket = new DatagramSocket(56789);
+        } catch (SocketException e) {
+            LOGGER.error("Metrics Broadcast Test Setup Failed: " + e.getMessage());
+        }
+    }
+
+
+    @Test
+    public void testFailedPersist() {
+        LogstashUdpMessagePersister persister = new LogstashUdpMessagePersister("udp://127.0.0.1:56789");
+
+        List<String> messageArray = Lists.newArrayList();
+        for(int x = 0; x < 10; x ++) {
+            messageArray.add("Fake_message #" + x);
+        }
+
+        persister.persistMessages(messageArray);
+        byte[] receiveData = new byte[1024];
+
+        DatagramPacket messageDatagram = new DatagramPacket(receiveData, receiveData.length);
+
+        try {
+            socket.receive(messageDatagram);
+            assertNotNull(messageDatagram);
+            List<String> messages = Lists.newArrayList(Splitter.on('\n').split(new
String(messageDatagram.getData())));
+            assertEquals(messageArray, messages.subList(0,10));
+        } catch (IOException e) {
+            LOGGER.error("Metrics Broadcast Test Failed: " + e.getMessage());
+        }
+
+    }
+
+}


Mime
View raw message