|
| 1 | +/** |
| 2 | + * This file is part of https://github.com/forcedotcom/datacloud-jdbc which is released under the |
| 3 | + * Apache 2.0 license. See https://github.com/forcedotcom/datacloud-jdbc/blob/main/LICENSE.txt |
| 4 | + */ |
| 5 | +package com.salesforce.datacloud.jdbc.integration; |
| 6 | + |
| 7 | +import java.sql.Connection; |
| 8 | +import java.sql.Driver; |
| 9 | +import java.sql.DriverManager; |
| 10 | +import java.sql.ResultSet; |
| 11 | +import java.sql.SQLException; |
| 12 | +import java.sql.Statement; |
| 13 | +import java.util.Properties; |
| 14 | +import lombok.extern.slf4j.Slf4j; |
| 15 | + |
| 16 | +/** |
| 17 | + * Integration test that validates the shaded JDBC JAR works correctly. |
| 18 | + * This test focuses on the critical functionality that was broken by the service file regression: |
| 19 | + * - Driver loading and registration |
| 20 | + * - Connection establishment |
| 21 | + * - Basic query execution |
| 22 | + * |
| 23 | + * Note: This test requires JVM arguments for Apache Arrow memory access on Java 9+: |
| 24 | + * --add-opens=java.base/java.nio=com.salesforce.datacloud.shaded.org.apache.arrow.memory.core,ALL-UNNAMED |
| 25 | + * (These are automatically added when using the runIntegrationTest Gradle task for Java 9+) |
| 26 | + * Java 8 doesn't need these arguments as it doesn't have the module system. |
| 27 | + */ |
| 28 | +@Slf4j |
| 29 | +public class ShadedJarIntegrationTest { |
| 30 | + |
| 31 | + private static final String DRIVER_CLASS = "com.salesforce.datacloud.jdbc.DataCloudJDBCDriver"; |
| 32 | + |
| 33 | + public static void main(String[] args) { |
| 34 | + log.info("Starting Shaded JAR Integration Test"); |
| 35 | + |
| 36 | + testDriverLoading(); |
| 37 | + testConnectionCreation(); |
| 38 | + testBasicFunctionality(); |
| 39 | + |
| 40 | + log.info("Integration test completed"); |
| 41 | + } |
| 42 | + |
| 43 | + /** |
| 44 | + * Test 1: Verify the JDBC driver can be loaded from the shaded JAR |
| 45 | + */ |
| 46 | + private static void testDriverLoading() { |
| 47 | + log.info("Test 1: Driver Loading"); |
| 48 | + |
| 49 | + try { |
| 50 | + // Load driver class |
| 51 | + Class<?> driverClass = Class.forName(DRIVER_CLASS); |
| 52 | + log.info(" Driver class loaded: {}", driverClass.getName()); |
| 53 | + |
| 54 | + // Verify driver is registered |
| 55 | + Driver driver = DriverManager.getDriver("jdbc:salesforce-datacloud:"); |
| 56 | + log.info( |
| 57 | + " Driver registered with DriverManager: {}", |
| 58 | + driver.getClass().getName()); |
| 59 | + |
| 60 | + // Verify driver accepts our URL format |
| 61 | + boolean accepts = driver.acceptsURL("jdbc:salesforce-datacloud://test.salesforce.com"); |
| 62 | + if (accepts) { |
| 63 | + log.info(" Driver accepts URL format"); |
| 64 | + } else { |
| 65 | + log.error(" Driver does not accept expected URL format"); |
| 66 | + } |
| 67 | + } catch (Exception e) { |
| 68 | + log.error(" Driver loading failed: {}", e.getMessage()); |
| 69 | + } |
| 70 | + } |
| 71 | + |
| 72 | + /** |
| 73 | + * Test 2: Verify connection can be created (tests gRPC NameResolver) |
| 74 | + * This is the critical test that would have caught the service file regression |
| 75 | + */ |
| 76 | + private static void testConnectionCreation() { |
| 77 | + log.info("Test 2: Connection Creation"); |
| 78 | + |
| 79 | + // Get connection details from system properties (for CI/CD secrets) |
| 80 | + String jdbcUrl = System.getProperty( |
| 81 | + "test.connection.url", "jdbc:salesforce-datacloud://login.test2.pc-rnd.salesforce.com"); |
| 82 | + String userName = System.getProperty("test.connection.userName", ""); |
| 83 | + String password = System.getProperty("test.connection.password", ""); |
| 84 | + String clientId = System.getProperty("test.connection.clientId", ""); |
| 85 | + String clientSecret = System.getProperty("test.connection.clientSecret", ""); |
| 86 | + |
| 87 | + Properties props = new Properties(); |
| 88 | + if (!userName.isEmpty()) props.setProperty("userName", userName); |
| 89 | + if (!password.isEmpty()) props.setProperty("password", password); |
| 90 | + if (!clientId.isEmpty()) props.setProperty("clientId", clientId); |
| 91 | + if (!clientSecret.isEmpty()) props.setProperty("clientSecret", clientSecret); |
| 92 | + |
| 93 | + log.info(" Attempting connection to: {}", jdbcUrl); |
| 94 | + log.info(" Using credentials: {}", userName.isEmpty() ? "Not provided" : "Provided"); |
| 95 | + |
| 96 | + try { |
| 97 | + Connection conn = DriverManager.getConnection(jdbcUrl, props); |
| 98 | + log.info(" Connection established successfully"); |
| 99 | + |
| 100 | + // Test basic query execution if connection succeeded |
| 101 | + testQueryExecution(conn); |
| 102 | + |
| 103 | + conn.close(); |
| 104 | + |
| 105 | + } catch (SQLException e) { |
| 106 | + String message = e.getMessage(); |
| 107 | + log.warn(" Connection failed: {}", message); |
| 108 | + |
| 109 | + // Check for the specific regression we're testing for |
| 110 | + if (message.toLowerCase().contains("address types of nameresolver 'unix'") |
| 111 | + || message.toLowerCase().contains("not supported by transport") |
| 112 | + || message.toLowerCase().contains("unix://")) { |
| 113 | + log.error(" CRITICAL: gRPC NameResolver regression detected!"); |
| 114 | + } |
| 115 | + } |
| 116 | + } |
| 117 | + |
| 118 | + /** |
| 119 | + * Test 3: Execute a simple query to verify end-to-end functionality |
| 120 | + */ |
| 121 | + private static void testQueryExecution(Connection conn) { |
| 122 | + log.info("Test 3: Query Execution"); |
| 123 | + |
| 124 | + try (Statement stmt = conn.createStatement()) { |
| 125 | + // Try a simple query first |
| 126 | + try (ResultSet rs = stmt.executeQuery("SELECT 1 as test_column")) { |
| 127 | + if (rs.next()) { |
| 128 | + log.info(" Simple query executed successfully: {}", rs.getInt("test_column")); |
| 129 | + } |
| 130 | + } catch (SQLException e) { |
| 131 | + log.error(" Simple query failed: {}", e.getMessage()); |
| 132 | + } |
| 133 | + |
| 134 | + // Try to query a real table if available |
| 135 | + try (ResultSet rs = stmt.executeQuery("SELECT * FROM shopify_order_details__dll LIMIT 1")) { |
| 136 | + if (rs.next()) { |
| 137 | + log.info(" Real table query executed successfully"); |
| 138 | + } else { |
| 139 | + log.info(" Real table query executed (no results)"); |
| 140 | + } |
| 141 | + } catch (SQLException e) { |
| 142 | + log.warn(" Real table query failed: {}", e.getMessage()); |
| 143 | + } |
| 144 | + } catch (SQLException e) { |
| 145 | + log.error(" Query execution failed: {}", e.getMessage()); |
| 146 | + } |
| 147 | + } |
| 148 | + |
| 149 | + /** |
| 150 | + * Test 4: Verify basic JDBC functionality works |
| 151 | + */ |
| 152 | + private static void testBasicFunctionality() { |
| 153 | + log.info("Test 4: Basic JDBC Functionality"); |
| 154 | + |
| 155 | + try { |
| 156 | + // Test driver metadata |
| 157 | + Driver driver = DriverManager.getDriver("jdbc:salesforce-datacloud:"); |
| 158 | + int majorVersion = driver.getMajorVersion(); |
| 159 | + int minorVersion = driver.getMinorVersion(); |
| 160 | + log.info(" Driver version: {}.{}", majorVersion, minorVersion); |
| 161 | + |
| 162 | + // Test driver properties |
| 163 | + Properties info = new Properties(); |
| 164 | + info.setProperty("user", "test"); |
| 165 | + info.setProperty("password", "test"); |
| 166 | + |
| 167 | + try { |
| 168 | + java.sql.DriverPropertyInfo[] propInfo = |
| 169 | + driver.getPropertyInfo("jdbc:salesforce-datacloud://test.com", info); |
| 170 | + log.info(" Driver property info available: {} properties", propInfo.length); |
| 171 | + } catch (Exception e) { |
| 172 | + log.warn(" Driver property info test failed: {}", e.getMessage()); |
| 173 | + } |
| 174 | + |
| 175 | + log.info(" Basic functionality tests completed"); |
| 176 | + } catch (Exception e) { |
| 177 | + log.error(" Basic functionality test failed: {}", e.getMessage()); |
| 178 | + } |
| 179 | + } |
| 180 | +} |
0 commit comments