From 186eef2261d3b93a102facc01215825b00494ed0 Mon Sep 17 00:00:00 2001 From: groys Date: Wed, 7 Apr 2010 03:36:45 +0000 Subject: [PATCH] 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 --- test/filecat.php | 47 +++++++++++++++++++++++++++++++++++++++++++++++ test/tests.php | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 test/filecat.php diff --git a/test/filecat.php b/test/filecat.php new file mode 100644 index 00000000..2208d3de --- /dev/null +++ b/test/filecat.php @@ -0,0 +1,47 @@ + 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'; + +?> diff --git a/test/tests.php b/test/tests.php index 6948949d..5a2cf4b0 100644 --- a/test/tests.php +++ b/test/tests.php @@ -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) {