Changeset 41172 for trunk/Nebulous-Server/t/08_server_find_instances.t
- Timestamp:
- Nov 27, 2019, 12:04:14 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Nebulous-Server/t/08_server_find_instances.t
r24362 r41172 8 8 use warnings FATAL => qw( all ); 9 9 10 use Test::More tests => 19;10 use Test::More tests => 44; 11 11 12 12 use lib qw( ./t ./lib ); … … 22 22 ); 23 23 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 30 Test::Nebulous->setup; 31 Test::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 38 Test::Nebulous->setup; 26 39 { 27 40 # key … … 35 48 36 49 Test::Nebulous->setup; 37 38 50 { 39 51 # key … … 49 61 50 62 Test::Nebulous->setup; 51 52 63 { 53 64 # key, volume … … 61 72 62 73 Test::Nebulous->setup; 63 64 74 { 65 75 # key, volume … … 73 83 74 84 Test::Nebulous->setup; 75 76 85 { 77 86 # key, volume … … 85 94 86 95 Test::Nebulous->setup; 87 88 96 { 89 97 # key … … 98 106 } 99 107 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 109 Test::Nebulous->setup; 103 110 eval { 104 111 # key, volume 105 112 my $uri = $neb->create_object('foo', '~node01'); 106 107 113 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 }; 118 is($@, "", "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 121 Test::Nebulous->setup; 122 eval { 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 }; 130 is($@, "", "instance on different node (as hard_volume) returned"); 131 132 ### TESTS FOR INSTANCE ON INVALID NODE 133 diag ("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] 136 Test::Nebulous->setup; 137 eval { 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 }; 146 is($@, "", "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] 149 Test::Nebulous->setup; 150 eval { 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 }; 157 like($@, 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] 160 Test::Nebulous->setup; 161 eval { 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 }; 168 like($@, 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] 171 Test::Nebulous->setup; 172 eval { 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 }; 181 is($@, "", "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] 184 Test::Nebulous->setup; 185 eval { 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 }; 192 like($@, 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] 195 Test::Nebulous->setup; 196 eval { 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 }; 203 like($@, 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 206 Test::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 234 Test::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 ######## 110 262 111 263 Test::Nebulous->setup; … … 125 277 126 278 Test::Nebulous->setup; 127 128 eval { 129 $neb->find_instances();130 };131 like($@, qr/1 - 2 were expected/, "no params"); 279 eval { 280 my $locations = $neb->find_instances(); 281 }; 282 like($@, qr/1 - 3 were expected/, "no params"); 283 # note the new API expects 1-3 parameters 132 284 133 285 Test::Nebulous->setup; … … 135 287 eval { 136 288 $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 }; 291 like($@, qr/1 - 3 were expected/, "too many params"); 292 # note the new API expects 1-3 parameters 140 293 141 294 Test::Nebulous->cleanup;
Note:
See TracChangeset
for help on using the changeset viewer.
