[Reconnoiter-devel] [reconnoiter commit] r1505 - trunk/test/t

svn-commit at lists.omniti.com svn-commit at lists.omniti.com
Wed Dec 8 00:32:28 EST 2010


Author: jesus
Date: 2010-12-08 00:32:28 -0500 (Wed, 08 Dec 2010)
New Revision: 1505

Added:
   trunk/test/t/stomp.pm
Modified:
   trunk/test/t/108_noit_strat.t
   trunk/test/t/testconfig.pm
Log:
update the tests to test the new extended_id stuff. refs #331

Modified: trunk/test/t/108_noit_strat.t
===================================================================
--- trunk/test/t/108_noit_strat.t	2010-12-08 05:31:12 UTC (rev 1504)
+++ trunk/test/t/108_noit_strat.t	2010-12-08 05:32:28 UTC (rev 1505)
@@ -1,18 +1,36 @@
-use Test::More tests => 19;
+use Test::More tests => 26;
 use WWW::Curl::Easy;
+use JSON;
 use XML::LibXML;
 use XML::LibXML::XPathContext;
 use testconfig;
 use apiclient;
+use stomp;
 use Data::Dumper;
 
 use strict;
+my $uuid_re = qr/^[0-9a-fA-F]{4}(?:[0-9a-fA-F]{4}-){4}[0-9a-fA-F]{12}$/;
 my $uuid = '9c2163aa-f4bd-11df-851b-979bd290a553';
 my $xp = XML::LibXML->new();
 my $xpc = XML::LibXML::XPathContext->new();
 
+my $iep_queries = [
+  { id => '52f1f2ec-0275-11e0-a846-b757d1de0f4a',
+    topic => 'numeric',
+    epl => 'select * from NoitMetricNumeric as r'
+  },
+  { id => '8f04d54c-0275-11e0-b62c-6fdd90cb8bde',
+    topic => 'text',
+    epl => 'select * from NoitMetricText as r'
+  },
+  { id => '95f4ed2e-0275-11e0-bdc7-27110e43915b',
+    topic => 'status',
+    epl => 'select * from NoitStatus as r'
+  },
+];
+
 ok(start_noit("108", { logs_debug => { '' => 'false' } }), 'starting noit');
-ok(start_stratcon("108", { noits => [ { address => "127.0.0.1", port => "$NOIT_API_PORT" } ] }), 'starting stratcon');
+ok(start_stratcon("108", { noits => [ { address => "127.0.0.1", port => "$NOIT_API_PORT" } ], iep => { queries => $iep_queries } }), 'starting stratcon');
 sleep(1);
 my $c = apiclient->new('localhost', $NOIT_API_PORT);
 my @r = $c->get("/checks/show/$uuid");
@@ -87,11 +105,51 @@
 $retcode = $curl->perform;
 is($retcode, 28, 'needed to timeout stream');
 
