populate.pl 3.25 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
#!/usr/bin/perl

package Test::Request;

use Mouse;

has userData    => ( is => 'rw' );
has sessionInfo => ( is => 'rw' );
has id          => ( is => 'rw' );

package main;
use Test::More;
use strict;
14
use POSIX qw(mktime strftime);
15 16 17 18 19 20
use lib 'lemonldap-ng-common/blib/lib';
use lib 'lemonldap-ng-handler/blib/lib';
use lib 'lemonldap-ng-portal/blib/lib';
use lib 'lemonldap-ng-manager/blib/lib';
require './lemonldap-ng-portal/t/test-lib.pm';

Xavier Guimard's avatar
Xavier Guimard committed
21
use constant COUNT => 10000;
22

23 24 25 26 27 28 29
my $portal = LLNG::Manager::Test->new(
    {
        ini => {
            configStorage => {
                type    => 'File',
                dirName => 'e2e-tests/conf',
            },
30
            localSessionStorage => undef,
31
            localStorage        => undef,
32 33 34 35 36
        }
    }
)->p;

my @chars = ( "A" .. "Z", "a" .. "z" );
Xavier Guimard's avatar
Xavier Guimard committed
37 38
my $t = time;;

39
foreach my $i ( 1 .. COUNT() ) {
40 41
    my $string;
    $string .= $chars[ rand @chars ] for 1 .. 8;
42

43 44 45 46 47 48
    #$string = 'dwho';
    my ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) =
      localtime(time);
    $hour = int( rand($hour) );
    $min  = int( rand(60) );
    $sec  = int( rand(60) );
49
    my $ipAddr = (
Xavier Guimard's avatar
Xavier Guimard committed
50
        int( rand(2) ) == 1
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
        ? join( '.',
            int( rand(256) ),
            int( rand(256) ),
            int( rand(256) ),
            int( rand(256) ) )
        : join(
            ':',

            # Mix routable IPv6 addresses (2000::/3) and local ones (fe:80::/10)
            (
                int( rand(2) ) == 1
                ? sprintf( "%X",      int( rand(8192) + 8192 ) )
                : sprintf( "fe80:%X", int( rand(16384) ) )
            ),
            sprintf( "%X", int( rand(65536) ) ),
            sprintf( "%X", int( rand(65536) ) ),
            sprintf( "%X", int( rand(65536) ) ),
            sprintf( "%X", int( rand(65536) ) ),
            sprintf( "%X", int( rand(65536) ) ),
            sprintf( "%X", int( rand(65536) ) ),
            sprintf( "%X", int( rand(65536) ) )
        )
    );

    # Replace 0 in IPv6 addresses
    if ( $ipAddr =~ ':0:' ) {
        my @t   = ( $ipAddr =~ /\:(?:0\:)+/g );
        my $ind = -1;
        my $len = 0;
        for ( my $i = 0 ; $i < @t ; $i++ ) {
            $ind = $i if ( length( $t[$i] ) > $len );
        }
        $ipAddr =~ s/$t[$ind]/::/;
        $ipAddr =~ s/^0//;
    }
86 87 88
    my $req = Test::Request->new(
        {
            sessionInfo => {
89 90 91 92 93 94 95 96 97 98 99
                _user     => $string,
                uid       => $string,
                cn        => uc($string),
                sn        => $string,
                mail      => "$string\@badwolf.org",
                _utime    => mktime( $sec, $min, $hour, $mday, $mon, $year ),
                startTime => strftime(
                    "%Y%m%d%H%M%S",
                    $sec,  $min,  $hour, $mday, $mon,
                    $year, $wday, $yday, $isdst
                ),
100
                ipAddr => $ipAddr,
101 102 103 104 105 106 107
            }
        }
    );

    $portal->setMacros($req);
    $portal->store($req);
}
Xavier Guimard's avatar
Xavier Guimard committed
108
print 'LOAD TIME: '.(time - $t)."\n";
109
done_testing( count() );
Xavier Guimard's avatar
Xavier Guimard committed
110 111 112 113 114 115 116

#use LWP::UserAgent;
#my $ua = LWP::UserAgent->new;
#$ua->get('http://manager.example.com:19876/sessions.html');
#$t = time;
#$ua->get('http://manager.example.com:19876/manager.fcgi/sessions/global?groupBy=substr(_whatToTrace,1)');
#print 'READ TIME: '.(time - $t)."\n";