|
5 | 5 | import com.clickhouse.client.ClickHouseProtocol; |
6 | 6 | import com.clickhouse.client.ClickHouseServerForTest; |
7 | 7 | import com.clickhouse.client.api.Client; |
| 8 | +import com.clickhouse.client.api.ClientConfigProperties; |
8 | 9 | import com.clickhouse.client.api.ClientException; |
9 | 10 | import com.clickhouse.client.api.DataTypeUtils; |
10 | 11 | import com.clickhouse.client.api.command.CommandResponse; |
@@ -269,6 +270,33 @@ public void insertRawData() throws Exception { |
269 | 270 | assertEquals(records.size(), 1000); |
270 | 271 | } |
271 | 272 |
|
| 273 | + @Test(groups = { "integration" }, enabled = true) |
| 274 | + public void insertRawDataAsync() throws Exception { |
| 275 | + final String tableName = "raw_data_table_async"; |
| 276 | + final String createSQL = "CREATE TABLE " + tableName + |
| 277 | + " (Id UInt32, event_ts Timestamp, name String, p1 Int64, p2 String) ENGINE = MergeTree() ORDER BY ()"; |
| 278 | + |
| 279 | + initTable(tableName, createSQL); |
| 280 | + |
| 281 | + InsertSettings localSettings = new InsertSettings(settings.getAllSettings()); |
| 282 | + localSettings.setOption(ClientConfigProperties.ASYNC_OPERATIONS.getKey(), true); |
| 283 | + ByteArrayOutputStream data = new ByteArrayOutputStream(); |
| 284 | + PrintWriter writer = new PrintWriter(data); |
| 285 | + for (int i = 0; i < 1000; i++) { |
| 286 | + writer.printf("%d\t%s\t%s\t%d\t%s\n", i, "2021-01-01 00:00:00", "name" + i, i, "p2"); |
| 287 | + } |
| 288 | + writer.flush(); |
| 289 | + client.insert(tableName, new ByteArrayInputStream(data.toByteArray()), |
| 290 | + ClickHouseFormat.TSV, localSettings).whenComplete((response, throwable) -> { |
| 291 | + OperationMetrics metrics = response.getMetrics(); |
| 292 | + assertEquals((int)response.getWrittenRows(), 1000 ); |
| 293 | + |
| 294 | + List<GenericRecord> records = client.queryAll("SELECT * FROM " + tableName); |
| 295 | + assertEquals(records.size(), 1000); |
| 296 | + }) |
| 297 | + .join(); // wait operation complete. only for tests |
| 298 | + } |
| 299 | + |
272 | 300 | @Test(groups = { "integration" }, dataProvider = "insertRawDataSimpleDataProvider", dataProviderClass = InsertTests.class) |
273 | 301 | public void insertRawDataSimple(String tableName) throws Exception { |
274 | 302 | // final String tableName = "raw_data_table"; |
@@ -639,10 +667,9 @@ public void testCollectionInsert() throws Exception { |
639 | 667 | } |
640 | 668 | } |
641 | 669 |
|
642 | | - |
643 | | - static { |
644 | | - System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "DEBUG"); |
645 | | - } |
| 670 | +// static { |
| 671 | +// System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "DEBUG"); |
| 672 | +// } |
646 | 673 |
|
647 | 674 | @Test(groups = {"integration"}, dataProvider = "testAppCompressionDataProvider", dataProviderClass = InsertTests.class) |
648 | 675 | public void testAppCompression(String algo) throws Exception { |
|
0 commit comments