/
hash_with_data_migration.t
111 lines (87 loc) · 2.86 KB
/
hash_with_data_migration.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# -*- cperl -*-
use warnings FATAL => qw(all);
use ExtUtils::testlib;
use Test::More;
use Test::Exception;
use Test::Warn ;
use Test::Differences ;
use Test::Memory::Cycle;
use Config::Model;
use Log::Log4perl qw(:easy :levels) ;
BEGIN { plan tests => 11; }
use strict;
my $arg = shift || '';
my $log = 0 ;
my $trace = $arg =~ /t/ ? 1 : 0 ;
$log = 1 if $arg =~ /l/;
my $home = $ENV{HOME} || "";
my $log4perl_user_conf_file = "$home/.log4config-model";
if ($log and -e $log4perl_user_conf_file ) {
Log::Log4perl::init($log4perl_user_conf_file);
}
else {
Log::Log4perl->easy_init($log ? $WARN: $ERROR);
}
my $model = Config::Model -> new ( ) ;
Config::Model::Exception::Any->Trace(1) if $arg =~ /e/;
ok(1,"compiled");
# minimal set up to get things working
$model->create_config_class(
name => "Master",
element => [
plain_hash => {
type => 'hash',
status => 'deprecated' ,
index_type => 'string',
ordered => 1,
cargo => {
type => 'leaf',
value_type => 'string'
},
},
hash_with_data_migration => {
type => 'hash',
index_type => 'string',
migrate_values_from => '- plain_hash',
ordered => 1,
cargo => {
type => 'leaf',
value_type => 'string' ,
},
},
hash2_with_data_migration => {
type => 'hash',
index_type => 'string',
migrate_values_from => '- hash_with_data_migration',
ordered => 1,
cargo => {
type => 'leaf',
value_type => 'string' ,
},
},
]
);
ok(1,"config classes created") ;
my $inst = $model->instance(
root_class_name => 'Master',
instance_name => 'test1'
);
ok( $inst, "created dummy instance" );
my $root = $inst->config_root;
# emulate config file load
$root->load(step => "plain_hash:k1=foo plain_hash:k2=bar", check => 'no') ;
ok(1,"set up plain hash") ;
my $hwdm = $root->fetch_element('hash_with_data_migration') ;
ok($hwdm, "create hash_with_data_migration element") ;
$hwdm->fetch_with_id('new')->store('baz0') ;
# check data prior to migration
eq_or_diff([$hwdm->fetch_all_values], ['baz0'],"hash data before migration") ;
# emulate end of file read
$inst->initial_load_stop ;
# test data migration stuff
eq_or_diff([$hwdm->fetch_all_indexes],[ qw/new k1 k2/ ],"hash keys after migration") ;
eq_or_diff([$hwdm->fetch_all_values], [ qw/baz0 foo bar/],"hash data after migration ") ;
my $hwdm2 = $root->fetch_element('hash2_with_data_migration') ;
ok($hwdm2, "create hash2_with_data_migration element") ;
eq_or_diff([$hwdm2->fetch_all_values], [ qw/baz0 foo bar/],"hash data after 2nd migration ") ;
memory_cycle_ok($model,"test memory cycles");