2023-06-15 11:14:22 +05:30
|
|
|
# Copyright 2021 Collate
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
|
|
|
"""
|
|
|
|
Test Redshift using the topology
|
|
|
|
"""
|
|
|
|
|
2022-08-30 22:10:51 +05:30
|
|
|
from unittest import TestCase
|
|
|
|
from unittest.mock import patch
|
|
|
|
|
|
|
|
from metadata.generated.schema.metadataIngestion.workflow import (
|
|
|
|
OpenMetadataWorkflowConfig,
|
|
|
|
)
|
2022-12-27 15:00:22 +01:00
|
|
|
from metadata.ingestion.source.database.redshift.metadata import RedshiftSource
|
2022-08-30 22:10:51 +05:30
|
|
|
|
2023-04-11 20:58:31 +05:30
|
|
|
mock_redshift_config = {
|
2022-08-30 22:10:51 +05:30
|
|
|
"source": {
|
|
|
|
"type": "redshift",
|
|
|
|
"serviceName": "local_redshift",
|
|
|
|
"serviceConnection": {
|
|
|
|
"config": {
|
|
|
|
"type": "Redshift",
|
|
|
|
"username": "username",
|
|
|
|
"password": "password",
|
|
|
|
"database": "database",
|
|
|
|
"hostPort": "cluster.name.region.redshift.amazonaws.com:5439",
|
2024-04-19 11:38:27 +05:30
|
|
|
"sslMode": "verify-full",
|
|
|
|
"sslConfig": {
|
|
|
|
"caCertificate": "CA certificate content",
|
|
|
|
},
|
2022-08-30 22:10:51 +05:30
|
|
|
}
|
|
|
|
},
|
|
|
|
"sourceConfig": {"config": {"type": "DatabaseMetadata"}},
|
|
|
|
},
|
|
|
|
"sink": {"type": "metadata-rest", "config": {}},
|
|
|
|
"workflowConfig": {
|
|
|
|
"openMetadataServerConfig": {
|
|
|
|
"hostPort": "http://localhost:8585/api",
|
2022-09-26 16:19:47 +05:30
|
|
|
"authProvider": "openmetadata",
|
2025-01-02 13:07:55 +05:30
|
|
|
"securityConfig": {"jwtToken": "redshift"},
|
2022-08-30 22:10:51 +05:30
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
RAW_DIST_STYLE = ["KEY(eventid)", "EVEN", "ALL"]
|
|
|
|
|
2024-02-28 07:11:00 +01:00
|
|
|
EXPECTED_PARTITION_COLUMNS = ["eventid", None, None]
|
2022-08-30 22:10:51 +05:30
|
|
|
|
|
|
|
|
2023-04-11 20:58:31 +05:30
|
|
|
class RedshiftUnitTest(TestCase):
|
2023-01-02 13:52:27 +01:00
|
|
|
@patch(
|
|
|
|
"metadata.ingestion.source.database.common_db_source.CommonDbSourceService.test_connection"
|
|
|
|
)
|
2022-08-30 22:10:51 +05:30
|
|
|
def __init__(self, methodName, test_connection) -> None:
|
|
|
|
super().__init__(methodName)
|
|
|
|
test_connection.return_value = False
|
2024-06-07 04:36:17 +02:00
|
|
|
self.config = OpenMetadataWorkflowConfig.model_validate(mock_redshift_config)
|
2022-08-30 22:10:51 +05:30
|
|
|
self.redshift_source = RedshiftSource.create(
|
2023-04-11 20:58:31 +05:30
|
|
|
mock_redshift_config["source"],
|
2022-08-30 22:10:51 +05:30
|
|
|
self.config.workflowConfig.openMetadataServerConfig,
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_partition_parse_columns(self):
|
|
|
|
for i in range(len(RAW_DIST_STYLE)):
|
2024-02-28 07:11:00 +01:00
|
|
|
with self.subTest(i=i):
|
|
|
|
self.assertEqual(
|
|
|
|
self.redshift_source._get_partition_key(RAW_DIST_STYLE[i]),
|
|
|
|
EXPECTED_PARTITION_COLUMNS[i],
|
|
|
|
)
|
2024-04-19 11:38:27 +05:30
|
|
|
|
|
|
|
@patch("sqlalchemy.engine.base.Engine")
|
|
|
|
@patch(
|
|
|
|
"metadata.ingestion.source.database.common_db_source.CommonDbSourceService.connection"
|
|
|
|
)
|
|
|
|
def test_close_connection(self, engine, connection):
|
|
|
|
connection.return_value = True
|
|
|
|
self.redshift_source.close()
|