IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 31, 2019, 12:02:31 PM (7 years ago)
Author:
eugene
Message:

add tests of the hard/soft hosts which are invalid; location-aware code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20191011/Nebulous-Server/t/08_server_find_instances.t

    r40984 r41019  
    88use warnings FATAL => qw( all );
    99
    10 use Test::More tests => 25;
     10use Test::More tests => 44;
    1111
    1212use lib qw( ./t ./lib );
     
    3131Test::Nebulous->cleanup; # make sure the database is reset before running any tests
    3232
     33# for (my $i = 0; $i < $Nloc; $i++) {
     34#       my $loc = $locations->[$i];
     35#       print "location: $loc\n";
     36#}
     37
    3338Test::Nebulous->setup;
    3439{
     
    101106}
    102107
    103 # object exists but instance is on a different volume
     108# request from a hard_volume returns an instance which is not on the hard volume if available
    104109Test::Nebulous->setup;
    105110eval {
     
    110115    uri_scheme_ok($locations->[0], 'file');
    111116    is($uri, $locations->[0], "URIs match");
    112 
    113     # print "uri: $uri\n";
    114     # print "result: $locations->[0]\n";
    115 };
    116 # die "quick check";
    117 # print "answer: $_[0]\n";
    118 # like($@, qr/no instances on storage volume/, 'instances on a different volume');
    119 
    120 # request from a soft_volume for an instance which is on an invalid node (find_invalid = 1)
    121 # XXX should return the INVALID instance (currently 2019.10.24 does not)
     117};
     118is($@, "", "instance on different node (as hard_volume) returned");
     119
     120# request from a hard_volume returns an instance which is not on the hard volume if available
     121Test::Nebulous->setup;
     122eval {
     123    # key, volume
     124    my $uri = $neb->create_object('foo', '~node01');
     125    my $locations = $neb->find_instances('foo', '~node02');
     126
     127    uri_scheme_ok($locations->[0], 'file');
     128    is($uri, $locations->[0], "URIs match");
     129};
     130is($@, "", "instance on different node (as hard_volume) returned");
     131
     132### TESTS FOR INSTANCE ON INVALID NODE
     133diag ("TESTS FOR INSTANCE ON INVALID NODE");
     134
     135# request from a soft_volume for an instance which is on an invalid node (find_invalid = 1) [SOFT, 1]
    122136Test::Nebulous->setup;
    123137eval {
     
    130144    is($uri, $locations->[0], "URIs match");
    131145};
    132 is($@, "", "instance on invalid node (as hard_volume) returned with find_invalid is set");
    133 #like($@, qr/database error/, "instance on invalid node (as hard_volume) not returned");
    134 
    135 # request from a soft_volume for an instance which is on an invalid node (find_invalid = 0)
    136 # XXX should return the INVALID instance (currently 2019.10.24 does not)
     146is($@, "", "instance on invalid node (as soft_volume) returned with find_invalid = 1");
     147
     148# request from a soft_volume for an instance which is on an invalid node (find_invalid = 0) [SOFT, 0]
    137149Test::Nebulous->setup;
    138150eval {
     
    143155    my $locations = $neb->find_instances('foo', 'node02', 0);
    144156};
    145 #is($@, "", "instance on invalid node (as hard_volume) returned with find_invalid is set");
    146 like($@, qr/database error/, "instance on invalid node (as soft_volume) not returned");
    147 
    148 #### tests with a hard_volume:
    149 
    150 # request from a hard_volume for an instance which is on an invalid node (find_instance not supplied)
     157like($@, qr/database error/, "instance on invalid node (as soft_volume) not returned (find_invalid = 0)");
     158
     159# request from a hard_volume for an instance which is on an invalid node (find_instance not supplied) [SOFT, X]
     160Test::Nebulous->setup;
     161eval {
     162    # key, volume
     163    my $uri = $neb->create_object('foo', '~node02');
     164    Test::Nebulous->switch_node_state;
     165
     166    my $locations = $neb->find_instances('foo', 'node02');
     167};
     168like($@, qr/no instances available for key/, "instance on invalid node (as soft_volume) not returned (find_invalid not set)");
     169
     170# request from a hard_volume for an instance which is on an invalid node (find_invalid = 1) [HARD, 1]
     171Test::Nebulous->setup;
     172eval {
     173    # key, volume
     174    my $uri = $neb->create_object('foo', '~node02');
     175    Test::Nebulous->switch_node_state;
     176
     177    my $locations = $neb->find_instances('foo', '~node02', 1);
     178    uri_scheme_ok($locations->[0], 'file');
     179    is($uri, $locations->[0], "URIs match");
     180};
     181is($@, "", "instance on invalid node (as hard_volume) returned with find_invalid = 1");
     182
     183# request from a hard_volume for an instance which is on an invalid node (find_invalid = 0) [HARD, 0]
     184Test::Nebulous->setup;
     185eval {
     186    # key, volume
     187    my $uri = $neb->create_object('foo', '~node02');
     188    Test::Nebulous->switch_node_state;
     189
     190    my $locations = $neb->find_instances('foo', '~node02', 0);
     191};
     192like($@, qr/no instances on storage volume/, "instance on invalid node (as hard_volume) not returned (find_invalid = 0)");
     193
     194# request from a hard_volume for an instance which is on an invalid node [HARD, X]
    151195Test::Nebulous->setup;
    152196eval {
     
    157201    my $locations = $neb->find_instances('foo', '~node02');
    158202};
    159 like($@, qr/no instances on storage volume/, "instance on invalid node (as hard_volume) not returned");
    160 
    161 # request from a hard_volume for an instance which is on an invalid node (find_invalid = 1)
    162 Test::Nebulous->setup;
    163 eval {
    164     # key, volume
    165     my $uri = $neb->create_object('foo', '~node02');
    166     Test::Nebulous->switch_node_state;
    167 
    168     my $locations = $neb->find_instances('foo', '~node02', 1);
    169     uri_scheme_ok($locations->[0], 'file');
    170     is($uri, $locations->[0], "URIs match");
    171 };
    172 is($@, "", "instance on invalid node (as hard_volume) returned with find_invalid is set");
    173 #like($@, qr/database error/, "instance on invalid node (as hard_volume) not returned");
    174 
    175 # request from a hard_volume for an instance which is on an invalid node (find_invalid = 0)
    176 Test::Nebulous->setup;
    177 eval {
    178     # key, volume
    179     my $uri = $neb->create_object('foo', '~node02');
    180     Test::Nebulous->switch_node_state;
    181 
    182     my $locations = $neb->find_instances('foo', '~node02', 0);
    183 };
    184 like($@, qr/no instances on storage volume/, "instance on invalid node (as hard_volume) not returned");
    185 
    186 # request from a hard_volume for an instance which is on an invalid node
    187 Test::Nebulous->setup;
    188 eval {
    189     # key, volume
    190     my $uri = $neb->create_object('foo', '~node02');
    191     Test::Nebulous->switch_node_state;
    192 
    193     my $locations = $neb->find_instances('foo', '~node02', 1);
    194 
    195     uri_scheme_ok($locations->[0], 'file');
    196     is($uri, $locations->[0], "URIs match");
    197 };
    198 
    199 # request from a hard_volume returns an instance which is not on the hard volume if available
    200 Test::Nebulous->setup;
    201 eval {
    202     # key, volume
    203     my $uri = $neb->create_object('foo', '~node01');
    204 
    205     my $locations = $neb->find_instances('foo', '~node02');
    206 
    207     uri_scheme_ok($locations->[0], 'file');
    208     is($uri, $locations->[0], "URIs match");
    209 };
     203like($@, qr/no instances on storage volume/, "instance on invalid node (as hard_volume) not returned (find_invalid not set)");
     204
     205#### TESTING the instance proximity analysis
     206Test::Nebulous->setup;
     207{
     208    my @nodedirs = Test::Nebulous->get_node_dirs();
     209
     210    # place 4 instances on specific nodes (hard targets works):
     211    my $uri1 = $neb->create_object("foo", "~node01");
     212    my $uri2 = $neb->replicate_object("foo", "~node02");
     213    my $uri3 = $neb->replicate_object("foo", "~node03");
     214    my $uri4 = $neb->replicate_object("foo", "~node08");
     215
     216    my $locations = $neb->find_instances("foo", "node01");
     217    my $Nloc = @$locations;
     218
     219    is($Nloc, 4, "found 4 instances");
     220   
     221    my $loc1 = $locations->[0];
     222    my $loc2 = $locations->[1];
     223    my $loc3 = $locations->[2];
     224    my $loc4 = $locations->[3];
     225
     226    # choosing instance relative to node01 yields:
     227    like($loc1, qr/$nodedirs[0]/, "node01 is closest to node01");   
     228    like($loc2, qr/$nodedirs[1]/, "node02 is 2nd closest to node01");
     229    like($loc3, qr/$nodedirs[2]/, "node03 is 3rd closest to node01");
     230    like($loc4, qr/$nodedirs[7]/, "node08 is 4th closest to node01");
     231}
     232
     233#### TESTING the instance proximity analysis
     234Test::Nebulous->setup;
     235{
     236    my @nodedirs = Test::Nebulous->get_node_dirs();
     237
     238    # place 4 instances on specific nodes (hard targets works):
     239    my $uri1 = $neb->create_object("foo", "~node01");
     240    my $uri2 = $neb->replicate_object("foo", "~node02");
     241    my $uri3 = $neb->replicate_object("foo", "~node03");
     242    my $uri4 = $neb->replicate_object("foo", "~node08");
     243
     244    my $locations = $neb->find_instances("foo", "node03");
     245    my $Nloc = @$locations;
     246
     247    is($Nloc, 4, "found 4 instances");
     248   
     249    my $loc1 = $locations->[0]; #
     250    my $loc2 = $locations->[1]; #
     251    my $loc3 = $locations->[2]; #
     252    my $loc4 = $locations->[3]; #
     253
     254    # choosing instance relative to node01 yields:
     255    like($loc1, qr/$nodedirs[2]/, "node03 is closest to node03");
     256    like($loc2, qr/$nodedirs[7]/, "node08 is 2nd closest to node03");
     257    like($loc3, qr/$nodedirs[1]/, "node02 is 3rd closest to node03");
     258    like($loc4, qr/$nodedirs[0]/, "node08 is 4th closest to node03");
     259}
    210260
    211261########
Note: See TracChangeset for help on using the changeset viewer.