forked from apache/gravitino
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[apache#2756] feat(PyClient): Integration test with Gravitino Python …
…client (apache#2797) ### What changes were proposed in this pull request? Add two Gradle command in the client-python module 1. `./gradlew :clients:client-python:test` 2. `./gradlew :clients:client-python: integrationTest` ### Why are the changes needed? Proved a real test environment for Gravitino server. Fix: apache#2756 ### Does this PR introduce _any_ user-facing change? N/A ### How was this patch tested? CI Passed
- Loading branch information
1 parent
98ca947
commit 6c6d5cb
Showing
8 changed files
with
153 additions
and
6 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
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
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
# Copyright 2024 Datastrato Pvt Ltd. | ||
# This software is licensed under the Apache License version 2. | ||
# This software is licensed under the Apache License version 2. | ||
requests |
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,101 @@ | ||
""" | ||
Copyright 2024 Datastrato Pvt Ltd. | ||
This software is licensed under the Apache License version 2. | ||
""" | ||
import logging | ||
import os | ||
import unittest | ||
import subprocess | ||
import time | ||
import requests | ||
|
||
from gravitino import GravitinoClient | ||
from gravitino.constants import TIMEOUT | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def check_gravitino_server_status(): | ||
try: | ||
response = requests.get("http://localhost:8090/api/version") | ||
response.raise_for_status() # raise an exception for bad status codes | ||
response.close() | ||
return True | ||
except requests.exceptions.RequestException as e: | ||
logger.error("Failed to access the server: {}", e) | ||
return False | ||
|
||
|
||
def _init_logging(): | ||
logging.basicConfig(level=logging.DEBUG) | ||
console_handler = logging.StreamHandler() | ||
console_handler.setLevel(logging.DEBUG) | ||
logger.addHandler(console_handler) | ||
|
||
|
||
# Provide real test environment for the Gravitino Server | ||
class IntegrationTestEnv(unittest.TestCase): | ||
GravitinoHome = None | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
_init_logging() | ||
logger.info("Starting integration test environment...") | ||
cls.GravitinoHome = os.environ.get('GRAVITINO_HOME') | ||
if cls.GravitinoHome is None: | ||
logger.warning('WARN: Currently, Python Client integration test only runs in the Gradle build environment, ' | ||
'Please execute `./gradlew :clients:client-python:test` in the gravitino project root directory.') | ||
quit(0) | ||
|
||
# Start Gravitino Server | ||
result = subprocess.run([cls.GravitinoHome + '/bin/gravitino.sh', 'start'], capture_output=True, text=True) | ||
if result.stdout: | ||
logger.info("stdout: %s", result.stdout) | ||
if result.stderr: | ||
logger.info("stderr: %s", result.stderr) | ||
|
||
gravitinoServerRunning = False | ||
for i in range(5): | ||
logger.info("Monitoring Gravitino server status. Attempt %s", i + 1) | ||
if check_gravitino_server_status(): | ||
logger.debug("Gravitino Server is running") | ||
gravitinoServerRunning = True | ||
break | ||
else: | ||
logger.debug("Gravitino Server is not running") | ||
time.sleep(1) | ||
|
||
if not gravitinoServerRunning: | ||
logger.error("ERROR: Can't start Gravitino server!") | ||
quit(0) | ||
|
||
cls.client = GravitinoClient("http://localhost:8090", timeout=TIMEOUT) | ||
|
||
@classmethod | ||
def tearDownClass(cls): | ||
logger.info("Stop integration test environment...") | ||
result = subprocess.run([cls.GravitinoHome + '/bin/gravitino.sh', 'stop'], capture_output=True, text=True) | ||
if result.stdout: | ||
logger.info("stdout: %s", result.stdout) | ||
if result.stderr: | ||
logger.info("stderr: %s", result.stderr) | ||
|
||
gravitinoServerRunning = True | ||
for i in range(5): | ||
logger.debug("Monitoring Gravitino server status. Attempt %s", i + 1) | ||
if check_gravitino_server_status(): | ||
logger.debug("Gravitino server still running") | ||
time.sleep(1) | ||
else: | ||
logger.debug("Stop Gravitino server successes!") | ||
gravitinoServerRunning = False | ||
break | ||
|
||
if gravitinoServerRunning: | ||
logger.error("ERROR: Can't stop Gravitino server!") | ||
|
||
# Determine whether to run from Gradle base on environment variables | ||
# integrated test environment (ITE) | ||
@staticmethod | ||
def not_in_ITE(): | ||
return os.environ.get('GRAVITINO_HOME') is None and os.environ.get('PROJECT_VERSION') is None |
23 changes: 23 additions & 0 deletions
23
clients/client-python/tests/test_integration_gravitino_client.py
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,23 @@ | ||
""" | ||
Copyright 2024 Datastrato Pvt Ltd. | ||
This software is licensed under the Apache License version 2. | ||
""" | ||
|
||
import os | ||
import unittest | ||
from tests.integration_test_env import IntegrationTestEnv | ||
|
||
|
||
@unittest.skipIf(IntegrationTestEnv.not_in_ITE(), | ||
"Currently, Python Client integration test only runs in the Gradle build environment") | ||
class IntegrationTestGravitinoClient(IntegrationTestEnv): | ||
def test_version(self): | ||
versionDTO = self.client.version | ||
assert versionDTO['version'] is not None | ||
|
||
# Get project version from environment (Setting by Gradle build script `build.gradle.kts`), | ||
# But if you directly execute this test in IDEA, maybe can not get it. | ||
projectVersion = os.environ.get('PROJECT_VERSION', '') | ||
|
||
if projectVersion != '': | ||
assert versionDTO['version'] == projectVersion |
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