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(
#!/usr/bin/env python2 from bithordetest import message, BithordeD, TestConnection if __name__ == '__main__': bithorded = BithordeD(config={ 'friend.evilservant.addr': '', }) 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,
bithorded = BithordeD(config={ 'friend.server.addr': '', 'cache': { 'dir': 'cache', '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()
#!/usr/bin/env python2 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))
INITIAL_REQUEST = randint(0, (2**64) - 1) if __name__ == '__main__': bithorded = BithordeD(config={ 'friend.upstream1.addr': '', 'friend.upstream2.addr': '', }) upstream1 = TestConnection(bithorded, name='upstream1') upstream2 = TestConnection(bithorded, name='upstream2') downstream1 = TestConnection(bithorded, name='downstream1') downstream2 = TestConnection(bithorded, name='downstream2') # Request an asset-session downstream1.send( 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))