Cluster-Init
view release on metacpan or search on metacpan
lib/Cluster/Init/Conf.pm view on Meta::CPAN
{
my $self=shift;
my $cltab = $self->{'cltab'};
unless (-f $cltab)
{
warn "file not found: $cltab\n";
$self->{msg}="file not found: $cltab\n";
$self->{ok}=1;
return $self->{ok};
}
my $mtime=(stat($cltab))[9] || die $!;
$self->{'cltab_mtime'} = 0 unless $self->{'cltab_mtime'};
return $self->{ok} unless $mtime > $self->{'cltab_mtime'};
$self->{'cltab_mtime'} = $mtime;
debug "reading cltab $cltab, PWD is $ENV{PWD}";
my @tag;
$self->{ok}=1;
$self->{raw}=[];
open(ITAB,"<$cltab") || die $!;
while(<ITAB>)
{
lib/Cluster/Init/DFA/Daemon.pm view on Meta::CPAN
HALTALL => '$self->haltall(@arg)', # HALTED
PUTRES => '$self->putres(@arg)', # HALTTIME SOCKET_ERROR
# WRITETIME
READ_CLTAB => '$self->read_cltab(@arg)', # CLTAB_NOK CLTAB_OK
# IDLE
START_LISTENER => '$self->start_listener(@arg)', # SOCKET_ERROR
# WRITETIME
TELLGROUP => '$self->tellgroup(@arg)', # GROUPTOLD GROUP_NOK
# SHUTDOWN
WATCH_CLIENT => '$self->watch_client(@arg)', # TIMEOUT
WRITESTAT => '$self->writestat(@arg)', # SOCKET_ERROR
# WRITETIME
);
my %const2act = DFA_ACTIONS;
# States
# use constant State => Value; # Events it can handle
#
use constant ACCEPT => 'ACCEPT'; # CLIENTIO TIMEOUT
lib/Cluster/Init/Daemon.pm view on Meta::CPAN
clstat=>$self->conf('clstat')
);
# debug dump $self;
return $self;
}
sub writestat
{
my $self=shift;
my $status=$self->{status};
$status->writestat(@_);
return '';
}
sub conf
{
my $self=shift;
my $var=shift;
return $self->{conf}->get($var);
}
exit;
}
run(1);
my $init = client Cluster::Init (%parms);
`cat /dev/null > t/out`;
ok(lines(),0);
$init->tell("hellogrp",1);
ok(waitstat($init,"hellogrp",1,"DONE"));
$init->tell("hellogrp","3");
ok(waitstat($init,"hellogrp",3,"STARTING"));
ok($init->status(group=>"hellogrp",level=>"3"),"STARTING");
ok(lines(),1);
ok(waitstat($init,"hellogrp",3,"DONE"));
ok(lines(),0);
$init->tell("hellogrp",1);
ok(waitstat($init,"hellogrp",1,"DONE"));
ok(lines(),1);
`cat /dev/null > t/out`;
ok(lines(),0);
$init->tell("hellogrp",1);
run(1);
ok(lines(),0);
$init->shutdown();
ok(1);
{
my $init = daemon Cluster::Init (%parms);
exit;
}
run(1);
my $init = client Cluster::Init (%parms);
`cat /dev/null > t/out`;
ok(lines(),0);
$init->tell("hellogrp","long1");
ok(waitstat($init,"hellogrp","long1","DONE"));
ok(lines(),1);
ok(lastline(),"long");
$init->tell("hellogrp","long3");
ok(waitstat($init,"hellogrp","long3","DONE"));
ok(lines(),1);
ok(lastline(),"long3");
$init->tell("hellogrp","long2");
ok(waitstat($init,"hellogrp","long2","DONE"));
ok(lines(),1);
ok(lastline(),"long");
$init->tell("hellogrp","long3");
ok(waitstat($init,"hellogrp","long3","DONE"));
ok(lines(),1);
ok(lastline(),"long3");
$init->tell("hellogrp","5");
ok(waitstat($init,"hellogrp","5","DONE"));
ok(lines(),1);
ok(lastline(),"long");
$init->shutdown();
ok(1);
t/40respawn.t view on Meta::CPAN
my $pid=lastline();
# warn "$pid";
sleep 1;
ok(kill(9,$pid),1);
sleep 5;
ok(lines(),1);
my $newpid=lastline();
# warn "$pid, $newpid";
ok(sub{return 1 if $pid != $newpid},1);
$init->tell("pidgrp",99);
ok(waitstat($init,"pidgrp",99,"DONE"));
`cat /dev/null > t/out`;
ok(lines(),0);
warn "\nyou should see a 'respawning too rapidly' message on the next line:\n";
$init->tell("hellogrp",2);
sleep 1 while(lines() < 5);
my $lines=lines();
ok($lines>=5);
ok($lines<=10);
sleep 5;
t/47reread.t view on Meta::CPAN
exit;
}
sleep 1;
my $init = Cluster::Init->client(%parms);
`cat /dev/null > t/out`;
ok(lines(),0);
$init->tell("pidgrp",1);
ok(waitstat($init,"pidgrp",1,"DONE"));
ok(lines(),1);
my $pid=lastline();
`cp t/cltab t/cltab.sav`;
`echo "scram:scram2:1:wait:sleep 1" > t/cltab`;
$init->tell("scram",1);
ok(waitstat($init,"scram",1,"DONE"));
my $pide=lastline();
ok($pide,$pid);
sleep 10;
my $pidf=lastline();
ok($pide,$pidf);
`cp t/cltab.sav t/cltab`;
$init->tell("pidgrp",1);
ok(waitstat($init,"pidgrp",1,"DONE"));
my $pidg=lastline();
ok(kill(0,$pidg),1);
$init->shutdown();
ok(1);
unless (fork())
{
my $init = Cluster::Init->daemon(%parms);
exit;
}
sleep 1;
my $init = Cluster::Init->client(%parms);
`echo 'offgrp:off1:1:once:echo \$\$ > t/out; sleep 30' > t/cltab`;
$init->tell("offgrp",1);
ok(waitstat($init,"offgrp",1,"DONE"));
ok(lines(),1);
my $pid=lastline();
ok(kill(0,$pid),1);
`echo 'offgrp:off1:1:off:echo \$\$ > t/out; sleep 30' > t/cltab`;
$init->tell("offgrp",1);
sleep 1;
my $pidb=lastline();
ok($pidb,$pid);
# system("ps -eaf | tail");
ok(kill(0,$pid),0);
t/60multichar.t view on Meta::CPAN
my $init = Cluster::Init->daemon(%parms);
exit;
}
sleep 1;
my $init = Cluster::Init->client(%parms);
`cat /dev/null > t/out`;
ok(lines(),0);
$init->tell("foogrp",1);
ok(waitstat($init,"foogrp",1,"DONE"));
ok(lastline(),"foo1start");
$init->tell("foogrp",2);
ok(waitstat($init,"foogrp",2,"DONE"));
ok(lastline(),"foo1start");
ok(waitline("foo1end"));
$init->tell("foogrp",99);
ok(waitstat($init,"foogrp",99,"DONE"));
$init->tell("foogrp",1);
ok(waitstat($init,"foogrp",1,"DONE"));
ok(waitline("foo1start"));
ok(lines(),1);
$init->tell("foogrp",3);
ok(waitstat($init,"foogrp",3,"DONE"));
ok(waitline("foo3"));
ok(lines(),1);
sleep 7;
ok(waitline("foo3"));
ok(lines(),1);
$init->shutdown();
ok(1);
__END__
t/70clinit.t view on Meta::CPAN
`cat /dev/null > t/out`;
ok(lines(),0);
unless (fork())
{
`$clinit -d`;
exit;
}
sleep 1;
`$clinit pidgrp 1`;
ok(clwaitstat($clinit,"pidgrp",1,"DONE"));
ok(lines(),1);
my $pid=lastline();
ok(kill(0,$pid),1);
`$clinit -k`;
1 while -s "t/clstat";
ok(1);
my $pidh=lastline();
ok($pid,$pidh);
ok(kill(0,$pid),0);
unless (fork())
{
my $init = Cluster::Init->daemon(%parms);
exit;
}
sleep 1;
my $init = Cluster::Init->client(%parms);
$init->tell("hellogrp","f");
ok(waitstat($init,"hellogrp","f","FAILED"));
$init->tell("hellogrp","t");
ok(waitstat($init,"hellogrp","t","PASSED"));
$init->shutdown();
ok(1);
( run in 0.880 second using v1.01-cache-2.11-cpan-49f99fa48dc )