Skip to content

Commit

Permalink
Use azure edge container on ARM architecture for testing (#1139)
Browse files Browse the repository at this point in the history
GitOrigin-RevId: 7a76c21d86053952e1f5648d25f259a914a939b0
  • Loading branch information
orcunc authored and actions-user committed Mar 26, 2024
1 parent 9f6645d commit 8fdbedf
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ public class MSSQLSchemaJdbcSqlConnectorTest extends SchemaJdbcConnectorTest {

@BeforeClass
public static void beforeClass() {
//There is no arm64 image for mssql server
assumeNoArm64Architecture();
initialize(new MSSQLDatabaseProvider());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ public class MSSQLSinkIntoJdbcSqlConnectorTest extends SinkJdbcSqlConnectorTest

@BeforeClass
public static void beforeClass() {
//There is no arm64 image for mssql server
assumeNoArm64Architecture();
initialize(new MSSQLDatabaseProvider());
}
}
4 changes: 4 additions & 0 deletions hazelcast/src/test/java/com/hazelcast/jet/TestedVersions.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,8 @@ public final class TestedVersions {
public static final String DEFAULT_ORACLE_IMAGE_NAME = "gvenzl/oracle-xe:21-slim-faststart";
public static final String ORACLE_PROPERTY_NAME = "test.oracle.version";
public static final String TEST_ORACLE_VERSION = System.getProperty(ORACLE_PROPERTY_NAME, DEFAULT_ORACLE_IMAGE_NAME);

public static final String TEST_AZURE_SQL_EDGE_VERSION = System.getProperty("test.azuresqledge.version", "1.0.7");

public static final String TEST_MSSQLSERVER_VERSION = System.getProperty("test.mssqlserver.version", "2022-latest");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright (c) 2008-2024, Hazelcast, Inc. All Rights Reserved.
*
* 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.
*/

package com.hazelcast.test.jdbc;

import org.testcontainers.containers.JdbcDatabaseContainerProvider;
import org.testcontainers.containers.MSSQLServerContainer;
import org.testcontainers.utility.DockerImageName;

import static com.hazelcast.jet.TestedVersions.TEST_AZURE_SQL_EDGE_VERSION;

/**
* Uses a {@link MSSQLServerContainer} with a `mcr.microsoft.com/azure-sql-edge` image in place of
* the standard ` mcr.microsoft.com/mssql/server` image
*/
class AzureSQLEdgeContainerProvider extends JdbcDatabaseContainerProvider {

private static final String NAME = "azuresqledge";

@Override
public boolean supports(String databaseType) {
return databaseType.equals(NAME);
}

@Override
public MSSQLServerContainer<?> newInstance() {
return newInstance(TEST_AZURE_SQL_EDGE_VERSION);
}

@Override
public MSSQLServerContainer<?> newInstance(String tag) {
var taggedImageName = DockerImageName.parse("mcr.microsoft.com/azure-sql-edge")
.withTag(tag)
.asCompatibleSubstituteFor("mcr.microsoft.com/mssql/server");
return new MSSQLServerContainer<>(taggedImageName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,48 @@

package com.hazelcast.test.jdbc;

import com.hazelcast.internal.tpcengine.util.OS;
import com.microsoft.sqlserver.jdbc.SQLServerDataSource;
import com.microsoft.sqlserver.jdbc.SQLServerXADataSource;
import org.testcontainers.containers.MSSQLServerContainer;

import javax.annotation.Nonnull;
import javax.sql.DataSource;

import static com.hazelcast.test.HazelcastTestSupport.assumeNoArm64Architecture;
import static com.hazelcast.jet.TestedVersions.TEST_MSSQLSERVER_VERSION;

public class MSSQLDatabaseProvider extends JdbcDatabaseProvider<MSSQLServerContainer<?>> {

public static final String TEST_MSSQLSERVER_VERSION = System.getProperty("test.mssqlserver.version", "2022-latest");

MSSQLServerContainer<?> createContainer(String dbName) {
assumeNoArm64Architecture();
// withDatabaseName() throws UnsupportedOperationException
MSSQLServerContainer<?> mssqlServerContainer = new MSSQLServerContainer<>("mcr.microsoft.com/mssql/server:" + TEST_MSSQLSERVER_VERSION);
MSSQLServerContainer<?> mssqlServerContainer;
if (isArmArchitecture()) {
mssqlServerContainer = createAzureSQLEdgeContainer();
} else {
mssqlServerContainer = createMSSQLContainer();
}
mssqlServerContainer.acceptLicense()
// See https://learn.microsoft.com/en-us/sql/connect/jdbc/using-basic-data-types?view=sql-server-ver16
// "To use java.sql.Time with the time SQL Server type, you must set the sendTimeAsDatetime
// connection property to false."
// See https://learn.microsoft.com/en-us/sql/connect/jdbc/using-basic-data-types?view=sql-server-ver16
// "To use java.sql.Time with the time SQL Server type, you must set the sendTimeAsDatetime
// connection property to false."
.withUrlParam("sendTimeAsDateTime", "false")
.withUrlParam("user", mssqlServerContainer.getUsername())
.withUrlParam("password", mssqlServerContainer.getPassword());
return mssqlServerContainer;
}

private boolean isArmArchitecture() {
return "aarch64".equals(OS.osArch());
}

private MSSQLServerContainer<?> createAzureSQLEdgeContainer() {
return new AzureSQLEdgeContainerProvider().newInstance();
}

private MSSQLServerContainer<?> createMSSQLContainer() {
// withDatabaseName() throws UnsupportedOperationException
return new MSSQLServerContainer<>("mcr.microsoft.com/mssql/server:" + TEST_MSSQLSERVER_VERSION);
}

@Override
public DataSource createDataSource(boolean xa) {
if (xa) {
Expand Down Expand Up @@ -82,8 +97,8 @@ public String getDatabaseName() {
@Override
public String noAuthJdbcUrl() {
return container.getJdbcUrl()
.replaceAll(";user=" + user(), "")
.replaceAll(";password=" + password(), "");
.replaceAll(";user=" + user(), "")
.replaceAll(";password=" + password(), "");
}

@Override
Expand Down

0 comments on commit 8fdbedf

Please sign in to comment.