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 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
|
<?php
class TestLogFiles extends UnitTestCase {
var $syslogParser;
var $logStream;
function setup() {
$this->syslogParser = new SyslogPostgreSQLParser();
$this->logStream = new LogStream();
}
function getLinesFromFile($fileName) {
$filePath = 'logs/TestLogFiles/'.$fileName;
if(is_readable($filePath)) {
$lines = file($filePath);
} else {
$lines = array();
}
return $lines;
}
function testDoubleDuration() {
$textLines = $this->getLinesFromFile('test_double_duration.log');
$step = 0;
foreach($textLines AS $textLine) {
$line =& $this->syslogParser->parse($textLine);
$logObject =& $this->logStream->append($line);
switch($step) {
case 0:
$this->checkLine($line, 'PostgreSQLDurationLine', '1168355794', '30059', '12', '1', '', '3.617465');
$this->assertFalse($logObject);
break;
case 1:
$this->checkLine($line, 'PostgreSQLQueryStartWithDurationLine', '1168355794', '30059', '13', '1', 'select', '3.617465');
$this->assertFalse($logObject);
break;
case 2:
$this->checkLine($line, 'PostgreSQLContinuationLine', '1168355794', '30059', '13', '2', " t.tid,t.title,m.name,gn.name,to_char( t.retail_reldate, 'mm-dd-yy' ) as retail_reldate,coalesce(s0c100r0.units,0) as", false);
$this->assertFalse($logObject);
break;
case 3:
$this->checkLine($line, 'PostgreSQLContinuationLine', '1168355794', '30059', '13', '3', " w0c100r0units,'NA' as w0c100r0dollars,'NA' as w0c100r0arp,coalesce(s0c1r0.units,0) as w0c1r0units,'NA' as w0c1r0dollars,'NA' as", false);
$this->assertFalse($logObject);
break;
case 4:
$this->checkLine($line, 'PostgreSQLContinuationLine', '1168355794', '30059', '13', '4', " w0c1r0arp,coalesce(s0c2r0.units,0) as w0c2r0units,coalesce(s0c2r0.dollars,0) as w0c2r0dollars,arp(s0c2r0.dollars, s0c2r0.units)", false);
$this->assertFalse($logObject);
break;
case 5:
$this->checkLine($line, 'PostgreSQLContinuationLine', '1168355794', '30059', '13', '5', " as w0c2r0arp from title t left outer join sublabel sl on t.sublabel_rel = sl.key left outer join label s on sl.lid = s.id left", false);
$this->assertFalse($logObject);
break;
case 6:
$this->checkLine($line, 'PostgreSQLContinuationLine', '1168355794', '30059', '13', '6', " outer join label d on s.did = d.id left outer join sale_200601 s0c100r0 on t.tid = s0c100r0.tid and s0c100r0.week = 200601 and", false);
$this->assertFalse($logObject);
break;
case 7:
$this->checkLine($line, 'PostgreSQLContinuationLine', '1168355794', '30059', '13', '7', " s0c100r0.channel = 100 and s0c100r0.region = 0 left outer join sale_200601 s0c1r0 on t.tid = s0c1r0.tid and s0c1r0.week =", false);
$this->assertFalse($logObject);
break;
case 8:
$this->checkLine($line, 'PostgreSQLContinuationLine', '1168355794', '30059', '13', '8', " 200601 and s0c1r0.channel = 1 and s0c1r0.region = 0 left outer join sale_200601 s0c2r0 on t.tid = s0c2r0.tid and s0c2r0.week =", false);
$this->assertFalse($logObject);
break;
case 9:
$this->checkLine($line, 'PostgreSQLContinuationLine', '1168355794', '30059', '13', '9', " 200601 and s0c2r0.channel = 2 and s0c2r0.region = 0 left outer join media m on t.media = m.key left outer join genre_n gn on", false);
$this->assertFalse($logObject);
break;
case 10:
$this->checkLine($line, 'PostgreSQLContinuationLine', '1168355794', '30059', '13', '10', " t.genre_n = gn.key where ((((upper(t.title) like '%MATRIX%' or upper(t.artist) like '%MATRIX%') ))) and t.blob in ('L', 'M',", false);
$this->assertFalse($logObject);
break;
case 11:
$this->checkLine($line, 'PostgreSQLContinuationLine', '1168355794', '30059', '13', '11', " 'R') and t.source_dvd != 'IN' order by t.title asc limit 100", false);
$this->assertFalse($logObject);
break;
case 12:
$this->checkLine($line, 'PostgreSQLDurationLine', '1168355794', '30059', '14', '1', '', '0.003358');
$this->checkQueryLogObject($logObject,
'QueryLogObject',
1168355794,
13,
"select t.tid,t.title,m.name,gn.name,to_char( t.retail_reldate, 'mm-dd-yy' ) as retail_reldate,coalesce(s0c100r0.units,0) as w0c100r0units,'NA' as w0c100r0dollars,'NA' as w0c100r0arp,coalesce(s0c1r0.units,0) as w0c1r0units,'NA' as w0c1r0dollars,'NA' as w0c1r0arp,coalesce(s0c2r0.units,0) as w0c2r0units,coalesce(s0c2r0.dollars,0) as w0c2r0dollars,arp(s0c2r0.dollars, s0c2r0.units) as w0c2r0arp from title t left outer join sublabel sl on t.sublabel_rel = sl.key left outer join label s on sl.lid = s.id left outer join label d on s.did = d.id left outer join sale_200601 s0c100r0 on t.tid = s0c100r0.tid and s0c100r0.week = 200601 and s0c100r0.channel = 100 and s0c100r0.region = 0 left outer join sale_200601 s0c1r0 on t.tid = s0c1r0.tid and s0c1r0.week = 200601 and s0c1r0.channel = 1 and s0c1r0.region = 0 left outer join sale_200601 s0c2r0 on t.tid = s0c2r0.tid and s0c2r0.week = 200601 and s0c2r0.channel = 2 and s0c2r0.region = 0 left outer join media m on t.media = m.key left outer join genre_n gn on t.genre_n = gn.key where ((((upper(t.title) like '%MATRIX%' or upper(t.artist) like '%MATRIX%') ))) and t.blob in ('L', 'M', 'R') and t.source_dvd != 'IN' order by t.title asc limit 100",
'3.617465');
break;
case 13:
$this->checkLine($line, 'PostgreSQLDurationLine', '1168355796', '30059', '15', '1', '', '1.98246');
$this->checkQueryLogObject($logObject,
'DurationLogObject',
1168355794,
14,
false,
'0.003358');
break;
case 14:
$this->checkLine($line, 'PostgreSQLQueryStartWithDurationLine', '1168355796', '30059', '16', '1', 'select sum(coalesce(s0c100r0.units,0)) as', '1.98246');
$this->assertFalse($logObject);
break;
case 15:
$this->checkLine($line, 'PostgreSQLContinuationLine', '1168355796', '30059', '16', '2', " w0c100r0units,'' as w0c100r0dollars,'' as w0c100r0arp,sum(coalesce(s0c1r0.units,0)) as w0c1r0units,'' as w0c1r0dollars,'' as", false);
$this->assertFalse($logObject);
break;
case 16:
$this->checkLine($line, 'PostgreSQLContinuationLine', '1168355796', '30059', '16', '3', " w0c1r0arp,sum(coalesce(s0c2r0.units,0)) as w0c2r0units,sum(coalesce(s0c2r0.dollars,0)) as w0c2r0dollars,NULL as w0c2r0arp from", false);
$this->assertFalse($logObject);
break;
case 17:
$this->checkLine($line, 'PostgreSQLContinuationLine', '1168355796', '30059', '16', '4', " title t left outer join sublabel sl on t.sublabel_rel = sl.key left outer join label s on sl.lid = s.id left outer join label d", false);
$this->assertFalse($logObject);
break;
case 18:
$this->checkLine($line, 'PostgreSQLContinuationLine', '1168355796', '30059', '16', '5', " on s.did = d.id left outer join sale_200601 s0c100r0 on t.tid = s0c100r0.tid and s0c100r0.week = 200601 and s0c100r0.channel =", false);
$this->assertFalse($logObject);
break;
case 19:
$this->checkLine($line, 'PostgreSQLContinuationLine', '1168355796', '30059', '16', '6', " 100 and s0c100r0.region = 0 left outer join sale_200601 s0c1r0 on t.tid = s0c1r0.tid and s0c1r0.week = 200601 and", false);
$this->assertFalse($logObject);
break;
case 20:
$this->checkLine($line, 'PostgreSQLContinuationLine', '1168355796', '30059', '16', '7', " s0c1r0.channel = 1 and s0c1r0.region = 0 left outer join sale_200601 s0c2r0 on t.tid = s0c2r0.tid and s0c2r0.week = 200601 and", false);
$this->assertFalse($logObject);
break;
case 21:
$this->checkLine($line, 'PostgreSQLContinuationLine', '1168355796', '30059', '16', '8', " s0c2r0.channel = 2 and s0c2r0.region = 0 where ((((upper(t.title) like '%MATRIX%' or upper(t.artist) like '%MATRIX%') ))) and", false);
$this->assertFalse($logObject);
break;
case 22:
$this->checkLine($line, 'PostgreSQLContinuationLine', '1168355796', '30059', '16', '9', " t.blob in ('L', 'M', 'R') and t.source_dvd != 'IN'", false);
$this->assertFalse($logObject);
break;
default:
stderrArray($line);
break;
}
unset($line);
unset($logObject);
$step ++;
}
}
function checkLine(& $line, $type, $timestamp, $connectionId, $commandNumber, $lineNumber, $text, $duration, $ignore = false, $database = false, $user = false) {
$this->assertIsA($line, $type);
$this->assertEqual($timestamp, $line->getTimestamp());
$this->assertEqual($connectionId, $line->getConnectionId());
$this->assertEqual($commandNumber, $line->getCommandNumber());
$this->assertEqual($lineNumber, $line->getLineNumber());
$this->assertEqual($text, $line->getText());
$this->assertEqual(0, bccomp($duration, $line->getDuration()));
$this->assertEqual($ignore, $line->isIgnored());
$this->assertEqual($database, $line->getDatabase());
$this->assertEqual($user, $line->getUser());
}
function checkQueryLogObject(& $logObject, $type, $timestamp, $commandNumber, $text, $duration, $ignored = false, $database = false, $user = false, $context = false, $subQueries = array()) {
$this->assertIsA($logObject, $type);
$this->assertEqual($timestamp, $logObject->getTimestamp());
$this->assertEqual($commandNumber, $logObject->getCommandNumber());
$this->assertEqual($text, $logObject->getText());
$this->assertEqual(0, bccomp($duration, $logObject->getDuration()));
$this->assertEqual($ignored, $logObject->isIgnored());
$this->assertEqual($database, $logObject->getDatabase());
$this->assertEqual($user, $logObject->getUser());
$this->assertEqual($context, $logObject->getContext());
if($type == 'QueryLogObject') {
$this->assertEqual($subQueries, $logObject->getSubQueries());
}
}
}
?>
|