Ejemplo n.º 1
0
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()
Ejemplo n.º 2
0
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()
Ejemplo n.º 3
0
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()
Ejemplo n.º 4
0
def test_sync_async():
  f = client.File()
  status, response = f.open(bigfile)
  assert status.ok
  
  handler = AsyncResponseHandler()
  status = f.sync(callback=handler)
  status, response, hostlist = handler.wait()
  assert status.ok
  f.close()
Ejemplo n.º 5
0
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
Ejemplo n.º 6
0
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
Ejemplo n.º 7
0
def test_truncate_async():
  f = client.File()
  status, response = f.open(smallfile, OpenFlags.DELETE)
  assert status.ok

  handler = AsyncResponseHandler()
  status = f.truncate(size=10000, callback=handler)
  assert status.ok
  status, response, hostlist = handler.wait()
  assert status.ok
  f.close()
Ejemplo n.º 8
0
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()
Ejemplo n.º 9
0
def test_stat_async():
  f = client.File()
  status, response = f.open(bigfile)
  assert status.ok

  handler = AsyncResponseHandler()
  status = f.stat(callback=handler)
  assert status.ok
  status, __, __ = handler.wait()
  assert status.ok
  f.close()
Ejemplo n.º 10
0
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()
Ejemplo n.º 11
0
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()
Ejemplo n.º 12
0
def test_write_async():
  f = client.File()
  status, response = f.open(smallfile, OpenFlags.DELETE)
  assert status.ok
  
  handler = AsyncResponseHandler()
  status = f.write(smallbuffer, callback=handler)
  status, response, hostlist = handler.wait()
  assert status.ok
  status, response = f.read()
  assert status.ok
  assert len(response) == len(smallbuffer)

  f.close()
Ejemplo n.º 13
0
def test_open_close_async():
  f = client.File()
  handler = AsyncResponseHandler()
  status = f.open(smallfile, OpenFlags.READ, callback=handler)
  assert status.ok
  status, response, hostlist = handler.wait()
  assert status.ok
  assert f.is_open()
  
  handler = AsyncResponseHandler()
  status = f.close(callback=handler)
  assert status.ok
  status, response, hostlist = handler.wait()
  assert status.ok
  assert f.is_open() == False
Ejemplo n.º 14
0
def test_vector_read_async():
  v = [(0, 100), (101, 200), (201, 200)]
  vlen = sum([vec[1] for vec in v])
  f = client.File()
  status, response = f.open(bigfile, OpenFlags.READ)
  assert status.ok
  
  handler = AsyncResponseHandler()
  status = f.vector_read(chunks=v, callback=handler)
  assert status.ok
  status, response, hostlist = handler.wait()
  print response
  print status
  assert response.size == vlen
  f.close()
Ejemplo n.º 15
0
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()
Ejemplo n.º 16
0
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()
Ejemplo n.º 17
0
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
Ejemplo n.º 18
0
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
Ejemplo n.º 19
0
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()
Ejemplo n.º 20
0
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()
Ejemplo n.º 21
0
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