Skip to content

Commit

Permalink
Upgrade to Java 11 [HZ-3617] (#289)
Browse files Browse the repository at this point in the history
  • Loading branch information
orcunc authored Dec 18, 2023
1 parent da01233 commit f91d2b7
Show file tree
Hide file tree
Showing 17 changed files with 92 additions and 105 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
java: [ '8' ]
java: [ '11' ]
architecture: [ 'x64' ]
distribution: [ 'adopt' ]
name: Build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
- name: Setup JDK
uses: actions/setup-java@v3
with:
java-version: 8
java-version: 11
distribution: 'adopt'
server-id: deploy-repository
server-username: MAVEN_USERNAME
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
java: [ '8' ]
java: [ '11' ]
architecture: [ 'x64' ]
distribution: [ 'adopt' ]
name: Build SNAPSHOT version with JDK ${{ matrix.java }}
Expand Down
17 changes: 1 addition & 16 deletions hazelcast-jdbc-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,7 @@
<!--Test dependencies-->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-commons</artifactId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private static void k8sConfigMapping(Map<String, BiConsumer<ClientConfig, String
}

private static void sslConfigMapping(Map<String, BiConsumer<ClientConfig, String>> map) {
map.put("sslEnabled", (c, p) -> sslConfig(c, (ssl) -> ssl.setEnabled(p.equalsIgnoreCase("true"))));
map.put("sslEnabled", (c, p) -> sslConfig(c, ssl -> ssl.setEnabled(p.equalsIgnoreCase("true"))));
map.put("trustStore", (c, p) -> sslConfig(c, "trustStore", p));
map.put("trustStorePassword", (c, p) -> sslConfig(c, "trustStorePassword", p));
map.put("keyStore", (c, p) -> sslConfig(c, "keyStore", p));
Expand All @@ -74,7 +74,7 @@ private static void sslConfigMapping(Map<String, BiConsumer<ClientConfig, String
map.put("trustCertCollectionFile", (c, p) -> sslConfig(c, "trustCertCollectionFile", p));
map.put("keyFile", (c, p) -> sslConfig(c, "keyFile", p));
map.put("keyCertChainFile", (c, p) -> sslConfig(c, "keyCertChainFile", p));
map.put("factoryClassName", (c, p) -> sslConfig(c, (ssl) -> ssl.setFactoryClassName(p)));
map.put("factoryClassName", (c, p) -> sslConfig(c, ssl -> ssl.setFactoryClassName(p)));
}

private static void awsConfigMapping(Map<String, BiConsumer<ClientConfig, String>> map) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package com.hazelcast.jdbc;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
Expand Down Expand Up @@ -89,10 +88,6 @@ static boolean acceptsUrl(String url) {
}

private static String decodeUrl(String raw) {
try {
return URLDecoder.decode(raw, StandardCharsets.UTF_8.name());
} catch (UnsupportedEncodingException impossible) {
throw new RuntimeException(impossible);
}
return URLDecoder.decode(raw, StandardCharsets.UTF_8);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ public static void afterClass() {
}

@Test
public void shouldHazelcastJdbcConnection() {
void shouldHazelcastJdbcConnection() {
assertThat(connection).isNotNull();
}

@Test
public void shouldExecuteSimpleQuery() throws SQLException {
void shouldExecuteSimpleQuery() throws SQLException {
Statement statement = connection.createStatement();
assertThat(statement).isNotNull();
ResultSet resultSet = statement.executeQuery("SELECT * FROM person");
Expand All @@ -84,7 +84,7 @@ public void shouldExecuteSimpleQuery() throws SQLException {
}

@Test
public void shouldUnwrapResultSet() throws SQLException {
void shouldUnwrapResultSet() throws SQLException {
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery("SELECT * FROM person WHERE name='Jack1'");
resultSet.next();
Expand All @@ -94,23 +94,23 @@ public void shouldUnwrapResultSet() throws SQLException {
}

@Test
public void shouldNotHaveTimeoutIfNotSetExplicitly() throws SQLException {
void shouldNotHaveTimeoutIfNotSetExplicitly() throws SQLException {
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery("SELECT * FROM person WHERE name='Jack1'");
resultSet.next();
assertThat(resultSet.getString("name")).isNotNull();
}

@Test
public void shouldReturnResultSet() throws SQLException {
void shouldReturnResultSet() throws SQLException {
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery("SELECT * FROM person WHERE name='Jack1'");

assertThat(resultSet).isSameAs(statement.getResultSet());
}

@Test
public void shouldExecuteSimplePreparedStatement() throws SQLException {
void shouldExecuteSimplePreparedStatement() throws SQLException {
PreparedStatement statement = connection.prepareStatement("SELECT * FROM person WHERE name=? AND age=?");
statement.setString(1, "Jack1");
statement.setInt(2, 1);
Expand All @@ -121,7 +121,7 @@ public void shouldExecuteSimplePreparedStatement() throws SQLException {
}

@Test
public void shouldCloseStatement() throws SQLException {
void shouldCloseStatement() throws SQLException {
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery("SELECT * FROM person WHERE name='Jack1'");
resultSet.next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@

class DriverTest {

private static final Condition<Throwable> THROWN_IN_DRIVER_CONNECT = new Condition<Throwable>(t -> {
private static final Condition<Throwable> THROWN_IN_DRIVER_CONNECT = new Condition<>(t -> {
StackTraceElement[] stackTrace = t.getStackTrace();
return stackTrace[0].getClassName().equals(Driver.class.getName())
&& stackTrace[0].getMethodName().equals("connect");
&& stackTrace[0].getMethodName().equals("connect");
}, "thrown at Driver.connect()");

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,8 @@ void shouldParseSmartRouting() {
.isEqualTo(expectedClientConfigFalse);
assertThatExceptionOfType(RuntimeException.class)
.as("clientConfigOther")
.isThrownBy(() -> {
configFactory.clientConfig(
new JdbcUrl(baseUrl + "?smartRouting=other", null));
});
.isThrownBy(() -> configFactory.clientConfig(
new JdbcUrl(baseUrl + "?smartRouting=other", null)));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.hazelcast.config.Config;
import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.sql.SqlResult;
import com.hazelcast.sql.SqlService;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
Expand All @@ -35,7 +36,7 @@
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;

public class JdbcConnectionIntegrationTest {
class JdbcConnectionIntegrationTest {
private HazelcastInstance member;
private HazelcastSqlClient client;

Expand All @@ -55,7 +56,7 @@ public void tearDown() {
}

@Test
public void test_connectionClose() throws SQLException {
void test_connectionClose() throws SQLException {
Connection connection = new JdbcConnection(client);
connection.close();
assertThatThrownBy(connection::createStatement)
Expand All @@ -65,11 +66,12 @@ public void test_connectionClose() throws SQLException {
}

@Test
void when_prepareCall_then_notSupported() {
Connection connection = new JdbcConnection(client);
assertThatThrownBy(() -> connection.prepareCall("{call getPerson(?, ?)}"))
.isInstanceOf(SQLFeatureNotSupportedException.class)
.hasMessage("CallableStatement not supported");
void when_prepareCall_then_notSupported() throws SQLException {
try (Connection connection = new JdbcConnection(client)) {
assertThatThrownBy(() -> connection.prepareCall("{call getPerson(?, ?)}"))
.isInstanceOf(SQLFeatureNotSupportedException.class)
.hasMessage("CallableStatement not supported");
}
}

@Test
Expand All @@ -88,17 +90,19 @@ void when_resultSetClosed_then_statementClosed() throws SQLException {
void when_schemaChangedOnConnection_then_shouldNotAffectExistingStatements() throws SQLException {
// test for https://github.com/hazelcast/hazelcast-jdbc/issues/58
SqlService sql = member.getSql();
sql.execute("CREATE OR REPLACE MAPPING mappings(__key INT, this INT) TYPE IMap "
+ "OPTIONS('keyFormat'='int', 'valueFormat'='int')");
SqlResult sqlResult = sql.execute("CREATE OR REPLACE MAPPING mappings(__key INT, this INT) TYPE IMap "
+ "OPTIONS('keyFormat'='int', 'valueFormat'='int')");
sqlResult.close();

Connection connection = new JdbcConnection(client);
Statement statement = connection.createStatement();
connection.setSchema("information_schema");
ResultSet resultSet = statement.executeQuery("SELECT * FROM mappings");
Assertions.assertEquals("__key", resultSet.getMetaData().getColumnName(1));
try (Connection connection = new JdbcConnection(client)) {
Statement statement = connection.createStatement();
connection.setSchema("information_schema");
ResultSet resultSet = statement.executeQuery("SELECT * FROM mappings");
Assertions.assertEquals("__key", resultSet.getMetaData().getColumnName(1));

statement = connection.createStatement();
resultSet = statement.executeQuery("SELECT * FROM mappings");
Assertions.assertEquals("table_catalog", resultSet.getMetaData().getColumnName(1));
statement = connection.createStatement();
resultSet = statement.executeQuery("SELECT * FROM mappings");
Assertions.assertEquals("table_catalog", resultSet.getMetaData().getColumnName(1));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@
import static org.junit.jupiter.api.Assumptions.assumeFalse;

@ExtendWith(MockitoExtension.class)
public class JdbcConnectionTest {
class JdbcConnectionTest {

@Mock
private HazelcastSqlClient client;
@InjectMocks
private JdbcConnection connection;

@Test
public void shouldNotSupportAutogeneratedKeys() {
void shouldNotSupportAutogeneratedKeys() {
connection = new JdbcConnection(client);
assertThatThrownBy(() -> connection.prepareStatement("SELECT * FROM person", new int[]{1, 2, 3}))
.isInstanceOf(SQLFeatureNotSupportedException.class)
Expand Down Expand Up @@ -84,7 +84,7 @@ void clientInfoTest() throws SQLException {

String expectedMessage = "Client info is not supported.";

// We called setClientInfo twice and we expect only two warnings in the chain.
// We called setClientInfo twice, and we expect only two warnings in the chain.
assertThat(connection.getWarnings().getMessage())
.isEqualTo(expectedMessage);
assertThat(connection.getWarnings().getNextWarning().getMessage())
Expand Down
Loading

0 comments on commit f91d2b7

Please sign in to comment.