def test_write_big_async(): f = client.File() pytest.raises(ValueError, 'f.read()') status, __ = f.open(bigfile, OpenFlags.DELETE, open_mode) assert status.ok rand_data = os.urandom(64 * 1024) max_size = 512 * 1024 # 512 K offset = 0 lst_handlers = [] while offset <= max_size: status, __ = f.write(smallbuffer) assert status.ok handler = AsyncResponseHandler() lst_handlers.append(handler) status = f.write(rand_data, offset, callback=handler) assert status.ok offset = offset + len(smallbuffer) + len(rand_data) # Wait for async write responses for handler in lst_handlers: status, __, __ = handler.wait() assert status.ok f.close()
def test_open_close_async(): f = client.File() handler = AsyncResponseHandler() status = f.open(smallfile, OpenFlags.READ, callback=handler) assert status.ok status, __, __ = handler.wait() assert status.ok assert f.is_open() # Close async handler = AsyncResponseHandler() status = f.close(callback=handler) assert status.ok status, __, __ = handler.wait() assert status.ok assert f.is_open() == False
def test_sync_async(): f = client.File() status, response = f.open(bigfile) assert status.ok handler = AsyncResponseHandler() status = f.sync(callback=handler) status, __, __ = handler.wait() assert status.ok f.close()
def test_locate_async(): c = client.FileSystem(SERVER_URL) handler = AsyncResponseHandler() response = c.locate('/tmp', OpenFlags.REFRESH, callback=handler) status, response, hostlist = handler.wait() assert status.ok for item in response: assert item
def test_query_async(): c = client.FileSystem(SERVER_URL) handler = AsyncResponseHandler() status = c.query(QueryCode.STATS, 'a', callback=handler) assert status.ok status, response, hostlist = handler.wait() assert status.ok assert response print response
def test_truncate_async(): f = client.File() status, __ = f.open(smallfile, OpenFlags.DELETE) assert status.ok handler = AsyncResponseHandler() status = f.truncate(size=10000, callback=handler) assert status.ok status, __, __ = handler.wait() assert status.ok f.close()
def test_read_async(): f = client.File() status, response = f.open(bigfile, OpenFlags.READ) assert status.ok status, response = f.stat() size = response.size handler = AsyncResponseHandler() status = f.read(callback=handler) assert status.ok status, response, hostlist = handler.wait() assert status.ok assert len(response) == size f.close()
def test_write_async(): f = client.File() status, __ = f.open(smallfile, OpenFlags.DELETE, open_mode) assert status.ok # Write async handler = AsyncResponseHandler() status = f.write(smallbuffer, callback=handler) status, __, __ = handler.wait() assert status.ok # Read sync status, response = f.read() assert status.ok assert len(response) == len(smallbuffer) f.close()
def async (func, args, hasReturnObject): handler = AsyncResponseHandler() status = func(callback=handler, *args) print status assert status.ok status, response, hostlist = handler.wait() assert status.ok if response: assert response for host in hostlist: assert host.url print host.url if hasReturnObject: assert response
def test_dirlist_async(): c = client.FileSystem(SERVER_URL) handler = AsyncResponseHandler() status = c.dirlist('/tmp', DirListFlags.STAT, callback=handler) assert status.ok status, response, hostlist = handler.wait() assert status.ok for h in hostlist: print h.url for item in response: assert item.name print item.statinfo assert item.statinfo assert item.hostaddr assert hostlist
def test_vector_read_async(): v = [(0, 100), (101, 200), (201, 200)] vlen = sum([vec[1] for vec in v]) f = client.File() status, __ = f.open(bigfile, OpenFlags.READ) assert status.ok status, stat_info = f.stat() assert status.ok handler = AsyncResponseHandler() status = f.vector_read(chunks=v, callback=handler) assert status.ok # If big enough file everything shoud be ok if (stat_info.size > max([off + sz for (off, sz) in v])): status, response, hostlist = handler.wait() assert status.ok assert response.size == vlen else: status, __, __ = handler.wait() assert not status.ok f.close()