Permalink
Browse files

Add a filecat test

Summary:
A simple test that will send a file to the required scribe
server. This can help verifying that there is no data loss while testing
"a one scribe server sending to another scribe server" scenario. Also
lets get the required path in tests.php. For opensourcing I will add it
to the script to revert those lines

Test Plan:
tested that this works

DiffCamp Revision: 103042
Reviewed By: pkhemani
CC: pkhemani, groys
Revert Plan:
OK

git-svn-id: svn+ssh://tubbs/svnapps/fbomb/trunk/fbcode/scribe@25476 2248de34-8caa-4a3c-bc55-5e52d9d7b73a
  • Loading branch information...
groys groys
groys authored and groys committed Apr 7, 2010
1 parent 8c51959 commit 186eef2261d3b93a102facc01215825b00494ed0
Showing with 94 additions and 0 deletions.
  1. +47 −0 test/filecat.php
  2. +47 −0 test/tests.php
View
@@ -0,0 +1,47 @@
+<?php
+// Copyright (c) 2007-2008 Facebook
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// 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.
+//
+// See accompanying file LICENSE or visit the Scribe site at:
+// http://developers.facebook.com/scribe/
+
+/* File cat test
+ * Read file, $file line by line send to scribe at localhost:1463
+ * with a category name = $category each line becomes a message.
+ * messages are sent at a rate of $rate messages per second
+ */
+
+require_once 'tests.php';
+
+function printUsage() {
+ echo "Usage $arg[0] pathtofile [categoryname]";
+}
+
+if ($argc > 2) {
+ $file = $argv[1];
+ $category = $argv[2];
+} else if ($argc > 1) {
+ $file = $argv[1];
+ $category = "filecattest";
+} else {
+ printUsage();
+}
+
+print 'starting test...';
+$rate = 10000;
+$msg_per_call = 20;
+file_cat($file, $category, $rate, $msg_per_call);
+print 'done';
+
+?>
View
@@ -113,6 +113,53 @@ function strange_input_test() {
print "Log returned: " . $ret . "\n";
}
+/* Read file, $file line by line send to scribe at localhost:1463
+ * with a category name = $category each line becomes a message.
+ * messages are sent at a rate of $rate messages per second
+ */
+function file_cat($file, $category, $rate, $msg_per_call) {
+
+ $send_interval = $msg_per_call/$rate;
+
+ $scribe_client = create_scribe_client();
+
+ $lines = file($file);
+
+ $messages = array();
+ $msgs_since_send = 0;
+ $last_send_time = microtime(true);
+
+ foreach ($lines as $line_num => $line) {
+ $entry = new LogEntry;
+ $entry->category = $category;
+ $entry->message = $line;
+ $messages []= $entry;
+ ++$msgs_since_send;
+
+ if ($msgs_since_send >= $msg_per_call) {
+
+ $msgs_since_send = 0;
+ $ret = scribe_Log_test($messages, $scribe_client);
+ // Print_r($messages);
+ $messages = array();
+
+ $now = microtime(true);
+ $wait = $last_send_time + $send_interval - $now;
+ $last_send_time = $now;
+ if ($wait > 0) {
+ usleep($wait * 1000000);
+ }
+ }
+ }
+ $ret = scribe_Log_test($messages, $scribe_client);
+ // Print_r($messages);
+}
+
+
+/* Send a total of $total messages at the rate of $rate per second
+ * let messages have an avg_size of $avg_size
+ *
+ */
function stress_test($category, $client_name, $rate, $total, $msg_per_call,
$avg_size, $num_categories) {

0 comments on commit 186eef2

Please sign in to comment.