source: A2P/a2p/test/A2P/Status.pm @ 3

Last change on this file since 3 was 3, checked in by guillaume, 16 years ago
  • AUTHORS: Ajout des différents contributeurs
  • COPYING: Ajout de la licence GPL v3
  • a2p: Préparation des sources pour leur publication sous GPL
  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 20.2 KB
Line 
1#
2# Copyright (c) 2004-2007 - Consultas, PKG.fr
3#
4# This file is part of A2P.
5#
6# A2P is free software; you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation; either version 2 of the License, or
9# (at your option) any later version.
10#
11# A2P is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with A2P; if not, write to the Free Software
18# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19#
20# $Id: Status.pm 3 2007-10-18 16:20:19Z guillaume $
21#
22
23use strict;
24use Test;
25use GDBM_File;
26use Storable qw( thaw );
27
28require 'test/A2P/Defaults.pm' ;
29
30use warnings FATAL => qw(void);
31
32BEGIN {
33    plan
34        tests  => 215,
35        onfail => sub { exit(1) }
36}
37
38$| = 1 ;
39
40our $tie_file ;
41our $test_string ;
42our ( $freezed, $SERVICE_TMP, $SHMDIR, $ADVANCED_DEBUGGING, $LOCKID,
43    $LOGFILENAME, $DEBUG_IN_FILE, %STATS );
44our $Progname    = 'TEST-Status' ;
45
46unlink $tie_file ;
47
48&info("Loading A2P::Status library");
49    ok require A2P::Status ;
50
51&info("Check default A2P::Status table");
52    ok join("*",&A2P::Status::INTIAL_STATUS), 'o*_*_*0*0*0*0*0*0*0*0*_*_' ;
53
54my $status ;
55my $cache_hashref   = {} ;
56my $cache_hashref_2 = {} ;
57my %tied__hash      = () ;
58
59my %h = () ;
60my %s = () ;
61my $do_next_test = 1 ;
62
63sub dump_hash {
64    $h{This} = $cache_hashref ;
65    map { print STDERR "CACHE: $_ -> ".$h{This}->{$_},($h{This}->{$_}=~/^HASH/?
66        " -> (".keys(%{$h{This}->{$_}})." keys)":""),"\n" }
67        keys(%{$h{This}}) ;
68    map { print STDERR "CACHE: __SID__ -> $_ -> ".$h{This}->{__SID__}->{$_},"\n"
69        } keys(%{$h{This}->{__SID__}}) ;
70    $h{This} = \%tied__hash ;
71    map { print STDERR "TIED : $_ -> ", ( $h{This}->{$_} =~ $freezed ?
72        "Freezed storable object" : $h{This}->{$_}),"\n" }
73        keys(%{$h{This}}) ;
74    delete $h{This} ;
75}
76
77
78&info("Get a status object");
79    $status = new A2P::Status( $cache_hashref, \%tied__hash );
80    ok defined($status) ;
81    ok ref($status) , 'A2P::Status' ;
82
83&info("Check cache");
84    ok $cache_hashref->{'noname'} , $status ;
85    ok keys(%{$cache_hashref}) , 2 ;
86
87sub check_status_defaults {
88    #&dump_hash ;
89    my $self = shift ;
90    my $job  = shift ;
91    &info("Checking Status object defaults of " . $job );
92    ok $self->{JOB}, $job ;
93    ok $self->is_job, $job ;
94    ok $self->{LOCKID}, $LOCKID ;
95    ok $self->{DAY}, 19700101 ;
96    &info("Checked");
97}
98
99&check_status_defaults($status,'noname');
100    ok $status->{AFP}, 'noname' ;
101    ok $status->get_sid_index, 0 ;
102
103&info("Insert status in cache");
104    ok $status->is_job('test'), 'test' ;
105    ok $status->cached ;
106
107&info("Check cache");
108    ok $cache_hashref->{'test'} , $status ;
109    ok keys(%{$cache_hashref}) , 3 ;
110    #&dump_hash ;
111    delete $cache_hashref->{'noname'} ;
112    delete $cache_hashref->{'test'} ;
113
114
115&info("Try tied cache");
116    ok defined(tie( %tied__hash, 'GDBM_File', $tie_file, GDBM_WRCREAT, 0660)) ;
117    $cache_hashref->{__GDBM_WRITER__} = 1 ;
118
119&info("Insert status in tied hash");
120    $status = new A2P::Status( $cache_hashref, \%tied__hash, 'TEST-UNIT-1' );
121    ok $cache_hashref->{'TEST-UNIT-1'} , $status ;
122&check_status_defaults($status,'TEST-UNIT-1');
123    ok $status->{AFP}, 'TEST-UNIT-1' ;
124    ok $status->get_sid_index, 0 ;
125
126
127&info("Set jobname, a private scalar and save to tied hash");
128    ok $status->is_job('TEST-UNIT-2') ;
129    ok $status->cached ;
130    ok $status->{"TESTUNIT-$$"} = '__PRIVATE__' ;
131    ok $status->{"TESTUNIT-$$"} , '__PRIVATE__' ;
132&info("Control 'is_tied' returns the same reference avec being tied");
133    ok $status->is_tied, 0 ; # Null when not in tied hash
134    ok $status->save_tied ;
135&info("Status ref is different as re-read from tied hash");
136    my $tied = $status->is_tied ;
137    ok $tied != $status ;
138    ok ref($status) , 'A2P::Status' ;
139    ok ref($tied) , 'A2P::Status' ;
140    ok $status->get_sid_index, $tied->get_sid_index ;
141    ok $cache_hashref->{'TEST-UNIT-2'} , $status ;
142    ok $cache_hashref->{'TEST-UNIT-2'} != $tied ;
143&info("Close tie");
144    untie %tied__hash ;
145
146&info("Reopen as reader and get one in tied hash");
147    ok defined(tie( %tied__hash, 'GDBM_File', $tie_file, GDBM_READER, 0660)) ;
148    $cache_hashref->{__GDBM_WRITER__} = 0 ;
149
150    ok defined($tied__hash{'TEST-UNIT-2'}) ;
151    my $intied = new A2P::Status( $cache_hashref, \%tied__hash, 'TEST-UNIT-2' );
152&info("Check status is inserted in cache automatically");
153    ok defined($intied) and ref($intied) =~ /^A2P::Status$/ ;
154    ok defined($cache_hashref->{'TEST-UNIT-2'}) ;
155    #&dump_hash ;
156
157&info("Control the retrieved jobname");
158    ok defined($intied->{JOB}) ;
159    ok $intied->is_job() ;
160    ok $intied->is_job(), 'TEST-UNIT-2' ;
161&info("Control private inserted value is there");
162    ok $intied->{"TESTUNIT-$$"} , '__PRIVATE__' ;
163    #&dump_hash ;
164
165untie %tied__hash ;
166&info("Reopen as writer and get new status");
167    ok defined(tie( %tied__hash, 'GDBM_File', $tie_file, GDBM_WRCREAT, 0660)) ;
168    $cache_hashref->{__GDBM_WRITER__} = 1 ;
169
170    $intied = new A2P::Status( $cache_hashref, \%tied__hash, 'TEST-UNIT-3' );
171    ok defined($intied) and ref($intied) =~ /^A2P::Status$/ ;
172    ok $intied->get_revision(), 0 ;
173
174&info("Test API used by tied_update_status in A2P::JobStatus");
175    &info("Check cache_timer call");
176    ok $intied->cache_timer ;
177    &info("Check step_status call");
178    ok $intied->step_status ;
179    ok $intied->step_status(-1), 0 ;
180    ok $intied->step_status(0), 'o';
181    ok $intied->step_status(12), '_';
182    ok $intied->{STATE}->[12], '_' ;
183    ok ! $intied->step_status(20);
184    ok $intied->step_status(5), '_' ;    # if char '0' return '_'
185    ok $intied->step_status(5);          # Still true by default
186    ok $intied->step_status(5,'0'), '.'; # Can't set '0' but '.' as default
187    ok $intied->step_status(12,'X'), 'X' ;
188    ok $intied->step_status(12), 'X';
189    ok $intied->{STATE}->[12], 'X' ;
190    ok $intied->{STEP}, 12 ;
191    #&dump_hash ;
192
193&info("Check infos API");
194    ok $intied->infos(), 1 ;
195    ok $intied->infos(1), 0 ;
196    ok $intied->infos("AA"), 0 ;
197    ok $intied->infos( ( TEST => 111 ) ), 0 ;
198    ok $intied->infos( { TEST => 111 } ), 1 ;
199    ok $intied->infos( [ TEST => 111 ] ), 0 ;
200    ok $intied->{TEST}, 111 ;
201        my @test = 'TEST' ;
202        &info("Try a call with a bad hash (it generates at least a warning)");
203    ok $intied->infos( { @test } ), 1 ;
204    ok $intied->{TEST}, "" ;
205    ok $intied->infos({ THIS => "TESTUNIT" }) ;
206    ok $intied->{THIS}, 'TESTUNIT' ;
207    ok $intied->infos( { THIS => "   " }) ;
208    ok $intied->{THIS}, '' ;
209    ok $intied->infos( { JOBID => 'UNIT-TEST' } ), 1 ;
210    ok $intied->{JOBID}, 'UNIT-TEST' ;
211    ok $intied->cached ;
212    ok defined($cache_hashref->{'TEST-UNIT-3'}) ;
213    ok $cache_hashref->{'TEST-UNIT-3'}, $intied ;
214    ok defined($cache_hashref->{'UNIT-TEST'}) ;
215    ok $cache_hashref->{'UNIT-TEST'}, $intied ;
216
217&info("Check current_in_tie_sid_key API");
218    ok $intied->get_sid_index, 0 ;
219    ok $intied->current_in_tie_sid_key , 'TEST-UNIT-3' ;
220
221&info("Check status API");
222    ok $intied->infos( { STATUS => "done" } ) ;
223    ok $intied->{STATUS}, 'done' ;
224    ok $intied->status, 'DONE' ;
225    ok $intied->{STATUS}, 'DONE' ;
226
227&info("Check save_tied call");
228    $intied = new A2P::Status( $cache_hashref, \%tied__hash, 'TEST-UNIT-4' );
229    ok $intied->get_revision(), 0 ;
230    ok $intied->save_tied(), $intied ;
231    ok $intied->get_revision(), 1 ;
232    ok defined($tied__hash{'TEST-UNIT-4'}) ;
233    $cache_hashref->{__GDBM_WRITER__} = 0 ;
234    &info("Must not save_tied and return 0");
235    ok $intied->save_tied(), 0 ;
236    ok $intied->get_revision(), 2 ;
237    $cache_hashref->{__GDBM_WRITER__} = 1 ;
238
239&info("Check about revision API");
240    ok $intied->get_revision(), 2 ;
241    ok $intied->{REV}, 2 ;
242    ok $intied->set_revision(), 3 ;
243    ok $intied->get_revision(), 3 ;
244    ok $intied->{REV}, 3 ;
245    ok $intied->set_revision(), 4 ;
246    ok $intied->{REV}, 4 ;
247
248&info("Check current_in_tie_sid_key API");
249    ok $intied->current_in_tie_sid_key , 'TEST-UNIT-4' ;
250
251&info("Simulating SID updates from another thread:");
252    $LOCKID = "SIMUL-1" ;
253    $0 = "TEST-Status-SM" , A2P::Syslog::SetLogger(0);
254    &info("1. First call initialize the status object");
255    $status = new A2P::Status( $cache_hashref, \%tied__hash, 'TEST-UNIT-5' );
256    ok $status->step_status ;
257    ok $status->infos ;
258    ok $status->cached ;
259    ok $s{timer1} = $status->cache_timer ;
260        $s{timer2} = $status->timer ;
261    ok $s{timer1} , $s{timer2} ;
262    ok $status->save_tied , $status ;
263    ok $cache_hashref->{'TEST-UNIT-5'} , $status ;
264    ok ! exists($cache_hashref->{'SIMULATION-1'}) ;
265    ok $status->get_revision , 1 ;
266    ok $status->get_sid_index , 0 ;
267    ok $status->get_sid_key , 'TEST-UNIT-5' ;
268    ok $status->get_sid_version_key , 'TEST-UNIT-5_rev' ;
269        $s{version} = &thaw($tied__hash{'TEST-UNIT-5_rev'}) ;
270    ok @{$s{version}} , 3 ;
271    ok $s{version}->[0] , 1 ;
272    ok $s{version}->[1] , "SIMUL-1" ;
273    ok $s{version}->[2] , $s{timer2} ;
274    undef $status ;
275    ok defined($tied__hash{'TEST-UNIT-5'}) ;
276    ok defined($tied__hash{'TEST-UNIT-5_rev'}) ;
277    ok $tied__hash{'SIMULATION-1'} , undef ;
278    #&dump_hash ;
279
280    &info("2. Second call initialize the status itself and a private value");
281    $status = new A2P::Status( $cache_hashref, \%tied__hash, 'TEST-UNIT-5' );
282    ok $status->step_status(1,'.') , '.';
283    ok $status->infos({ STATUS => 'WAITING', FILE => 'TEST.test-unit-5' });
284    ok $status->cached ;
285    ok $status->cache_timer ;
286    ok $status->save_tied , $status ;
287    ok $cache_hashref->{'TEST-UNIT-5'} , $status ;
288    ok ! exists($cache_hashref->{'SIMULATION-1'}) ;
289    undef $status ;
290    ok defined($tied__hash{'TEST-UNIT-5'}) ;
291    ok defined($tied__hash{'TEST-UNIT-5_rev'}) ;
292        $s{version} = &thaw($tied__hash{'TEST-UNIT-5_rev'}) ;
293    ok @{$s{version}} , 3 ;
294    ok $s{version}->[0] , 2 ;
295    ok $tied__hash{'SIMULATION-1'} , undef ;
296
297    &info("3. Third call initialize the JID");
298    $status = new A2P::Status( $cache_hashref, \%tied__hash, 'TEST-UNIT-5' );
299    ok $status->step_status(1,'o') , 'o';
300    ok $status->step_status(1,'o') , 'o';
301    ok $status->step_status(1,'-') , 'o';
302    ok $status->infos({ JID => 'SIMULATION-1', STATUS => 'STARTING',
303        FILE => 'TEST/test-unit-5' });
304    ok $status->cached ;
305    ok $status->cache_timer ;
306    ok $status->save_tied , $status ;
307    ok $cache_hashref->{'TEST-UNIT-5'} , $status ;
308    ok $cache_hashref->{'SIMULATION-1'}, $status ;
309    undef $status ;
310    ok defined($tied__hash{'TEST-UNIT-5'}) ;
311    ok defined($tied__hash{'TEST-UNIT-5_rev'}) ;
312        $s{version} = &thaw($tied__hash{'TEST-UNIT-5_rev'}) ;
313    ok @{$s{version}} , 3 ;
314    ok $s{version}->[0] , 3 ;
315    ok $tied__hash{'SIMULATION-1'} , 'TEST-UNIT-5' ;
316
317    $cache_hashref = { __GDBM_WRITER__ => 1 } ;
318    #&dump_hash ;
319
320    &info("4. Next update from converter using another cache");
321    $0 = "TEST-Status-CO" , A2P::Syslog::SetLogger(0);
322    $cache_hashref_2->{__GDBM_WRITER__} = 1 ;
323    $status = new A2P::Status( $cache_hashref_2, \%tied__hash, 'TEST-UNIT-5' );
324    ok $status->step_status(2,'.') , '.';
325    ok $status->infos({ JID => 'SIMULATION-1' });
326    ok $status->cached ;
327    ok $status->cache_timer ;
328    ok $status->save_tied , $status ;
329    ok $cache_hashref_2->{'TEST-UNIT-5'} , $status ;
330    ok $cache_hashref_2->{'SIMULATION-1'}, $status ;
331    ok $cache_hashref_2->{'__SID__'}->{3}, undef ;
332    undef $status ;
333    ok defined($tied__hash{'TEST-UNIT-5'}) ;
334    ok defined($tied__hash{'TEST-UNIT-5_rev'}) ;
335        $s{version} = &thaw($tied__hash{'TEST-UNIT-5_rev'}) ;
336    ok @{$s{version}} , 3 ;
337    ok $s{version}->[0] , 4 ;
338    ok $tied__hash{'SIMULATION-1'} , 'TEST-UNIT-5' ;
339
340    &info("5. Clear the cache to simulate check from a2p-status as reader");
341    $cache_hashref = { __GDBM_WRITER__ => 0 } ;
342    #&dump_hash ;
343
344    &info("6. In the same time a2p-status get the status and update it in DB");
345    $0 = "TEST-Status-DB" , A2P::Syslog::SetLogger(0);
346    $status = new A2P::Status( $cache_hashref, \%tied__hash, 'TEST-UNIT-5' );
347
348    &info("Check current_in_tie_sid_key API");
349    ok $status->current_in_tie_sid_key , 'TEST-UNIT-5' ;
350
351    ok $cache_hashref->{'TEST-UNIT-5'} , $status ;
352    ok $cache_hashref->{'SIMULATION-1'}, $status ;
353    ok $status->get_sid_index , 0 ;
354    &info("7. Here a sync with DB result in a change of SID");
355    ok A2P::Status::_found_sid() , 0 ;
356    ok $status->{DB}->{SID} , undef ;
357    $status->{PREVIOUS_SID} = 'TEST-UNIT-5' ;
358    $status->{SID} = $status->{DB}->{SID} = 3 ;
359    ok $status->get_revision, 4 ;
360    $status->{DB}->{REV} = $status->get_revision ;
361    ok $status->get_sid_index , 3 ;
362    $cache_hashref->{'__SID__'}->{$status->get_sid_index} = $status ;
363    ok A2P::Status::_found_sid(3), 3 ;
364    ok A2P::Status::_found_sid() , 4 ;
365    ok $status->cache_timer ;
366    #&dump_hash ;
367
368    &info("Check current_in_tie_sid_key API");
369    ok $status->current_in_tie_sid_key , 'TEST-UNIT-5' ;
370
371    &info("8. Check we can't update status tied hash");
372    ok $status->get_revision, 4 ;
373    ok $status->save_tied , 0 ;
374    ok $status->get_revision, 5 ;
375    ok $cache_hashref->{'TEST-UNIT-5'} , $status ;
376    ok $cache_hashref->{'SIMULATION-1'}, $status ;
377    ok $cache_hashref->{'__SID__'}->{3}, $status ;
378    ok defined($tied__hash{'TEST-UNIT-5'}) ;
379    ok defined($tied__hash{'TEST-UNIT-5_rev'}) ;
380        $s{version} = &thaw($tied__hash{'TEST-UNIT-5_rev'}) ;
381    ok @{$s{version}} , 3 ;
382    ok $s{version}->[0] , 4 ;
383    ok ! exists($tied__hash{'_SID_3'}) ;
384    ok ! exists($tied__hash{'_SID_3_rev'}) ;
385    ok $tied__hash{'SIMULATION-1'} , 'TEST-UNIT-5' ;
386    #&dump_hash ;
387
388    &info("9. Retry to update tied hash");
389    $cache_hashref->{__GDBM_WRITER__} = 1 ;
390    undef $status ;
391    $status = new A2P::Status( $cache_hashref, \%tied__hash, 'TEST-UNIT-5' );
392    ok $cache_hashref->{'TEST-UNIT-5'} , $status ;
393    ok $cache_hashref->{'SIMULATION-1'}, $status ;
394    ok $status->get_sid_index , 3 ;
395    ok $cache_hashref->{'__SID__'}->{3}, $status ;
396    &info("Here sync_with_db simulates a change of SID with PREVIOUS_SID");
397    ok $status->{SID} , 3 ;
398    ok $status->get_sid_index , 3 ;
399    ok $status->{PREVIOUS_SID} , 'TEST-UNIT-5' ;
400    ok $status->{DB}->{SID} , 3 ;
401    ok $status->cache_timer ;
402
403    &info("10. Check we have updated status tied hash");
404    ok $status->save_tied , $status ;
405    # Only deleted after save_tied in sync_with_db
406    delete $tied__hash{'TEST-UNIT-5_rev'} ;
407    ok $status->get_revision, 6 ;
408    ok $cache_hashref->{'TEST-UNIT-5'} , $status ;
409    ok $cache_hashref->{'SIMULATION-1'}, $status ;
410    ok $cache_hashref->{'__SID__'}->{3}, $status ;
411    ok $tied__hash{'TEST-UNIT-5'} , '3' ;
412    ok ! exists($tied__hash{'TEST-UNIT-5_rev'}) ;
413    ok defined($tied__hash{'_SID_3'}) ;
414    ok defined($tied__hash{'_SID_3_rev'}) ;
415        $s{version} = &thaw($tied__hash{'_SID_3_rev'}) ;
416    ok @{$s{version}} , 3 ;
417    ok $s{version}->[0] , 6 ;
418    ok $tied__hash{'SIMULATION-1'} , 'TEST-UNIT-5' ;
419
420    &info("Check current_in_tie_sid_key API");
421    ok $status->current_in_tie_sid_key , '_SID_3' ;
422    undef $status ;
423
424    &info("11. Following check as reader are done with new SID key");
425    $cache_hashref->{__GDBM_WRITER__} = 0 ;
426    undef $status ;
427    $status = new A2P::Status( $cache_hashref, \%tied__hash, '_SID_3' );
428    ok $status->get_revision, 6 ;
429    ok $status->get_sid_index , 3 ;
430    $cache_hashref->{'__SID__'}->{$status->get_sid_index} = $status ;
431    #&dump_hash ;
432
433    &info("Check current_in_tie_sid_key API");
434    ok $status->current_in_tie_sid_key , '_SID_3' ;
435
436    &info("12. Use the other cache and control SID is not troubled");
437    $0 = "TEST-Status-CO" , A2P::Syslog::SetLogger(0);
438    $status = new A2P::Status( $cache_hashref_2, \%tied__hash, 'TEST-UNIT-5' );
439
440    &info("Check current_in_tie_sid_key API");
441    ok $status->current_in_tie_sid_key , '_SID_3' ;
442
443    ok $status->step_status(2,'o') , 'o';
444    ok $status->infos ;
445    ok $status->cached ;
446    ok $status->cache_timer ;
447    #&dump_hash ;
448    ok $status->save_tied , $status ;
449    ok $status->get_revision, 7 ;
450    ok $cache_hashref_2->{'TEST-UNIT-5'} , $status ;
451    ok $cache_hashref_2->{'SIMULATION-1'}, $status ;
452    ok $cache_hashref_2->{'__SID__'}->{3}, $status ;
453    ok ! exists($tied__hash{'TEST-UNIT-5_rev'}) ;
454    ok defined($tied__hash{'_SID_3'}) ;
455    ok defined($tied__hash{'_SID_3_rev'}) ;
456    ok defined($tied__hash{'_SID_3_rev'}) ;
457        $s{version} = &thaw($tied__hash{'_SID_3_rev'}) ;
458    ok @{$s{version}} , 3 ;
459    ok $s{version}->[0] , 7 ;
460    ok $tied__hash{'SIMULATION-1'} , 'TEST-UNIT-5' ;
461    ok $tied__hash{'TEST-UNIT-5'}  , '3' ;
462    undef $status ;
463
464&info("Check remove_from_cache call");
465    $cache_hashref->{__GDBM_WRITER__} = 1 ;
466    $intied = new A2P::Status( $cache_hashref, \%tied__hash, 'TEST_UNIT_6' );
467    ok $intied->save_tied(), $intied ;
468    ok defined($tied__hash{'TEST_UNIT_6'}) ;
469    ok $cache_hashref->{'TEST_UNIT_6'}, $intied ;
470    $intied->remove_from_cache ;
471    ok defined($tied__hash{'TEST_UNIT_6'}) ;
472    ok $cache_hashref->{'TEST_UNIT_6'}, undef ;
473
474&info("Check cache/timer info APIs");
475    ok $cache_hashref->{__GDBM_WRITER__} ;
476    $status = new A2P::Status( $cache_hashref, \%tied__hash, 'TEST_UNIT_7' );
477    ok $status->cached ;
478    ok exists($cache_hashref->{'TEST_UNIT_7'}) ;
479    ok $cache_hashref->{'TEST_UNIT_7'}, $status ;
480    ok exists($cache_hashref->{'TEST_UNIT_7'}->{TIMER}) ;
481    ok $cache_hashref->{'TEST_UNIT_7'}->{TIMER} ;
482    ok $cache_hashref->{'TEST_UNIT_7'}->timer ;
483        my $timer = $cache_hashref->{'TEST_UNIT_7'}->{TIMER} ;
484    ok $cache_hashref->{'TEST_UNIT_7'}->timer, $timer ;
485
486&info("Check compared_with_one_from_tiehash API");
487    ok $status->get_revision, 0 ;
488    ok $status->save_tied(), $status ;
489    ok $status->get_revision, 1 ;
490    ok defined($tied__hash{'TEST_UNIT_7'}) ;
491        my $dirty = $status->clone ;
492    ok $status->save_tied(), $status ;
493    ok $status->get_revision, 2 ;
494    ok $dirty->get_revision, 1 ;
495        # Dirty cache entry
496    ok $status->compared_with_one_from_tiehash, $status ;
497        my $updated = $dirty->compared_with_one_from_tiehash ;
498    ok $updated != $dirty ;
499    ok $updated->get_revision, 2 ;
500        $updated->cached ;
501    ok $cache_hashref->{'TEST_UNIT_7'}, $updated ;
502    ok $dirty->get_revision, 1 ;
503    ok $dirty->set_revision, 2 ;
504    ok $dirty->compared_with_one_from_tiehash, $dirty ;
505    ok $dirty->set_revision, 3 ;
506    ok $dirty->compared_with_one_from_tiehash, $dirty ;
507    ok $cache_hashref->{'TEST_UNIT_7'} != $dirty ;
508
509$do_next_test = 0 ;
510if ($do_next_test) { # This long test should normally be disabled
511&info("Check remove_from_tied_hash API timing");
512    $status = new A2P::Status( $cache_hashref, \%tied__hash, 'TEST_UNIT_8' );
513    my $ostatus = new A2P::Status( $cache_hashref, \%tied__hash, 'TEST_UNIT_9' );
514    ok $status->save_tied(), $status ;
515    ok $ostatus->save_tied(), $ostatus ;
516    ok defined($tied__hash{'TEST_UNIT_8'}) ;
517        my $i = 0 ;
518        while ( $i++ < 10000 ) {
519            #&dump_hash if ( $i == 10 );
520            $status->is_job('TEST_UNIT_8_ref_'.$i);
521            $status->save_tied();
522            $ostatus->is_job('TEST_UNIT_9_ref_'.$i);
523            $ostatus->save_tied();
524        }
525        $status->set_sid_index(500);
526        $status->save_tied ;
527        $ostatus->set_sid_index(5000);
528        $ostatus->save_tied ;
529    my ( $size, $maxsize ) = ( -s $tie_file, 3000000 );
530    &info("Memory file size = $size bytes");
531    $size > $maxsize ? ok $size, $maxsize : ok 1 ;
532    my ( $timing, $maxtiming ) = ( $STATS{'TIMING-SAVE-TIED-MAX'}, 20000 );
533    &info("Max save to tied timing = $timing");
534    $timing > $maxtiming ? ok $timing, $maxtiming : ok 1 ;
535        $status->remove_from_cache ;
536        $status->remove_from_tied_hash();
537    ( $timing, $maxtiming ) = ( $STATS{'TIMING-REMOVE-FROM-TIED-MAX'}, 700000 );
538    &info("Max remove timing = $timing");
539    $timing > $maxtiming ? ok $timing, $maxtiming : ok 1 ;
540        my $tiedhash = tied( %tied__hash ) ;
541    ok ref($tiedhash) , 'GDBM_File' ;
542    &info("Shrinking memory file...");
543        my $shrinked = -s $tie_file ? $tiedhash->reorganize() : 0 ;
544        undef $tiedhash ;
545    (defined($shrinked) and $shrinked >= 0) ? ok $shrinked, 0 : ok 0 ;
546    ( $size, $maxsize ) = ( -s $tie_file, 1200000 );
547    &info("Shrinked memory file size = $size bytes");
548    $size > $maxsize ? ok $size, $maxsize : ok 1 ;
549}
550
551# Clean
552#&dump_hash ;
553untie %tied__hash ;
554unlink $tie_file ;
555
556exit(0) ;
Note: See TracBrowser for help on using the repository browser.