Copilot commented on code in PR #105: URL: https://github.com/apache/pulsar-connectors/pull/105#discussion_r3562832198
########## jdbc/openmldb/src/test/java/org/apache/pulsar/io/jdbc/OpenMLDBJdbcSinkIntegrationTest.java: ########## @@ -0,0 +1,205 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ +package org.apache.pulsar.io.jdbc; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.Statement; +import java.time.Duration; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.TimeUnit; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.pulsar.client.api.Message; +import org.apache.pulsar.client.api.schema.GenericObject; +import org.apache.pulsar.client.api.schema.GenericRecord; +import org.apache.pulsar.client.api.schema.SchemaDefinition; +import org.apache.pulsar.client.impl.MessageImpl; +import org.apache.pulsar.client.impl.schema.AutoConsumeSchema; +import org.apache.pulsar.client.impl.schema.AvroSchema; +import org.apache.pulsar.client.impl.schema.generic.GenericAvroSchema; +import org.apache.pulsar.functions.api.Record; +import org.apache.pulsar.functions.source.PulsarRecord; +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.containers.wait.strategy.Wait; +import org.testcontainers.utility.DockerImageName; +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Integration test for the OpenMLDB JDBC sink, exercised against a real OpenMLDB cluster via + * Testcontainers, mirroring {@code ClickHouseJdbcSinkIntegrationTest}: create the table, open the + * sink, write an Avro {@code GenericRecord} through it, read the row back and assert. + * + * <p><b>Why this test is Linux-x86-64-only.</b> The OpenMLDB JDBC driver is a thin JNI wrapper over + * a native SDK ({@code libsql_jsdk.so}) shipped in {@code openmldb-native}, which publishes no + * macOS/arm64 binary — the driver cannot initialise on Apple Silicon, so this test only runs on a + * Linux x86-64 host (and in CI, which is Linux x86-64). See issue #46. + * + * <p><b>Why cluster mode + host networking.</b> The OpenMLDB JDBC driver mandates {@code zk} and + * {@code zkPath} params ({@code jdbc:openmldb:///db?zk=host:port&zkPath=/path}); the host after + * {@code //} is ignored. It reads tablet/nameserver endpoints from ZooKeeper and dials them + * directly, so OpenMLDB must run in <b>cluster mode</b> (standalone has no zk) and its advertised + * endpoints must be reachable from the test JVM. Host networking (Linux only) is the simplest way + * to guarantee that — the container binds the OpenMLDB ports on localhost and zk advertises + * host-reachable addresses. + * + * <p>The image tag matches the pinned OpenMLDB client version; the sink-driving logic mirrors the + * ClickHouse test, minus key/nonKey config and label-based ResultSet getters, which the OpenMLDB + * driver does not support. + */ +@Slf4j +public class OpenMLDBJdbcSinkIntegrationTest { + + /** Match the module's pinned client (libs.openmldb == 0.9.2). */ + private static final DockerImageName OPENMLDB_IMAGE = DockerImageName.parse("4pdosc/openmldb:0.9.2"); + + /** ZooKeeper coordinates the JDBC driver discovers cluster endpoints through. */ + private static final String ZK_ENDPOINT = "127.0.0.1:2181"; + private static final String ZK_PATH = "/openmldb"; + + private static final String DATABASE = "pulsar_test"; + private static final String TABLE_NAME = "pulsar_messages"; + + private GenericContainer<?> openmldb; + private BaseJdbcAutoSchemaSink jdbcSink; + + /** A simple record class matching the {@link #TABLE_NAME} columns. */ + @Data + @NoArgsConstructor + @AllArgsConstructor + public static class Foo { + private String field1; + private String field2; + private int field3; + } + + /** JDBC URL for the OpenMLDB driver — zk-based; the host after {@code //} is ignored. */ + private static String jdbcUrl(String database) { + return "jdbc:openmldb:///" + database + "?zk=" + ZK_ENDPOINT + "&zkPath=" + ZK_PATH; + } + + @BeforeClass(alwaysRun = true) + public void setUp() throws Exception { + // Host networking (Linux only): binds OpenMLDB's ports on localhost so the endpoints zk + // advertises are reachable from this JVM. The image's init.sh deploys and starts the + // cluster (zk on localhost:2181, zkPath /openmldb) and prints "OpenMLDB start success". + openmldb = new GenericContainer<>(OPENMLDB_IMAGE) + .withNetworkMode("host") + .withCommand("bash", "-c", "/work/init.sh && tail -f /dev/null") + .waitingFor(Wait.forLogMessage(".*OpenMLDB start success.*", 1)) + .withStartupTimeout(Duration.ofMinutes(4)); + openmldb.start(); Review Comment: This integration test is documented as Linux x86-64 only (native OpenMLDB SDK + host-network Docker), but it currently runs unconditionally. On macOS/Windows or Linux aarch64 this will fail during driver/container startup and break `:jdbc:pulsar-io-jdbc-openmldb:test` for non-Linux contributors. Add an explicit TestNG skip in setUp (and optionally skip when localhost:2181 is already in use, since host-network mode needs to bind that port). -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
