Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add metadata tests #75

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
66 changes: 66 additions & 0 deletions tests/test_metadata_docker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import os

from alluxio import AlluxioClient
from tests.conftest import TEST_DIR
from tests.conftest import TEST_ROOT


def validate_list_get_status(
alluxio_client: AlluxioClient, alluxio_path, local_path
):
validate_get_status(alluxio_client, alluxio_path, local_path)
if not os.path.isdir(local_path):
return
alluxio_res = alluxio_client.listdir(alluxio_path)
alluxio_listing = {item.name: item for item in alluxio_res}
local_listing = list(os.scandir(local_path))
assert len(local_listing) == len(
alluxio_listing
), "Local listing result has different length compared to alluxio_listing"
for entry in local_listing:
assert (
entry.name in alluxio_listing
), f"{entry.name} is missing in Alluxio listing"
alluxio_entry = alluxio_listing[entry.name]
expected_type = "directory" if entry.is_dir() else "file"
assert (
expected_type == alluxio_entry.type
), f"Type mismatch for {entry.name}: expected {expected_type}, got {alluxio_entry.type}"
local_mod_time_ms = int(entry.stat().st_mtime * 1000)
alluxio_mod_time_ms = alluxio_entry.last_modification_time_ms
assert (
abs(local_mod_time_ms - alluxio_mod_time_ms) <= 1000
), f"Last modification time mismatch for {entry.name}: expected {local_mod_time_ms}, got {alluxio_mod_time_ms}"
if expected_type == "file":
assert (
entry.stat().st_size == alluxio_entry.length
), f"Size mismatch for {entry.name}: expected {entry.stat().st_size}, got {alluxio_entry.length}"
validate_list_get_status(
alluxio_client,
os.path.join(alluxio_path, alluxio_entry.name),
os.path.join(local_path, entry.name),
)


def validate_get_status(
alluxio_client: AlluxioClient, alluxio_path: str, local_path: str
):
alluxio_status = alluxio_client.get_file_status(alluxio_path)
local_status = os.stat(local_path)
expected_type = "directory" if os.path.isdir(local_path) else "file"
assert (
expected_type == alluxio_status.type
), f"Type mismatch for {alluxio_path}: expected {expected_type}, got {alluxio_status.type}"
local_mod_time_ms = int(local_status.st_mtime * 1000)
assert (
abs(local_mod_time_ms - alluxio_status.last_modification_time_ms)
<= 1000
), f"Last modification time mismatch for {alluxio_path}"
if expected_type == "file":
assert (
local_status.st_size == alluxio_status.length
), f"Size mismatch for {alluxio_path}: expected {local_status.st_size}, got {alluxio_status.length}"


def test_list_get_status(alluxio_client: AlluxioClient):
validate_list_get_status(alluxio_client, TEST_ROOT, TEST_DIR)
8 changes: 4 additions & 4 deletions tests/test_worker_hash_ring.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


def test_hash_ring():
worker_hostnames_path = "tests/hash_res/workerHostnames.json"
worker_hostnames_path = "tests/assets/hash_res/workerHostnames.json"
with open(worker_hostnames_path, "r") as file:
worker_hostnames = json.load(file)

Expand All @@ -16,10 +16,10 @@ def test_hash_ring():
etcd_refresh_workers_interval=100000000,
)

hash_ring_path = "tests/hash_res/activeNodesMap.json"
hash_ring_path = "tests/assets/hash_res/activeNodesMap.json"
validate_hash_ring(hash_provider.hash_ring, hash_ring_path)

worker_list_path = "tests/hash_res/workerList.json"
worker_list_path = "tests/assets/hash_res/workerList.json"
with open(worker_list_path, "r") as file:
workers_data = json.load(file)

Expand All @@ -35,7 +35,7 @@ def test_hash_ring():
hash_provider._update_hash_ring(worker_info_map)
validate_hash_ring(hash_provider.hash_ring, hash_ring_path)

file_workers_path = "tests/hash_res/fileUrlWorkers.json"
file_workers_path = "tests/assets/hash_res/fileUrlWorkers.json"
with open(file_workers_path, "r") as file:
file_workers_data = json.load(file)

Expand Down
Loading