if __name__ == '__main__': ASSET = "A" * 87234 ASSET_TTH = "5V7AM5PT6PVGTCWITETZUFPBTCDK2DPHBJMTFWI" bithorded = BithordeD(config={ 'cache': { 'dir': Cache() }, 'client.tester.addr': '', }) conn = TestConnection(bithorded, name='tester') # Open an invalid handle conn.send( message.BindRead(handle=1, ids=[TigerId("IDONOTEXISTO")], timeout=500)) conn.expect(message.AssetStatus(handle=1, status=message.NOTFOUND)) # Create small asset conn.send(message.BindWrite(handle=1, size=len(ASSET))) conn.expect(message.AssetStatus(handle=1, status=message.SUCCESS)) conn.send(message.DataSegment(handle=1, offset=0, content=ASSET)) conn.expect( message.AssetStatus(handle=1, status=message.SUCCESS, ids=[TigerId(ASSET_TTH)])) conn.send(message.BindRead(handle=1, ids=[TigerId(ASSET_TTH)], timeout=500)) conn.expect( message.AssetStatus(handle=1,
}) conn = TestConnection(bithorded, name='tester') server = TestConnection(bithorded, name='evilservant') # Open a valid handle conn.send( message.BindRead(handle=1, ids=[ message.Identifier(type=message.TREE_TIGER, id='NON-EXISTANT') ], timeout=500)) assetReq = server.expect(message.BindRead) server.send( message.AssetStatus(handle=assetReq.handle, ids=assetReq.ids, status=message.SUCCESS, size=1024)) conn.expect( message.AssetStatus(handle=1, ids=assetReq.ids, status=message.SUCCESS)) # Send a pending read-request. conn.send( message.Read.Request(reqId=1, handle=1, offset=0, size=1024, timeout=500)) server.expect( message.Read.Request(handle=assetReq.handle, offset=0, size=1024))
'size': 8192, }, }) server = TestConnection(bithorded, name='server') client = TestConnection(bithorded, name='client') dummy_ids = [ message.Identifier(type=message.TREE_TIGER, id='NON-EXISTANT') ] # Send request, and wait for it to arrive at server and time out client.send(message.BindRead(handle=1, ids=dummy_ids, timeout=50)) server_asset = server.expect(message.BindRead) server.send( message.AssetStatus(handle=server_asset.handle, ids=server_asset.ids, size=ASSET_SIZE, status=message.SUCCESS)) client.expect(message.AssetStatus(handle=1, status=message.SUCCESS)) # Delayed cache-creation works. assert len(os.listdir('cache/assets')) == 0 import threading t = threading.Thread(target=responder, args=(server, )) t.start() for i in xrange(64, 4096, 64): client.send( message.Read.Request(reqId=1, handle=1, offset=i * 4,
from bithordetest import message, BithordeD, TestConnection if __name__ == '__main__': bithorded = BithordeD(config={ 'friend.deadservant.addr': '' }) server = TestConnection(bithorded, name='deadservant') conn = TestConnection(bithorded, name='tester') dummy_ids = [message.Identifier(type=message.TREE_TIGER, id='NON-EXISTANT')] # Send request, and wait for it to arrive at server and time out conn.send(message.BindRead(handle=1, ids=dummy_ids, timeout=50)) req = server.expect(message.BindRead) bithorded.wait_for("Failed upstream deadservant") conn.expect(message.AssetStatus(handle=1, status=message.NOTFOUND)) # BithordeD should now have closed the connection. Hold the confirmation. req = server.expect(message.BindRead(handle=req.handle, ids=[])) # Re-bind, now with responding source conn.send(message.BindRead(handle=1, ids=dummy_ids, timeout=5000)) req2 = server.expect(message.BindRead(ids=dummy_ids)) assert req.handle != req2.handle # Since we did not confirm the close before, bithorde should not yet have re-used the handle. server.send(message.AssetStatus(handle=req2.handle, ids=req2.ids, status=message.SUCCESS)) conn.expect(message.AssetStatus(handle=1, status=message.SUCCESS)) # Now close both handles and confirm the closing server.send(message.AssetStatus(handle=req.handle, status=message.NOTFOUND)) conn.send(message.BindRead(handle=1)) # We have to close the client-reference first req2 = server.expect(message.BindRead(ids=[]))
message.BindRead(handle=1, ids=ASSET_IDS, timeout=500, requesters=[INITIAL_REQUEST])) req1 = upstream1.expect(message.BindRead) assert len(req1.requesters) > 1 assert INITIAL_REQUEST in req1.requesters assert INITIAL_REQUEST == req1.requesters[ -1] # Try to keep backwards compatibility server_id = next(x for x in req1.requesters if x != INITIAL_REQUEST) # Let upstream1 join as server upstream1.send( message.AssetStatus(handle=req1.handle, status=message.SUCCESS, ids=ASSET_IDS, servers=[99998888], size=15)) resp = downstream1.expect(message.AssetStatus) assert len(resp.servers) > 1 assert 99998888 in resp.servers assert server_id in resp.servers # Let upstream2 join as server req2 = upstream2.expect(message.BindRead) upstream2.send( message.AssetStatus(handle=req2.handle, status=message.SUCCESS, ids=ASSET_IDS, servers=[12345], size=15))