Skip to content

Commit

Permalink
add test for response side
Browse files Browse the repository at this point in the history
  • Loading branch information
t-horikawa committed Sep 2, 2024
1 parent 0885d33 commit d8b92a8
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import com.tsurugidb.tsubakuro.sql.Parameters;

public class Insert {
public static void doInsert(String url) throws IOException, ServerException, InterruptedException {
public static void doInsert(String url, boolean testResponse) throws IOException, ServerException, InterruptedException {
try (Session session = SessionBuilder.connect(url).create();
SqlClient sqlClient = SqlClient.attach(session);
PreparedStatement preparedStatement = sqlClient.prepare("INSERT INTO foo (bar1, bar2, bar3) VALUES (:int_for_bar1, :double_for_bar2, :char_for_bar3)",
Expand All @@ -22,15 +22,25 @@ public static void doInsert(String url) throws IOException, ServerException, Int
Transaction transaction = sqlClient.createTransaction().get();) {

// insert first data into foo table
transaction.executeStatement(preparedStatement,
var f1 = transaction.executeStatement(preparedStatement,
Parameters.of("int_for_bar1", (long) 1234),
Parameters.of("double_for_bar2", (double) 56.789),
Parameters.of("char_for_bar3", "text for first data")).get();
Parameters.of("char_for_bar3", "text for first data"));
if (testResponse) {
f1.close(); // test of FutureResponse close without performing get()
} else {
f1.get(); // normal operation;
}
// insert second data into foo table
transaction.executeStatement(preparedStatement,
var f2 = transaction.executeStatement(preparedStatement,
Parameters.of("int_for_bar1", (long) 5678),
Parameters.of("double_for_bar2", (double) 123.45),
Parameters.of("char_for_bar3", "text for second data")).get();
Parameters.of("char_for_bar3", "text for second data"));
if (testResponse) {
f2.close(); // test of FutureResponse close without performing get()
} else {
f2.get(); // normal operation;
}
transaction.commit().get();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,35 @@
package com.tsurugidb.tsubakuro.examples.resultsetClose;

// for command options
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;

import java.io.IOException;
import java.util.ArrayList;

import com.tsurugidb.tsubakuro.exception.ServerException;

public final class Main {
private static String url = System.getProperty("tsurugi.dbname");
private static boolean testResponse = false;

public static void main(String[] args) {
// コマンドラインオプションの設定
Options options = new Options();

options.addOption(Option.builder("z").argName("prepare").desc("do simple test.").build());

CommandLineParser parser = new DefaultParser();
CommandLine cmd = null;

if (cmd.hasOption("i")) {
testResponse = true;
}

try {
CreateTable.doCreateTable(url);
} catch (IOException | ServerException | InterruptedException e) {
Expand All @@ -17,7 +38,7 @@ public static void main(String[] args) {
return;
}
try {
Insert.doInsert(url);
Insert.doInsert(url, testResponse);
} catch (IOException | ServerException | InterruptedException e) {
System.out.println(e);
e.printStackTrace();
Expand Down

0 comments on commit d8b92a8

Please sign in to comment.