|
| 1 | +#!/usr/bin/env bash |
| 2 | +# |
| 3 | +# Delta sharing node Integration Test |
| 4 | +# |
| 5 | +# Author: Ritesh Karki <ritesh.karki@rwth-aachen.de> |
| 6 | +# SPDX-FileCopyrightText: 2014-2025 Institute for Automation of Complex Power Systems, RWTH Aachen University |
| 7 | +# SPDX-License-Identifier: Apache-2.0 |
| 8 | + |
| 9 | +echo "Test not ready" |
| 10 | +exit 99 |
| 11 | + |
| 12 | +set -e |
| 13 | + |
| 14 | +DIR=$(mktemp -d) |
| 15 | +pushd ${DIR} |
| 16 | + |
| 17 | +function finish { |
| 18 | + popd |
| 19 | + rm -rf ${DIR} |
| 20 | +} |
| 21 | +trap finish EXIT |
| 22 | + |
| 23 | +# Test data paths |
| 24 | +TEST_PROFILE="${DIR}/open_delta_profile.json" |
| 25 | +TEST_CACHE="${DIR}/delta_sharing_test_cache" |
| 26 | +TEST_CONFIG="${DIR}/test_config.json" |
| 27 | +TEST_OUTPUT="${DIR}/test_output.json" |
| 28 | +TEST_INPUT="${DIR}/test_input.json" |
| 29 | + |
| 30 | + |
| 31 | +# Set up test environment |
| 32 | +function setup_test { |
| 33 | + # Create test cache directory |
| 34 | + mkdir -p "${TEST_CACHE}" |
| 35 | + |
| 36 | + cat > "${TEST_PROFILE}" << 'EOF' |
| 37 | +{ |
| 38 | + "shareCredentialsVersion": 1, |
| 39 | + "endpoint": "https://sharing.delta.io/delta-sharing/", |
| 40 | + "bearerToken": "faaie590d541265bcab1f2de9813274bf233" |
| 41 | +} |
| 42 | +EOF |
| 43 | + |
| 44 | + cat > "${TEST_INPUT}" << 'EOF' |
| 45 | +{ |
| 46 | + "nodes": { |
| 47 | + "signal_source": { |
| 48 | + "type": "signal", |
| 49 | + "signal": "sine", |
| 50 | + "rate": 10, |
| 51 | + "limit": 5 |
| 52 | + } |
| 53 | + }, |
| 54 | + "paths": [ |
| 55 | + { |
| 56 | + "in": "signal_source" |
| 57 | + } |
| 58 | + ] |
| 59 | +} |
| 60 | +EOF |
| 61 | + |
| 62 | + cat > "${TEST_CONFIG}" << EOF |
| 63 | +{ |
| 64 | + "nodes": { |
| 65 | + "delta_reader": { |
| 66 | + "type": "delta_sharing", |
| 67 | + "profile_path": "${TEST_PROFILE}", |
| 68 | + "cache_dir": "${TEST_CACHE}", |
| 69 | + "table_path": "open-datasets.share#delta_sharing.default.COVID_19_NYT", |
| 70 | + "op": "read", |
| 71 | + "batch_size": 10 |
| 72 | + }, |
| 73 | + "delta_writer": { |
| 74 | + "type": "delta_sharing", |
| 75 | + "profile_path": "${TEST_PROFILE}", |
| 76 | + "cache_dir": "${TEST_CACHE}", |
| 77 | + "table_path": "open-delta-sharing.s3.us-west-2.amazonaws.com#samples.test_output", |
| 78 | + "op": "write", |
| 79 | + "batch_size": 10 |
| 80 | + }, |
| 81 | + "file1": { |
| 82 | + "type": "file", |
| 83 | + "uri": "${TEST_OUTPUT}", |
| 84 | + "format": "json" |
| 85 | + } |
| 86 | + }, |
| 87 | + "paths": [ |
| 88 | + { |
| 89 | + "in": "delta_reader", |
| 90 | + "out": "file1" |
| 91 | + } |
| 92 | + ] |
| 93 | +} |
| 94 | +EOF |
| 95 | + |
| 96 | +} |
| 97 | + |
| 98 | +# Test 1: Verify Delta Sharing credentials |
| 99 | +function test_credentials { |
| 100 | + echo "Testing Delta Sharing credentials..." |
| 101 | + |
| 102 | + if [ ! -f "${TEST_PROFILE}" ]; then |
| 103 | + log_error "Profile file not found: ${TEST_PROFILE}" |
| 104 | + return 1 |
| 105 | + fi |
| 106 | + |
| 107 | + # Check if profile has valid JSON structure |
| 108 | + if ! python3 -m json.tool "${TEST_PROFILE}" > /dev/null 2>&1; then |
| 109 | + log_error "Invalid JSON in profile file" |
| 110 | + return 1 |
| 111 | + fi |
| 112 | + |
| 113 | + |
| 114 | + log_info "Credentials validation test passed" |
| 115 | + return 0 |
| 116 | +} |
| 117 | + |
| 118 | +# Test 2: Test Delta Sharing connection |
| 119 | +function test_connection { |
| 120 | + echo "Testing Delta Sharing server connection..." |
| 121 | + |
| 122 | + if timeout 2 "${VILLAS_NODE}" -c "${TEST_CONFIG}" --start 2>&1 | grep -q "Delta Sharing"; then |
| 123 | + log_info "Connection test passed (Delta Sharing client initialized)" |
| 124 | + return 0 |
| 125 | + else |
| 126 | + log_error "Connection test failed" |
| 127 | + return 1 |
| 128 | + fi |
| 129 | +} |
| 130 | + |
| 131 | +# TODO: Test 3, to test data reading from Delta Sharing |
| 132 | +function test_data_reading { |
| 133 | + echo "Testing data reading from Delta Sharing..." |
| 134 | + |
| 135 | + echo "Attempting to read data from COVID-19_NYT table..." |
| 136 | + |
| 137 | + echo "Data reading test completed" |
| 138 | + return 0 |
| 139 | +} |
| 140 | + |
| 141 | +# Test 4: Test node configuration parsing |
| 142 | +function test_config_parsing { |
| 143 | + echo "Testing node configuration parsing..." |
| 144 | + |
| 145 | + if ! "${VILLAS_NODE}" --help | grep -i "delta_sharing"; then |
| 146 | + echo "delta_sharing node type not found in villas-node" |
| 147 | + return 1 |
| 148 | + else |
| 149 | + echo "delta_sharing node type present in villas-node" |
| 150 | + fi |
| 151 | + |
| 152 | + #Test if the configuration can be parsed |
| 153 | + if ! ("${VILLAS_NODE}" "${TEST_CONFIG}" &); then |
| 154 | + echo "Node configuration check failed" |
| 155 | + return 1 |
| 156 | + else |
| 157 | + echo "running example configuration for 3 seconds" |
| 158 | + DELTA_PID=$! |
| 159 | + kill $DELTA_PID |
| 160 | + fi |
| 161 | + # wait 3 |
| 162 | + # kill $(DELTA_PID) |
| 163 | + |
| 164 | + echo "Configuration parsing test passed" |
| 165 | + return 0 |
| 166 | +} |
| 167 | + |
| 168 | +# Test 5: Test node lifecycle |
| 169 | +function test_node_lifecycle { |
| 170 | + echo "Testing node lifecycle..." |
| 171 | + |
| 172 | + if timeout 2 "${VILLAS_NODE}" -c "${TEST_CONFIG}" --start 2>&1 | grep -q "Delta Sharing\|Started"; then |
| 173 | + echo "Node lifecycle test passed" |
| 174 | + return 0 |
| 175 | + else |
| 176 | + echo "Node lifecycle test inconclusive" |
| 177 | + return 0 |
| 178 | + fi |
| 179 | +} |
| 180 | + |
| 181 | +echo "Starting Delta Sharing integration tests with open datasets server..." |
| 182 | + |
| 183 | +# Run all tests |
| 184 | +test_credentials || exit 1 |
| 185 | +test_config_parsing || exit 1 |
| 186 | +test_connection || exit 1 |
| 187 | +test_data_reading || exit 1 |
| 188 | +test_node_lifecycle || exit 1 |
| 189 | + |
| 190 | +echo "All tests passed!" |
| 191 | +exit 0 |
0 commit comments