#!/usr/bin/perl
sub
POE::Kernel::ASSERT_DEFAULT () { 1 }
$|++;
my
%opts
;
getopts(
'd:'
, \
%opts
);
$opts
{
'd'
} = 0
unless
defined
(
$opts
{
'd'
});
set_level(
$opts
{
'd'
});
POE::Session->create
(
inline_states
=>
{
_start
=>
sub
{
my
(
$kernel
,
$session
,
$heap
) =
@_
[KERNEL, SESSION, HEAP];
my
$status
=
$kernel
->alias_set(
"main"
);
my
$server
= TestServer->new(
Port
=> 5000);
$heap
->{server} =
$server
;
$heap
->{proxy} = POE::Component::Proxy::TCP->new
(
Alias
=>
"ProxyServerSessionAl"
,
Port
=> 4000,
OrigPort
=> 5000,
OrigAddress
=>
"localhost"
,
DataFromClient
=>
sub
{
my
$s
=
shift
;
dbprint(3,
"**from client $s"
);
},
DataFromServer
=>
sub
{
my
$s
=
shift
;
dbprint(3,
"**from server $s"
);
},
);
$kernel
->delay_add(
"start_client"
, 3);
},
client_done
=>
sub
{
my
(
$kernel
,
$session
,
$heap
) =
@_
[KERNEL, SESSION, HEAP];
$heap
->{client_count}++;
if
(
$heap
->{client_count} ==
$heap
->{number_clients}) {
exit
(0);
}
},
test_result
=>
sub
{
my
(
$kernel
,
$session
,
$heap
,
$ok
,
$test_name
) =
@_
[KERNEL, SESSION, HEAP, ARG0, ARG1];
ok(
$ok
,
$test_name
);
},
start_client
=>
sub
{
my
(
$kernel
,
$session
,
$heap
) =
@_
[KERNEL, SESSION, HEAP];
$heap
->{client_count} = 0;
$heap
->{number_clients} = 0;
my
$request_list_ref1
= [ClientRequest->new(
Count
=> 15,
Text
=>
"client #1 request #1!"
,
DelaySecs
=> 2),
ClientRequest->new(
Count
=> 6,
Text
=>
"Client #1 request #2"
,
DelaySecs
=> 4),
];
my
$client1
= TestClient->new(
Port
=> 4000,
RequestList
=>
$request_list_ref1
);
$heap
->{client1} =
$client1
;
$heap
->{number_clients}++;
my
$request_list_ref2
= [ClientRequest->new(
Count
=> 5,
Text
=>
"client #2 request #1!"
,
DelaySecs
=> 2),
ClientRequest->new(
Count
=> 6,
Text
=>
"client #2 request #2!"
,
DelaySecs
=> 4),
];
my
$client2
= TestClient->new(
Port
=> 4000,
RequestList
=>
$request_list_ref2
);
$heap
->{client2} =
$client2
;
$heap
->{number_clients}++;
},
_stop
=>
sub
{
return
0 },
_child
=>
sub
{ },
},
);
$poe_kernel
->run();
exit
0;