-my @rdata = grep { /^\s*<script id=.*window\.parent\.plot_iframe_data\(\{.*'value':"/ } split(/\R/,$response_body);
+my @rdata;
+my $json_text;
+my $test_S = 0;
+eval {
+  foreach (split(/\R/,$response_body)) {
+    if(/^\s*<script id=.*window\.parent\.plot_iframe_data\((\{.*?\})\)/) {
+      $json_text = $1;
+      my $json = from_json($json_text);
+      push @rdata, $json;
+      if(!$test_S && $json->{type} eq 'S') {
+        like($json->{id}, $uuid_re, 'status line uuid');
+        is($json->{check_module}, 'selfcheck', 'status line module');
+        $test_S = 1;
+      }
+    }
+  }
+};
+if(!$test_S) {
+  ok(0, "status line uuid");
+  ok(0, "status line module");
+}
+is($@, '', 'json parse errors: ' . ($@ ? $json_text : 'none'));
 
 # There are at least 4 metrics for the self check.
 # in 5 seconds - (1 second lag) - jittered start at 500ms period,
 # it should run at least 7 times.
 cmp_ok(scalar(@rdata), '>=', 7*4, 'streamed data');
 
+my $stomp;
+my $payload;
+my $json;
+
+$stomp = stomp->new();
+$stomp->subscribe('/queue/noit.firehose');
+$payload = $stomp->get({timeout => 6});
+undef $stomp;
+ok($payload, 'firehose traffic');
+
+$stomp = stomp->new();
+$stomp->subscribe('/topic/noit.alerts.numeric');
+$payload = $stomp->get({timeout => 6});
+eval { $json = from_json($payload); };
+is($@, '', 'json numeric payload');
+undef $stomp;
+like($json->{r}->{uuid} || '', $uuid_re, 'numeric match has uuid');
+is($json->{r}->{check_module} || '', 'selfcheck', 'modules is set');
+
 1;

Added: trunk/test/t/stomp.pm
===================================================================
--- trunk/test/t/stomp.pm	                        (rev 0)
+++ trunk/test/t/stomp.pm	2010-12-08 05:32:28 UTC (rev 1505)
@@ -0,0 +1,45 @@
+package stomp;
+use strict;
+use Net::Stomp;
+
+sub new {
+    my $class = shift;
+    my $port = shift || 61613;
+    my $stomp = Net::Stomp->new( { hostname => 'localhost', port => '61613'} );
+    $stomp->connect( { login => 'guest', passcode => 'guest' } );
+    return bless { stomp => $stomp }, $class;
+}
+sub subscribe {
+    my $self = shift;
+    my $topic = shift;
+    $self->{stomp}->subscribe(
+        {   destination             => $topic,
+            'ack'                   => 'client',
+            'activemq.prefetchSize' => 1
+        }
+    );
+}
+sub unsubscribe {
+    my $self = shift;
+    my $topic = shift;
+    $self->{stomp}->unsubscribe( { destination => $topic });
+}
+sub get {
+    my $self = shift;
+    my $opts = shift || {};
+    my $frame = $self->{stomp}->receive_frame($opts);
+    return undef unless $frame;
+    my $payload = $frame->body;
+    $self->{stomp}->ack( { frame => $frame } );
+    return $payload;
+}
+sub disconnect {
+    my $self = shift;
+    eval { $self->{stomp}->disconnect(); } if $self->{stomp};
+    delete $self->{stomp};
+}
+sub DESTROY {
+    my $self = shift;
+    $self->disconnect();
+}
+1;

Modified: trunk/test/t/testconfig.pm
===================================================================
--- trunk/test/t/testconfig.pm	2010-12-08 05:31:12 UTC (rev 1504)
+++ trunk/test/t/testconfig.pm	2010-12-08 05:32:28 UTC (rev 1505)
@@ -137,6 +137,7 @@
   print $o qq{
     </components>
     <feeds>
+      <config><extended_id>on</extended_id></config>
       <outlet name="feed"/>
       <log name="check">
         <outlet name="error"/>
@@ -357,6 +358,19 @@
     }
     print $o qq{    </broker>\n};
   }
+  print $o qq{    <queries master="iep">\n};
+  foreach my $s (@{$opts->{iep}->{statements}}) {
+    print $o qq{        <statement id="$s->{id}" provides="$s->{id}">\n};
+    print $o qq{            <requires>$s->{requires}</requires>\n} if $s->{requires};
+    print $o qq{            <epl><![CDATA[$s->{epl}]]></epl>\n};
+    print $o qq{        </statement>\n};
+  }
+  foreach my $s (@{$opts->{iep}->{queries}}) {
+    print $o qq{        <query id="$s->{id}" topic="$s->{topic}">\n};
+    print $o qq{            <epl><![CDATA[$s->{epl}]]></epl>\n};
+    print $o qq{        </query>\n};
+  }
+  print $o qq{    </queries>\n};
   print $o qq{</iep>\n};
 }
 sub make_database_config {



More information about the Reconnoiter-devel mailing list