/
EventParse.harness
137 lines (115 loc) · 3.68 KB
/
EventParse.harness
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/usr/bin/perl -w
#
# Copyright 2007-2009, Kynetx Inc. All rights reserved.
#
# This Software is an unpublished, proprietary work of Kynetx Inc.
# Your access to it does not grant you any rights, including, but not
# limited to, the right to install, execute, copy, transcribe, reverse
# engineer, or transmit it by any means. Use of this Software is
# governed by the terms of a Software License Agreement transmitted
# separately.
#
# Any reproduction, redistribution, or reverse engineering of the
# Software not in accordance with the License Agreement is expressly
# prohibited by law, and may result in severe civil and criminal
# penalties. Violators will be prosecuted to the maximum extent
# possible.
#
# Without limiting the foregoing, copying or reproduction of the
# Software to any other server or location for further reproduction or
# redistribution is expressly prohibited, unless such reproduction or
# redistribution is expressly permitted by the License Agreement
# accompanying this Software.
#
# The Software is warranted, if at all, only according to the terms of
# the License Agreement. Except as warranted in the License Agreement,
# Kynetx Inc. hereby disclaims all warranties and conditions
# with regard to the software, including all warranties and conditions
# of merchantability, whether express, implied or statutory, fitness
# for a particular purpose, title and non-infringement.
#
use lib qw(/web/lib/perl);
use strict;
use Test::More;
use Test::Deep;
use Log::Log4perl qw(get_logger :levels);
use Data::Dumper;
use APR::Pool ();
use Cache::Memcached;
Log::Log4perl->easy_init($INFO);
Log::Log4perl->easy_init($DEBUG);
use Kynetx::Test qw/:all/;
use Kynetx::JParser qw/:all/;
use Kynetx::Json qw(:all);
use Kynetx::Rules;
use Kynetx::Scheduler;
use Kynetx::FakeReq;
my $r = Kynetx::Test::configure();
my $logger = get_logger();
my $rule_env = Kynetx::Test::gen_rule_env();
my $session = Kynetx::Session::process_session($r);
# grab the test data file names
my @krl_files = @ARGV ? @ARGV : <data/events/expEvent2.krl>;
my $debug = 1;
my @skips = qw(
data/exprs0.krl
data/regexp0.krl
data/regexp1.krl
data/regexp2.krl
data/regexp3.krl
data/regexp4.krl
data/regexp5.krl
data/regexp6.krl
data/regexp7.krl
data/regexp8.krl
data/regexp9.krl
data/counter2.krl
);
my $skip_list;
map {$skip_list->{$_} = 1} @skips;
my $js;
sub gen_req_info {
my ($rid) = @_;
return Kynetx::Test::gen_req_info($rid,
{'ip' => '72.21.203.1',
'txn_id' => 'txn_id',
'caller' => 'http://www.google.com/search', });
}
$logger->debug("Skips: ", sub {Dumper($skip_list)});
my $num_tests = $#krl_files+1;
#my $jparser = Kynetx::JParser::get_antlr_parser();
foreach my $f (@krl_files) {
my ($fl,$krl_text) = getkrl($f);
if ($debug) {
diag $f;
}
if ($skip_list->{$f}) {
diag "Skipping $f";
$num_tests--;
next;
}
#my $ptree = $jparser->ruleset($krl_text);
my $ptree = Kynetx::Parser::parse_ruleset($krl_text);
$logger->debug("Parse tree: ", sub {Dumper($ptree)});
my $ruleset_rid = $ptree->{'ruleset_name'};
my $req_info = gen_req_info($ruleset_rid);
$req_info->{'domain'} = 'pageview';
$req_info->{'eventtype'} = 'prim_event';
Kynetx::Rules::stash_ruleset($req_info,
Kynetx::Rules::optimize_ruleset($ptree));
my $ev = Kynetx::Events::mk_event($req_info);
my $schedule = Kynetx::Scheduler->new();
Kynetx::Events::process_event_for_rid($ev,
$req_info,
$session,
$schedule,
$ruleset_rid);
$js = Kynetx::Rules::process_schedule($r,
$schedule,
$session,
time,
$req_info);
$logger->debug("Javascript: ", $js);
}
plan tests => $num_tests;
1;