Skip to content

Commit

Permalink
Adding new test for insert big chuncks
Browse files Browse the repository at this point in the history
  • Loading branch information
mzitnik committed Dec 21, 2023
1 parent 8514c51 commit 8a7d90f
Showing 1 changed file with 37 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

public class JdbcIssuesTest extends JdbcIntegrationTest {
@Test(groups = "integration")
public void testDecompress() throws SQLException {
public void test01Decompress() throws SQLException {
String httpEndpoint = "http://" + getServerAddress(ClickHouseProtocol.HTTP) + "/";
String TABLE_NAME = "decompress_issue";
String TABLE_NAME = "decompress_issue_01";
Properties prop = new Properties();
prop.setProperty("decompress", "true");
prop.setProperty("decompress_algorithm", "lz4");
Expand Down Expand Up @@ -52,4 +52,39 @@ public void testDecompress() throws SQLException {
}
}


@Test
public void test02Decompress() throws SQLException {
String httpEndpoint = "http://" + getServerAddress(ClickHouseProtocol.HTTP) + "/";
String TABLE_NAME = "decompress_issue_02";
Properties prop = new Properties();
prop.setProperty("decompress", "true");
prop.setProperty("decompress_algorithm", "lz4");
String url = String.format("jdbc:ch:%s", httpEndpoint);
ClickHouseDataSource dataSource = new ClickHouseDataSource(url, prop);
String columnNames = "event_id";
String columnValues = "('event_id String')";
String sql = String.format("INSERT INTO %s (%s) SELECT %s FROM input %s", TABLE_NAME, columnNames, columnNames, columnValues);

Connection conn = dataSource.getConnection("default", "");
Statement st = conn.createStatement();
st.execute(String.format("CREATE TABLE %s (`event_id` String) ENGINE = Log", TABLE_NAME));

int count = 1;
boolean failed = false;

String content = StringUtils.repeat("*", count);
try (PreparedStatement ps = conn.prepareStatement(sql)) {
while (count <= 100000) {
ps.setString(1, content);
ps.addBatch();
count *= 2;
}
ps.executeBatch();
} catch (SQLException sqlException) {
sqlException.printStackTrace();
failed = true;
}
Assert.assertFalse(failed, String.format("Failed when content size %d", count));
}
}

0 comments on commit 8a7d90f

Please sign in to comment.