-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IGNITE-23113 [ducktests] Add thin JDBC support and LOB ducktest
- Loading branch information
Showing
11 changed files
with
451 additions
and
4 deletions.
There are no files selected for viewing
168 changes: 168 additions & 0 deletions
168
.../java/org/apache/ignite/internal/ducktest/tests/jdbc_test/JdbcThinLobTestApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
/* | ||
* 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.ignite.internal.ducktest.tests.jdbc_test; | ||
|
||
import java.lang.management.ManagementFactory; | ||
import java.lang.management.MemoryPoolMXBean; | ||
import java.lang.management.MemoryUsage; | ||
import java.sql.Blob; | ||
import java.sql.Clob; | ||
import java.sql.Connection; | ||
import java.sql.PreparedStatement; | ||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.Random; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import org.apache.ignite.internal.IgniteInterruptedCheckedException; | ||
import org.apache.ignite.internal.ducktest.utils.IgniteAwareApplication; | ||
import org.apache.ignite.internal.util.typedef.internal.U; | ||
|
||
/** | ||
* Simple application that used in smoke tests | ||
*/ | ||
public class JdbcThinLobTestApplication extends IgniteAwareApplication { | ||
/** {@inheritDoc} */ | ||
@Override public void run(JsonNode jsonNode) throws ClassNotFoundException, SQLException { | ||
int blobSize = Optional.ofNullable(jsonNode.get("blob_size")).map(JsonNode::asInt).orElse(1); | ||
int clobSize = Optional.ofNullable(jsonNode.get("clob_size")).map(JsonNode::asInt).orElse(1); | ||
String action = Optional.ofNullable(jsonNode.get("action")).map(JsonNode::asText).orElse("insert"); | ||
|
||
int id = 1; | ||
|
||
try (Connection conn = thinJdbcDataSource.getConnection()) { | ||
conn.createStatement().execute("CREATE TABLE IF NOT EXISTS query(id INT, clob VARCHAR, blob BINARY, PRIMARY KEY(id)) " + | ||
"WITH \"cache_name=query,template=WITH_STATISTICS_ENABLED\""); | ||
|
||
if ("insert".equals(action)) { | ||
PreparedStatement insertStatement = conn.prepareStatement("INSERT INTO query(id, clob, blob) VALUES(?, ?, ?)"); | ||
|
||
insertStatement.setInt(1, id); | ||
|
||
Clob clob = getClob(conn, clobSize); | ||
insertStatement.setClob(2, clob); | ||
|
||
Blob blob = getBlob(conn, blobSize); | ||
insertStatement.setBlob(3, blob); | ||
|
||
insertStatement.execute(); | ||
} | ||
else if ("select".equals(action)) { | ||
PreparedStatement selectStatement = conn.prepareStatement("SELECT * FROM query WHERE id = ?"); | ||
|
||
selectStatement.setInt(1, id); | ||
|
||
ResultSet resultSet = selectStatement.executeQuery(); | ||
|
||
while (resultSet.next()) { | ||
Clob clob = resultSet.getClob("clob"); | ||
|
||
recordResult("CLOB_SIZE", clob.length()); | ||
recordResult("CLOB", clob.getSubString(1, Math.min((int)clob.length(), 64))); | ||
|
||
Blob blob = resultSet.getBlob("blob"); | ||
byte[] bytes = blob.getBytes(1, Math.min((int)blob.length(), 64)); | ||
|
||
recordResult("BLOB_SIZE", blob.length()); | ||
recordResult("BLOB", U.byteArray2String(bytes, "0x%02X", ",0x%02X")); | ||
} | ||
} | ||
|
||
markInitialized(); | ||
|
||
while (!terminated()) { | ||
try { | ||
U.sleep(100); // Keeping node/txs alive. | ||
} | ||
catch (IgniteInterruptedCheckedException ignored) { | ||
log.info("Waiting interrupted."); | ||
} | ||
} | ||
|
||
recordMemoryPeakUsage(); | ||
|
||
markFinished(); | ||
} | ||
} | ||
|
||
/** | ||
* @param conn Connection. | ||
* @param size CLOB size. | ||
* @return CLOB of specified size. | ||
*/ | ||
private Clob getClob(Connection conn, int size) throws SQLException { | ||
Clob clob = conn.createClob(); | ||
|
||
if (size > 0) { | ||
StringBuilder sb = new StringBuilder(size); | ||
|
||
for (int i = 0; i < size; i++) { | ||
sb.append("Ж"); | ||
} | ||
|
||
clob.setString(1, sb.toString()); | ||
} | ||
return clob; | ||
} | ||
|
||
/** | ||
* @param conn Connection. | ||
* @param size BLOB size. | ||
* @return BLOB with random data. | ||
*/ | ||
private Blob getBlob(Connection conn, int size) throws SQLException { | ||
Blob blob = conn.createBlob(); | ||
|
||
if (size > 0) { | ||
byte[] bytes = new byte[size]; | ||
|
||
new Random().nextBytes(bytes); | ||
|
||
blob.setBytes(1, bytes); | ||
} | ||
|
||
return blob; | ||
} | ||
|
||
/** | ||
* @return Memory usage. | ||
*/ | ||
private MemoryUsage getPeakMemoryUsage() { | ||
List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans(); | ||
|
||
return pools.stream().filter(pool -> pool.getName().contains("G1")) | ||
.map(MemoryPoolMXBean::getPeakUsage) | ||
.reduce((MemoryUsage a, MemoryUsage b) -> | ||
new MemoryUsage(a.getInit() + b.getInit(), a.getUsed() + b.getUsed(), | ||
a.getCommitted() + b.getCommitted(), | ||
Math.max(a.getMax() + b.getMax(), a.getCommitted() + b.getCommitted()))) | ||
.orElse(null); | ||
} | ||
|
||
/** | ||
*/ | ||
private void recordMemoryPeakUsage() { | ||
MemoryUsage peakMemoryUsage = getPeakMemoryUsage(); | ||
|
||
recordResult("PEAK_MEMORY_USED", peakMemoryUsage.getUsed()); | ||
recordResult("PEAK_MEMORY_COMMITTED", peakMemoryUsage.getCommitted()); | ||
recordResult("PEAK_MEMORY_MAX", peakMemoryUsage.getMax()); | ||
recordResult("PEAK_MEMORY_INIT", peakMemoryUsage.getInit()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,3 +29,4 @@ class IgniteServiceType(IntEnum): | |
NODE = 0 | ||
THIN_CLIENT = 1 | ||
NONE = 2 | ||
THIN_JDBC = 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
modules/ducktests/tests/ignitetest/services/utils/templates/thin_jdbc_config.xml.j2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{# | ||
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. | ||
#} | ||
|
||
<?xml version="1.0" encoding="UTF-8"?> | ||
<beans xmlns="http://www.springframework.org/schema/beans" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation=" | ||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd | ||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"> | ||
<bean class="org.apache.ignite.IgniteJdbcThinDataSource" id="thin.jdbc.cfg"> | ||
<property name="addresses"> | ||
<list> | ||
{% for address in config.addresses %} | ||
<value>{{ address }}</value> | ||
{% endfor %} | ||
</list> | ||
</property> | ||
|
||
{% if config.username %} | ||
<property name="username" value="{{ config.username }}"/> | ||
<property name="password" value="{{ config.password }}"/> | ||
{% endif %} | ||
|
||
{% if config.ssl_params %} | ||
<property name="sslMode" value="require"/> | ||
<property name="sslClientCertificateKeyStoreUrl" value="{{ config.ssl_params.key_store_path }}"/> | ||
<property name="sslClientCertificateKeyStorePassword" value="{{ config.ssl_params.key_store_password }}"/> | ||
<property name="sslTrustCertificateKeyStoreUrl" value="{{ config.ssl_params.trust_store_path }}"/> | ||
<property name="sslTrustCertificateKeyStorePassword" value="{{ config.ssl_params.trust_store_password }}"/> | ||
{% endif %} | ||
</bean> | ||
</beans> |
Oops, something went wrong.