162
162
self.shares = self.mktemp('shares')
163
163
self.partials = self.mktemp('partials')
165
# set up Fake Main to use the testing AQ
165
# set up Fake Main to use the testing AQ, the port will
166
167
self._orig_fakemain_aq = (FakeMain._fake_AQ_class,
167
168
FakeMain._fake_AQ_params)
168
169
FakeMain._fake_AQ_class = TestActionQueue
169
FakeMain._fake_AQ_params = ('127.0.0.1', 55555, False)
170
FakeMain._fake_AQ_params = ('127.0.0.1', 0, False)
171
172
self.main = FakeMain(root_dir=self.root, shares_dir=self.shares,
172
173
data_dir=self.data, partials_dir=self.partials)
861
862
def _start_sample_webserver(self):
862
863
"""Start a web server serving content at its root"""
864
# start listening on `decide yourself` port, and fix AQ with it
863
865
website = server.Site(None)
864
webport = reactor.listenTCP(55555, website)
866
webport = reactor.listenTCP(0, website)
867
self.action_queue.port = webport.getHost().port
866
869
transport_class = webport.transport
867
870
def save_an_instance(skt, protocol, addr, sself, s, sreactor):
1330
1333
@defer.inlineCallbacks
1331
1334
def test_demark_not_marker(self):
1332
1335
"""Test demark with not a marker."""
1333
result = yield self.cmd.demark('not a marker')
1334
self.assertEqual(result, ['not a marker'])
1336
self.cmd.possible_markers = 'foo',
1337
self.cmd.foo = 'not a marker'
1338
yield self.cmd.demark()
1339
self.assertEqual(self.cmd.foo, 'not a marker')
1336
1341
@defer.inlineCallbacks
1337
1342
def test_demark_with_marker_future(self):
1340
1345
Here, on purpose, set up everything and trigger later.
1342
1347
marker = MDMarker('foo')
1343
d = self.cmd.demark(marker)
1348
self.cmd.possible_markers = 'foo',
1349
self.cmd.foo = marker
1350
d = self.cmd.demark()
1345
1352
self.action_queue.uuid_map.set(marker, 'node_id')
1347
self.assertEqual(result, ['node_id'])
1354
self.assertEqual(self.cmd.foo, 'node_id')
1348
1355
self.assertTrue(self.handler.check_debug(
1349
1356
"waiting for the real value of marker:foo"))
1352
1359
def test_demark_with_marker_ready(self):
1353
1360
"""Test demark with a marker that had data."""
1354
1361
marker = MDMarker('foo')
1355
d = self.cmd.demark(marker)
1362
self.cmd.possible_markers = 'foo',
1363
self.cmd.foo = marker
1364
d = self.cmd.demark()
1356
1365
self.action_queue.uuid_map.set(marker, 'node_id')
1358
self.assertEqual(result, ['node_id'])
1367
self.assertEqual(self.cmd.foo, 'node_id')
1359
1368
self.assertTrue(self.handler.check_debug(
1360
1369
"waiting for the real value of marker:foo"))
1364
1373
"""Test demark with both a marker and not."""
1365
1374
# call demark with both
1366
1375
marker = MDMarker('foo')
1367
d = self.cmd.demark('notamarker', marker)
1376
self.cmd.possible_markers = 'foo', 'bar'
1377
self.cmd.foo = 'notamarker'
1378
self.cmd.bar = marker
1379
d = self.cmd.demark()
1368
1380
self.action_queue.uuid_map.set(marker, 'node_id')
1372
self.assertEqual(result, ['notamarker', 'node_id'])
1384
self.assertEqual(self.cmd.foo, 'notamarker')
1385
self.assertEqual(self.cmd.bar, 'node_id')
1373
1386
self.assertTrue(self.handler.check_debug(
1374
1387
"waiting for the real value of marker:foo"))
1375
1388
self.assertFalse(self.handler.check_debug(
1380
1393
"""Test demark getting a marker triggered ok later."""
1381
1394
# don't have the info now
1382
1395
marker = MDMarker('foo')
1383
d = self.cmd.demark(marker)
1396
self.cmd.possible_markers = 'foo',
1397
self.cmd.foo = marker
1398
d = self.cmd.demark()
1384
1399
self.assertFalse(self.handler.check_debug("for marker:foo"))
1386
1401
# set and check
1387
1402
self.action_queue.uuid_map.set(marker, 'node_id')
1389
self.assertEqual(result, ['node_id'])
1404
self.assertEqual(self.cmd.foo, 'node_id')
1390
1405
self.assertTrue(self.handler.check_debug(
1391
1406
"for marker:foo got value 'node_id'"))
1481
1498
self.assertFalse(self.cmd.running)
1483
def test_start_calls_unqueued(self):
1500
def test_queue_calls_prequeued(self):
1484
1501
"""Do the pre-queue when queued."""
1486
self.cmd.start_unqueued = lambda: called.append(True)
1503
self.cmd.pre_queue_setup = lambda: called.append(True)
1488
1505
self.assertTrue(called)
1490
def test_unqueued_calls_demark(self):
1507
def test_prequeued_calls_demark(self):
1491
1508
"""Pre-queue implies dereferencing markers."""
1493
self.cmd._get_possible_markers = lambda: called.append(True) or ()
1494
self.cmd.start_unqueued()
1510
self.cmd.demark = lambda: called.append(True)
1511
self.cmd.pre_queue_setup()
1495
1512
self.assertTrue(called)
1497
1514
@defer.inlineCallbacks
1499
1516
"""Default _start just returns a triggered deferred and sets done."""
1500
1517
yield self.cmd._start()
1502
@defer.inlineCallbacks
1503
def test_get_possible_markers_default(self):
1504
"""Non-overwritten method just returns a triggered deferred."""
1505
yield self.cmd._get_possible_markers()
1519
def test_possible_markers_default(self):
1520
"""Default value for possible markers."""
1521
self.assertEqual(self.cmd.possible_markers, ())
1507
1523
@defer.inlineCallbacks
1508
1524
def test_marker_storing(self):
1509
1525
"""Pre-queueing deferres the marker storing."""
1510
d = defer.Deferred()
1511
self.cmd.store_marker_result = lambda _: d.callback(True)
1512
self.cmd.start_unqueued()
1526
self.cmd.pre_queue_setup()
1527
yield self.cmd.markers_resolved_deferred
1515
1530
class CreateUDFTestCase(ConnectedBaseTestCase):
1516
1531
"""Test for CreateUDF ActionQueueCommand."""
1925
1940
self.assertIn(event, self.command.action_queue.event_queue.events)
1926
1941
self.assertTrue(res is None)
1928
def test_get_possible_markers(self):
1943
def test_possible_markers(self):
1929
1944
"""Test that it returns the correct values."""
1930
res = self.command._get_possible_markers()
1931
self.assertEqual(res, (VOLUME, NODE))
1933
def test_store_marker_result(self):
1934
"""Test that it stores the correct values."""
1935
self.command.store_marker_result(('a', 'b'))
1936
self.assertEqual(self.command.share_id, 'a')
1937
self.assertEqual(self.command.node_id, 'b')
1945
res = [getattr(self.command, x) for x in self.command.possible_markers]
1946
self.assertEqual(res, [VOLUME, NODE])
1940
1949
class GetPublicFilesTestCase(ConnectedBaseTestCase):
2049
2058
self.command = Download(request_queue, share_id='a_share_id',
2050
2059
node_id='a_node_id', server_hash='server_hash',
2051
2060
fileobj_factory=lambda: None)
2052
self.command.start_unqueued() # create the logger
2061
self.command.pre_queue_setup() # create the logger
2054
2063
def test_progress_information_setup(self):
2055
2064
"""Test the setting up of the progress information in ._run()."""
2135
2144
self.assertEqual(self.command.n_bytes_read_last,
2136
2145
5+TRANSFER_PROGRESS_THRESHOLD)
2138
def test_get_possible_markers(self):
2147
def test_possible_markers(self):
2139
2148
"""Test that it returns the correct values."""
2140
res = self.command._get_possible_markers()
2141
self.assertEqual(res, ('a_share_id', 'a_node_id'))
2143
def test_store_marker_result(self):
2144
"""Test that it stores the correct values."""
2145
self.command.store_marker_result(('a', 'b'))
2146
self.assertEqual(self.command.share_id, 'a')
2147
self.assertEqual(self.command.node_id, 'b')
2149
res = [getattr(self.command, x) for x in self.command.possible_markers]
2150
self.assertEqual(res, ['a_share_id', 'a_node_id'])
2149
2152
def test_cancel_set_cancelled(self):
2150
2153
"""Set the command to cancelled."""
2203
2206
hash='yadda', crc32=0, size=0,
2204
2207
fileobj_factory=lambda: None,
2205
2208
tempfile_factory=lambda: None)
2206
self.command.start_unqueued() # create the logger
2209
self.command.pre_queue_setup() # create the logger
2208
2211
def test_upload_progress_wrapper_setup(self):
2209
2212
"""Test the setting up of the progress wrapper in ._run()."""
2279
2282
hash='yadda', crc32=0, size=0,
2280
2283
fileobj_factory=lambda: None,
2281
2284
tempfile_factory=lambda: None)
2282
self.command.start_unqueued() # create the logger
2285
self.command.pre_queue_setup() # create the logger
2284
2287
def test_upload_in_progress(self):
2285
2288
"""Test Upload retries on UploadInProgress."""
2416
2419
self.command.cancelled = True
2417
2420
self.assertTrue(self.command.is_runnable)
2419
def test_get_possible_markers(self):
2422
def test_possible_markers(self):
2420
2423
"""Test that it returns the correct values."""
2421
res = self.command._get_possible_markers()
2422
self.assertEqual(res, (self.command.share_id, 'a_node_id'))
2424
def test_store_marker_result(self):
2425
"""Test that it stores the correct values."""
2426
self.command.store_marker_result(('a', 'b'))
2427
self.assertEqual(self.command.share_id, 'a')
2428
self.assertEqual(self.command.node_id, 'b')
2424
res = [getattr(self.command, x) for x in self.command.possible_markers]
2425
self.assertEqual(res, [self.command.share_id, 'a_node_id'])
2430
2427
def test_cancel_set_cancelled(self):
2431
2428
"""Set the command to cancelled."""
2530
2527
self.assertEqual('share_name', name)
2531
2528
self.assertTrue(read_only)
2533
def test_get_possible_markers(self):
2530
def test_possible_markers(self):
2534
2531
"""Test that it returns the correct values."""
2535
2532
cmd = CreateShare(self.request_queue, 'node_id', 'shareto@example.com',
2536
2533
'share_name', 'View', 'marker')
2537
res = cmd._get_possible_markers()
2538
self.assertEqual(res, ('node_id',))
2540
def test_store_marker_result(self):
2541
"""Test that it stores the correct values."""
2542
cmd = CreateShare(self.request_queue, 'node_id', 'shareto@example.com',
2543
'share_name', 'View', 'marker')
2544
cmd.store_marker_result(('a',))
2545
self.assertEqual(cmd.node_id, 'a')
2534
res = [getattr(cmd, x) for x in cmd.possible_markers]
2535
self.assertEqual(res, ['node_id'])
2548
2538
class RequestQueueManagerTestCase(FactoryBaseTestCase):
3325
3315
cmd1 = FakeCommand()
3326
3316
self.rq.waiting.append(cmd1)
3327
3317
cmd2 = GetDelta(self.rq, 'vol2', 0)
3329
3319
self.assertEqual(list(self.rq.waiting), [cmd1, cmd2])
3330
3320
self.assertTrue(self.handler.check_debug("queueing in the"))
3332
3322
def test_queued_two_different(self):
3333
3323
"""Two different queued commands is ok."""
3334
3324
cmd1 = GetDelta(self.rq, 'vol1', 0)
3336
3326
cmd2 = GetDelta(self.rq, 'vol2', 0)
3338
3328
self.assertEqual(list(self.rq.waiting), [cmd1, cmd2])
3340
3330
def test_queued_two_equals_one_in_head(self):
3341
3331
"""Second cmd equal to first is queued if later already processing."""
3342
3332
# create first command and run the queue for it to get into _head
3343
3333
cmd1 = GetDelta(self.rq, 'vol1', 0)
3347
3337
# create second command and start it, then check
3348
3338
cmd2 = GetDelta(self.rq, 'vol1', 0)
3350
3340
self.assertEqual(self.rq._head, cmd1)
3351
3341
self.assertEqual(list(self.rq.waiting), [cmd2])
3353
3343
def test_queued_two_equal_second_bigger(self):
3354
3344
"""When two equals, only survive the one with smaller gen, first."""
3355
3345
cmd1 = GetDelta(self.rq, 'vol', 3)
3357
3347
cmd2 = GetDelta(self.rq, 'vol', 5)
3359
3349
self.assertEqual(list(self.rq.waiting), [cmd1])
3360
3350
self.assertTrue(self.handler.check_debug("not queueing self"))
3362
3352
def test_queued_two_equal_second_smaller(self):
3363
3353
"""When two equals, only survive the one with smaller gen, second."""
3364
3354
cmd1 = GetDelta(self.rq, 'vol', 5)
3366
3356
cmd2 = GetDelta(self.rq, 'vol', 3)
3368
3358
self.assertEqual(list(self.rq.waiting), [cmd2])
3369
3359
self.assertTrue(self.handler.check_debug("removing previous command"))
3371
3361
def test_queued_three_equal(self):
3372
3362
"""When several equals, only survive the one with smaller gen."""
3373
3363
cmd1 = GetDelta(self.rq, 'vol', 5)
3375
3365
cmd2 = GetDelta(self.rq, 'vol', 3)
3377
3367
cmd3 = GetDelta(self.rq, 'vol', 7)
3379
3369
self.assertEqual(list(self.rq.waiting), [cmd2])
3460
3450
cmd1 = FakeCommand()
3461
3451
self.rq.waiting.append(cmd1)
3462
3452
cmd2 = GetDeltaFromScratch(self.rq, 'vol2')
3464
3454
self.assertEqual(list(self.rq.waiting), [cmd1, cmd2])
3465
3455
self.assertTrue(self.handler.check_debug("queueing in the"))
3467
3457
def test_queued_two_different(self):
3468
3458
"""Two different queued commands is ok."""
3469
3459
cmd1 = GetDeltaFromScratch(self.rq, 'vol1')
3471
3461
cmd2 = GetDeltaFromScratch(self.rq, 'vol2')
3473
3463
self.assertEqual(list(self.rq.waiting), [cmd1, cmd2])
3475
3465
def test_queued_two_equals_one_in_head(self):
3476
3466
"""Second cmd equal to first is queued if later already processing."""
3477
3467
# create first command and run the queue for it to get into _head
3478
3468
cmd1 = GetDeltaFromScratch(self.rq, 'vol1')
3482
3472
# create second command and start it, then check
3483
3473
cmd2 = GetDeltaFromScratch(self.rq, 'vol1')
3485
3475
self.assertEqual(self.rq._head, cmd1)
3486
3476
self.assertEqual(list(self.rq.waiting), [cmd2])
3488
3478
def test_queued_two_equal(self):
3489
3479
"""When two equals, only survive the first one."""
3490
3480
cmd1 = GetDeltaFromScratch(self.rq, 'vol')
3492
3482
cmd2 = GetDeltaFromScratch(self.rq, 'vol')
3494
3484
self.assertEqual(list(self.rq.waiting), [cmd1])
3495
3485
self.assertTrue(self.handler.check_debug("not queueing self"))
3521
3511
node_id='node_id', new_generation=13)
3522
3512
self.assertEqual(received, ('AQ_UNLINK_OK', (), info))
3524
def test_get_possible_markers(self):
3514
def test_possible_markers(self):
3525
3515
"""Test that it returns the correct values."""
3526
3516
cmd = Unlink(self.rq, VOLUME, 'parent_id', 'node_id')
3527
res = cmd._get_possible_markers()
3528
self.assertEqual(res, (VOLUME, 'node_id', 'parent_id'))
3530
def test_store_marker_result(self):
3531
"""Test that it stores the correct values."""
3532
cmd = Unlink(self.rq, VOLUME, 'parent_id', 'node_id')
3533
cmd.store_marker_result(('a', 'b', 'c'))
3534
self.assertEqual(cmd.share_id, 'a')
3535
self.assertEqual(cmd.node_id, 'b')
3536
self.assertEqual(cmd.parent_id, 'c')
3517
res = [getattr(cmd, x) for x in cmd.possible_markers]
3518
self.assertEqual(res, [VOLUME, 'node_id', 'parent_id'])
3539
3521
class MoveTestCase(ConnectedBaseTestCase):
3562
3544
info = dict(share_id=VOLUME, node_id='node', new_generation=13)
3563
3545
self.assertEqual(received, ('AQ_MOVE_OK', (), info))
3565
def test_get_possible_markers(self):
3547
def test_possible_markers(self):
3566
3548
"""Test that it returns the correct values."""
3567
3549
cmd = Move(self.rq, VOLUME, 'node', 'o_parent', 'n_parent', 'n_name')
3568
res = cmd._get_possible_markers()
3569
self.assertEqual(res, (VOLUME, 'node', 'o_parent', 'n_parent'))
3571
def test_store_marker_result(self):
3572
"""Test that it stores the correct values."""
3573
cmd = Move(self.rq, VOLUME, 'node', 'o_parent', 'n_parent', 'n_name')
3574
cmd.store_marker_result(('a', 'b', 'c', 'd'))
3575
self.assertEqual(cmd.share_id, 'a')
3576
self.assertEqual(cmd.node_id, 'b')
3577
self.assertEqual(cmd.old_parent_id, 'c')
3578
self.assertEqual(cmd.new_parent_id, 'd')
3550
res = [getattr(cmd, x) for x in cmd.possible_markers]
3551
self.assertEqual(res, [VOLUME, 'node', 'o_parent', 'n_parent'])
3581
3554
class MakeFileTestCase(ConnectedBaseTestCase):
3624
3597
info = dict(marker='marker', failure=failure)
3625
3598
self.assertEqual(received, ('AQ_FILE_NEW_ERROR', (), info))
3627
def test_get_possible_markers(self):
3600
def test_possible_markers(self):
3628
3601
"""Test that it returns the correct values."""
3629
3602
cmd = MakeFile(self.rq, VOLUME, 'parent', 'name', 'marker')
3630
res = cmd._get_possible_markers()
3631
self.assertEqual(res, (VOLUME, 'parent'))
3633
def test_store_marker_result(self):
3634
"""Test that it stores the correct values."""
3635
cmd = MakeFile(self.rq, VOLUME, 'parent', 'name', 'marker')
3636
cmd.store_marker_result(('a', 'b'))
3637
self.assertEqual(cmd.share_id, 'a')
3638
self.assertEqual(cmd.parent_id, 'b')
3603
res = [getattr(cmd, x) for x in cmd.possible_markers]
3604
self.assertEqual(res, [VOLUME, 'parent'])
3641
3607
class MakeDirTestCase(ConnectedBaseTestCase):
3684
3650
info = dict(marker='marker', failure=failure)
3685
3651
self.assertEqual(received, ('AQ_DIR_NEW_ERROR', (), info))
3687
def test_get_possible_markers(self):
3653
def test_possible_markers(self):
3688
3654
"""Test that it returns the correct values."""
3689
3655
cmd = MakeDir(self.rq, VOLUME, 'parent', 'name', 'marker')
3690
res = cmd._get_possible_markers()
3691
self.assertEqual(res, (VOLUME, 'parent'))
3693
def test_store_marker_result(self):
3694
"""Test that it stores the correct values."""
3695
cmd = MakeDir(self.rq, VOLUME, 'parent', 'name', 'marker')
3696
cmd.store_marker_result(('a', 'b'))
3697
self.assertEqual(cmd.share_id, 'a')
3698
self.assertEqual(cmd.parent_id, 'b')
3656
res = [getattr(cmd, x) for x in cmd.possible_markers]
3657
self.assertEqual(res, [VOLUME, 'parent'])
3701
3660
class TestDeltaList(unittest.TestCase):