root/perl/t/1.t

Revision 81ac86a15e3940ff0b787698853fb6a6157f800b, 1.1 kB (checked in by Theo Schlossnagle <jesus@omniti.com>, 7 years ago)

initial import with Ecelerity bits removed and some autoconf glue added in. Could certainly use some work on the build/install. Needs shared lib support for multiple platforms

  • Property mode set to 100644
Line 
1 # Before `make install' is performed this script should be runnable with
2 # `make test'. After `make install' it should work as `perl JLog.t'
3
4 #########################
5
6 use Fcntl;
7 use Test::More tests => 7;
8 BEGIN {
9   use_ok('JLog::Writer');
10   use_ok('JLog::Reader');
11 };
12
13 my $sub = "testsubscriber";
14 my $log = "foo.jlog";
15
16 system("rm -rf $log");
17 my $w = JLog::Writer->new($log, O_CREAT|O_EXCL, 1024);
18 ok !$w->alter_journal_size(1024), "set journal size should fail";
19
20 $w->add_subscriber($sub);
21 $w->open;
22 foreach (1 ... 3) {
23   $w->write("foo $_");
24 }
25 $w->close;
26
27 my $r = JLog::Reader->new($log);
28
29 my @subs = $r->list_subscribers;
30 is_deeply(\@subs, [ $sub ], 'list_subscribers');
31
32 $r->open($sub);
33
34 my @lines;
35 my $i;
36
37 while(my $line = $r->read) {
38   push @lines, $line;
39   $i++;
40 }
41 is_deeply(\@lines, [ 'foo 1', 'foo 2', 'foo 3' ], "in == out");
42
43 # checkpoint
44 undef $r;
45
46 $r = JLog::Reader->new($log);
47 $r->open($sub);
48 @lines = ();
49 $i = 0;
50 while(my $line = $r->read) {
51   push @lines, $line;
52   $i++;
53 }
54 is_deeply(\@lines, [ 'foo 1', 'foo 2', 'foo 3' ], "in == out");
55
56 $r->checkpoint;
57
58 $r = JLog::Reader->new($log);
59 $r->open($sub);
60 is $r->read, undef, "our checkpoint cleared things";
Note: See TracBrowser for help on using the browser.