Skip to content

Commit

Permalink
revise session test programs
Browse files Browse the repository at this point in the history
  • Loading branch information
t-horikawa committed May 30, 2024
1 parent adb16c9 commit 3e91184
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;

import com.tsurugidb.tsubakuro.util.FutureResponse;
import com.tsurugidb.tsubakuro.common.Session;
import com.tsurugidb.tsubakuro.common.SessionBuilder;
import com.tsurugidb.tsubakuro.common.ShutdownType;
import com.tsurugidb.tsubakuro.channel.common.connection.UsernamePasswordCredential;
import com.tsurugidb.tsubakuro.exception.ServerException;
import com.tsurugidb.tsubakuro.sql.SqlClient;
import com.tsurugidb.tsubakuro.sql.ResultSet;

// Prior to executing this program, the following create table and insert to table must be executed.
// DROP TABLE IF EXISTS TBL01;
Expand All @@ -44,13 +46,14 @@ private Main(String[] args) {
private static String url = System.getProperty("tsurugi.dbname");

private static boolean doGet = false;
private static boolean threadSleep = false;
private static boolean execSql = false;
private static int sleepTime = 2000;

public static void main(String[] args) {
// コマンドラインオプションの設定
Options options = new Options();
options.addOption(Option.builder("g").argName("doGet").desc("do get() operation").build());
options.addOption(Option.builder("s").argName("sleep").desc("sleep for a while").build());
options.addOption(Option.builder("s").argName("execSql").desc("execute SQL").build());
options.addOption(Option.builder("h").argName("huge").desc("huge result set").build());
CommandLineParser parser = new DefaultParser();

Expand All @@ -63,8 +66,8 @@ public static void main(String[] args) {
System.err.println("do get() operation");
}
if (cmd.hasOption("s")) {
threadSleep = true;
System.err.println("sleep for a while");
execSql = true;
System.err.println("execute SQL");
}
if (cmd.hasOption("h")) {
sql = "SELECT * FROM TBL02,TBL02,TBL01";
Expand All @@ -82,24 +85,25 @@ public static void main(String[] args) {
.create(10, TimeUnit.SECONDS);
SqlClient sqlClient = SqlClient.attach(session);
var transaction = sqlClient.createTransaction().get(timeout, TimeUnit.MILLISECONDS);
var futureResultSet = transaction.executeQuery(sql);
if (doGet) {
futureResultSet.get();
}
if (threadSleep) {
Thread.sleep(10000);
FutureResponse<ResultSet> futureResultSet = null;
if (execSql) {
futureResultSet = transaction.executeQuery(sql);
if (doGet) {
futureResultSet.get();
}
}
Thread.sleep(sleepTime);

System.out.println("going to do session.close");
session.close();

if (!doGet) {
if (!doGet && futureResultSet != null) {
futureResultSet.get();
}
} catch (IOException | ServerException | InterruptedException | TimeoutException e) {
System.err.println(e);
} finally {
System.out.println("---- program execution finished in " + (System.currentTimeMillis() - start) + " milli seconds ----");
System.out.println("---- program execution finished in " + (System.currentTimeMillis() - start - sleepTime) + " milli seconds ----");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public static void shutdown(Session session) throws IOException, ServerException
} else {
while (session.isAlive()) {
System.out.println("session is still alive");
Thread.sleep(2000);
}
}
}
Expand Down

0 comments on commit 3e91184

Please sign in to comment.