"Fossies" - the Fresh Open Source Software Archive

Member "eprints3.4-3.4.4/tests/23_cache.pl" (7 Aug 2022, 2614 Bytes) of package /linux/www/eprints3.4-3.4.4.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "23_cache.pl": 3.4-3.4.3_vs_3.4-3.4.4.

    1 use strict;
    2 use Test::More tests => 9;
    3 
    4 BEGIN { use_ok( "EPrints" ); }
    5 BEGIN { use_ok( "EPrints::Test" ); }
    6 
    7 my $session = EPrints::Test::get_test_session( 0 );
    8 ok(defined $session, 'opened an EPrints::Session object');
    9 
   10 my $database = $session->get_database();
   11 ok( defined $database, "database defined" );
   12 
   13 my $dataset = $session->dataset( "cachemap" );
   14 
   15 my $cachemap;
   16 
   17 $cachemap = $dataset->create_dataobj( {
   18     oneshot => 'TRUE',
   19 } );
   20 $cachemap->create_sql_table( $dataset );
   21 ok( $database->has_table( $cachemap->get_sql_table_name ), "create_sql_table" );
   22 
   23 &cleanup();
   24 
   25 my $fake_time = time() - 2 * 3600;
   26 
   27 for(1..10)
   28 {
   29     $cachemap = $dataset->create_dataobj( {
   30         oneshot => 'TRUE',
   31         created => $fake_time,
   32     } );
   33     $cachemap->create_sql_table( $dataset );
   34 }
   35 
   36 $cachemap = $dataset->create_dataobj( {
   37     oneshot => 'TRUE',
   38 } );
   39 $cachemap->create_sql_table( $dataset );
   40 
   41 do {
   42     local $session->{config}->{cache_maxlife} = 1;
   43     BAIL_OUT "Expected to set config but didn't" if $session->config( "cache_maxlife" ) != 1;
   44 
   45     my $dropped = EPrints::DataObj::Cachemap->cleanup( $session );
   46 
   47     is( $dropped, 10, "expired all old cachemaps" );
   48     is( $session->get_database->count_table( $dataset->get_sql_table_name ), 1, "didn't expire current cachemap" );
   49 };
   50 
   51 &cleanup();
   52 
   53 do {
   54     local $session->{config}->{cache_max} = 5;
   55     for(1..10)
   56     {
   57         my $cachemap = $dataset->create_dataobj( {
   58             oneshot => 'TRUE',
   59             created => $fake_time,
   60         } );
   61         $cachemap->create_sql_table( $dataset );
   62     }
   63     is( $session->get_database->count_table( $dataset->get_sql_table_name ), 5, "cache_max limits tables created" );
   64 };
   65 
   66 &cleanup();
   67 
   68 $session->terminate;
   69 
   70 ok(1);
   71 
   72 sub cleanup
   73 {
   74 # clear all current cachemaps
   75     $dataset->search->map(sub {
   76         my( undef, undef, $cachemap ) = @_;
   77 
   78         $cachemap->remove;
   79     } );
   80 }
   81 
   82 =head1 COPYRIGHT
   83 
   84 =for COPYRIGHT BEGIN
   85 
   86 Copyright 2022 University of Southampton.
   87 EPrints 3.4 is supplied by EPrints Services.
   88 
   89 http://www.eprints.org/eprints-3.4/
   90 
   91 =for COPYRIGHT END
   92 
   93 =for LICENSE BEGIN
   94 
   95 This file is part of EPrints 3.4 L<http://www.eprints.org/>.
   96 
   97 EPrints 3.4 and this file are released under the terms of the
   98 GNU Lesser General Public License version 3 as published by
   99 the Free Software Foundation unless otherwise stated.
  100 
  101 EPrints 3.4 is distributed in the hope that it will be useful,
  102 but WITHOUT ANY WARRANTY; without even the implied warranty of
  103 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  104 See the GNU Lesser General Public License for more details.
  105 
  106 You should have received a copy of the GNU Lesser General Public
  107 License along with EPrints 3.4.
  108 If not, see L<http://www.gnu.org/licenses/>.
  109 
  110 =for LICENSE END
  111