IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Nov 27, 2019, 12:04:14 PM (7 years ago)
Author:
eugene
Message:

merging updates to Nebulous from EAM dev branch ipp-20191011

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Nebulous-Server/t/08_server_find_instances.t

    r24362 r41172  
    88use warnings FATAL => qw( all );
    99
    10 use Test::More tests => 19;
     10use Test::More tests => 44;
    1111
    1212use lib qw( ./t ./lib );
     
    2222);
    2323
    24 Test::Nebulous->setup;
    25 
     24# XXX previously, the logic was: if we request a hard volume location
     25# using ~node, then we would give an error if no data is available except on that node.
     26
     27# the code has been modified so that the requested storage object is provided if possible,
     28# even if the apparently "hard" target did not exist.
     29
     30Test::Nebulous->setup;
     31Test::Nebulous->cleanup; # make sure the database is reset before running any tests
     32
     33# for (my $i = 0; $i < $Nloc; $i++) {
     34#       my $loc = $locations->[$i];
     35#       print "location: $loc\n";
     36#}
     37
     38Test::Nebulous->setup;
    2639{
    2740    # key
     
    3548
    3649Test::Nebulous->setup;
    37 
    3850{
    3951    # key
     
    4961
    5062Test::Nebulous->setup;
    51 
    5263{
    5364    # key, volume
     
    6172
    6273Test::Nebulous->setup;
    63 
    6474{
    6575    # key, volume
     
    7383
    7484Test::Nebulous->setup;
    75 
    7685{
    7786    # key, volume
     
    8594
    8695Test::Nebulous->setup;
    87 
    8896{
    8997    # key
     
    98106}
    99107
    100 # object exists but instance is on a different volume
    101 Test::Nebulous->setup;
    102 
     108# request from a hard_volume returns an instance which is not on the hard volume if available
     109Test::Nebulous->setup;
    103110eval {
    104111    # key, volume
    105112    my $uri = $neb->create_object('foo', '~node01');
    106 
    107113    my $locations = $neb->find_instances('foo', '~node02');
    108 };
    109 like($@, qr/no instances on storage volume/, 'instances on a different volume');
     114
     115    uri_scheme_ok($locations->[0], 'file');
     116    is($uri, $locations->[0], "URIs match");
     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]
     136Test::Nebulous->setup;
     137eval {
     138    # key, volume
     139    my $uri = $neb->create_object('foo', '~node02');
     140    Test::Nebulous->switch_node_state;
     141
     142    my $locations = $neb->find_instances('foo', 'node02', 1);
     143    uri_scheme_ok($locations->[0], 'file');
     144    is($uri, $locations->[0], "URIs match");
     145};
     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]
     149Test::Nebulous->setup;
     150eval {
     151    # key, volume
     152    my $uri = $neb->create_object('foo', '~node02');
     153    Test::Nebulous->switch_node_state;
     154
     155    my $locations = $neb->find_instances('foo', 'node02', 0);
     156};
     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]
     195Test::Nebulous->setup;
     196eval {
     197    # key, volume
     198    my $uri = $neb->create_object('foo', '~node02');
     199    Test::Nebulous->switch_node_state;
     200
     201    my $locations = $neb->find_instances('foo', '~node02');
     202};
     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}
     260
     261########
    110262
    111263Test::Nebulous->setup;
     
    125277
    126278Test::Nebulous->setup;
    127 
    128 eval {
    129     $neb->find_instances();
    130 };
    131 like($@, qr/1 - 2 were expected/, "no params");
     279eval {
     280    my $locations = $neb->find_instances();
     281};
     282like($@, qr/1 - 3 were expected/, "no params");
     283# note the new API expects 1-3 parameters
    132284
    133285Test::Nebulous->setup;
     
    135287eval {
    136288    $neb->create_object('foo');
    137     $neb->find_instances('foo', 'node01', 3);
    138 };
    139 like($@, qr/1 - 2 were expected/, "too many params");
     289    $neb->find_instances('foo', 'node01', 3, 5);
     290};
     291like($@, qr/1 - 3 were expected/, "too many params");
     292# note the new API expects 1-3 parameters
    140293
    141294Test::Nebulous->cleanup;
Note: See TracChangeset for help on using the changeset viewer.