-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
132 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from tests.conftest import TEST_ROOT | ||
|
||
|
||
def test_simple_fsspec(alluxio_file_system): | ||
alluxio_file_system.ls(TEST_ROOT) # no error | ||
|
||
|
||
def test_simple_etcd_fsspec(etcd_alluxio_file_system): | ||
etcd_alluxio_file_system.ls(TEST_ROOT) # no error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import os | ||
import random | ||
|
||
from alluxiofs import AlluxioFileSystem | ||
from tests.conftest import ALLUXIO_FILE_PATH | ||
from tests.conftest import LOCAL_FILE_PATH | ||
|
||
NUM_TESTS = 10 | ||
|
||
import logging | ||
|
||
LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
def validate_read_range( | ||
alluxio_file_system: AlluxioFileSystem, | ||
alluxio_file_path, | ||
local_file_path, | ||
offset, | ||
length, | ||
): | ||
alluxio_data = alluxio_file_system.cat_file( | ||
alluxio_file_path, offset, offset + length | ||
) | ||
|
||
with open(local_file_path, "rb") as local_file: | ||
local_file.seek(offset) | ||
local_data = local_file.read(length) | ||
|
||
try: | ||
assert alluxio_data == local_data | ||
except AssertionError: | ||
error_message = ( | ||
f"Data mismatch between Alluxio and local file\n" | ||
f"Alluxio file path: {alluxio_file_path}\n" | ||
f"Local file path: {local_file_path}\n" | ||
f"Offset: {offset}\n" | ||
f"Length: {length}\n" | ||
f"Alluxio data: {alluxio_data}\n" | ||
f"Local data: {local_data}" | ||
) | ||
raise AssertionError(error_message) | ||
|
||
|
||
def test_alluxio_fsspec_cat_file(alluxio_file_system: AlluxioFileSystem): | ||
file_size = os.path.getsize(LOCAL_FILE_PATH) | ||
|
||
alluxio_file_system.ls(ALLUXIO_FILE_PATH) | ||
|
||
# Validate normal case | ||
max_length = 13 * 1024 | ||
for _ in range(NUM_TESTS): | ||
offset = random.randint(0, file_size - 1) | ||
length = min(random.randint(1, file_size - offset), max_length) | ||
validate_read_range( | ||
alluxio_file_system, | ||
ALLUXIO_FILE_PATH, | ||
LOCAL_FILE_PATH, | ||
offset, | ||
length, | ||
) | ||
|
||
LOGGER.debug( | ||
f"Data matches between Alluxio file and local source file for {NUM_TESTS} times" | ||
) | ||
|
||
special_test_cases = [ | ||
(file_size - 1, -1), | ||
(file_size - 1, file_size + 1), | ||
(file_size, 100), | ||
] | ||
|
||
for offset, length in special_test_cases: | ||
validate_read_range( | ||
alluxio_file_system, | ||
ALLUXIO_FILE_PATH, | ||
LOCAL_FILE_PATH, | ||
offset, | ||
length, | ||
) | ||
LOGGER.debug("Passed corner test cases") | ||
|
||
|
||
def test_etcd_alluxio_fsspec_cat_file( | ||
etcd_alluxio_file_system: AlluxioFileSystem, | ||
): | ||
test_alluxio_fsspec_cat_file(etcd_alluxio_file_system) |