[LON-CAPA-cvs] cvs: newloncapa / cleartest.pl

foxr lon-capa-cvs@mail.lon-capa.org
Sat, 12 Apr 2003 02:48:48 -0000


foxr		Fri Apr 11 22:48:48 2003 EDT

  Added files:                 
    /newloncapa	cleartest.pl 
  Log:
  Test the new lonc with clear text transactions.
  
  

Index: newloncapa/cleartest.pl
+++ newloncapa/cleartest.pl
#!//usr/bin/perl
#
#   Tests the ability to perform requests to lonc that can be processed in 
#    clear text.


use POSIX;
use Socket;
use IO::Socket;
use IO::Socket::UNIX;

$socketpath = "/home/foxr/londtest";
$system     = "lonkashy.nscl.msu.edu";

sub MakeConnection {
    my $Socket = IO::Socket::UNIX->new(Peer => $socketpath,
				    type => SOCK_STREAM,
				    Timeout => 100);
    return $Socket;
}


sub Transaction {
    my $Socket  = shift;
    my $Request = shift;
    print "Transaction: ".$Request."\n";
    $Request    = $Request."\n";	# Transactions end in newline.

    $Socket->send($Request, 0);

    my $reply = <$Socket>;
    return $reply;
}

sub Load {
    my $Socket = shift;
    return Transaction ($Socket, "load");
}

sub Ping {
    my $Socket = shift;
    return Transaction($Socket, "ping");
}

sub Pong {
    my $Socket = shift;
    return Transaction($Socket, "pong");
}


# See if we can get two transactions in flight at the same time forcing
# two connections:

sub Double {

    my $Socket = shift;
    my $Sock1  = shift;
    my $Data   = shift;
    my $Data1  = shift;
    $Data      = $Data."\n";
    $Data1     = $Data1."\n";

    $Socket->send($Data);
    $Sock1->send($Data1);
    my $r1;
    my $r2;
    $r1 = "";
    $r2 = "";
    
    $r1 = <$Socket>;
    $r2 = <$Sock1>;

    return ($r1, $r2);

}


# Do it all with a single connection:

$Socket = MakeConnection;
$Sock1  = MakeConnection;

$reply = Load($Sock1);
print("Load request on sock1 : ".$reply."\n");

$reply  = Load($Socket);	# Get load info:
print("Load request Socket returned: ".$reply."\n");

$reply = Ping($Socket);		# Ping...
print("Ping request returned: ".$reply."\n");


$reply = Pong($Socket);		# pong
print("Pong Request returned: ".$reply."\n");

#  Now see if we can force two lond connections from lonc:

@reply = Double($Socket, $Sock1, "load", "load");
print("Double op got me: ".$reply[0]." ".$reply[1]."\n");
@reply = Double($Socket, $Sock1, "load", "ping");
print("Double op got me: ".$reply[0]." ".$reply[1]."\n");
@reply = Double($Socket, $Sock1, "ping", "pong");
print("Double op got me: ".$reply[0]." ".$reply[1]."\n");
@reply = Double($Socket, $Sock1, "pong", "load");
print("Double op got me: ".$reply[0]." ".$reply[1]."\n");
@reply = Double($Socket, $Sock1, "load", "load");
print("Double op got me: ".$reply[0]." ".$reply[1]."\n");