Skip to content

Commit

Permalink
feat: Added setConnectTimeout()
Browse files Browse the repository at this point in the history
  • Loading branch information
hishidama committed Aug 14, 2024
1 parent d38efd6 commit 36552bb
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import com.tsurugidb.iceaxe.util.IceaxeConvertUtil;
import com.tsurugidb.iceaxe.util.IceaxeInternal;
import com.tsurugidb.iceaxe.util.IceaxeIoUtil;
import com.tsurugidb.iceaxe.util.IceaxeTimeout;
import com.tsurugidb.iceaxe.util.InterruptedRuntimeException;
import com.tsurugidb.iceaxe.util.TgTimeValue;
import com.tsurugidb.iceaxe.util.function.TsurugiTransactionConsumer;
Expand All @@ -53,8 +52,6 @@ public class TsurugiQueryResult<R> extends TsurugiSqlResult implements Iterable<
private final IceaxeConvertUtil convertUtil;
private FutureResponse<ResultSet> lowResultSetFuture;
private ResultSet lowResultSet;
private final IceaxeTimeout connectTimeout;
private final IceaxeTimeout closeTimeout;
private List<TsurugiQueryResultEventListener<R>> eventListenerList = null;
private int readCount = 0;
private TsurugiResultRecord record;
Expand All @@ -77,13 +74,9 @@ public class TsurugiQueryResult<R> extends TsurugiSqlResult implements Iterable<
*/
@IceaxeInternal
public TsurugiQueryResult(int sqlExecuteId, TsurugiTransaction transaction, TsurugiSql ps, Object parameter, TgResultMapping<R> resultMapping, IceaxeConvertUtil convertUtil) {
super(sqlExecuteId, transaction, ps, parameter);
super(sqlExecuteId, transaction, ps, parameter, TgTimeoutKey.RS_CONNECT, TgTimeoutKey.RS_CLOSE);
this.resultMapping = resultMapping;
this.convertUtil = convertUtil;

var sessionOption = transaction.getSessionOption();
this.connectTimeout = new IceaxeTimeout(sessionOption, TgTimeoutKey.RS_CONNECT);
this.closeTimeout = new IceaxeTimeout(sessionOption, TgTimeoutKey.RS_CLOSE);
}

/**
Expand Down Expand Up @@ -126,37 +119,45 @@ public void initialize(FutureResponse<ResultSet> lowResultSetFuture) throws IOEx
*
* @param time time value
* @param unit time unit
* @see #setConnectTimeout(long, TimeUnit)
*/
@Deprecated(since = "X.X.X", forRemoval = true)
public void setRsConnectTimeout(long time, TimeUnit unit) {
setRsConnectTimeout(TgTimeValue.of(time, unit));
setConnectTimeout(time, unit);
}

/**
* set ResetSet-timeout.
*
* @param timeout time
* @see #setConnectTimeout(TgTimeValue)
*/
@Deprecated(since = "X.X.X", forRemoval = true)
public void setRsConnectTimeout(TgTimeValue timeout) {
connectTimeout.set(timeout);
setConnectTimeout(timeout);
}

/**
* set ResetSet-close-timeout.
*
* @param time timeout time
* @param unit timeout unit
* @see #setCloseTimeout(long, TimeUnit)
*/
@Deprecated(since = "X.X.X", forRemoval = true)
public void setRsCloseTimeout(long time, TimeUnit unit) {
setRsCloseTimeout(TgTimeValue.of(time, unit));
setCloseTimeout(time, unit);
}

/**
* set ResetSet-close-timeout.
*
* @param timeout time
* @see #setCloseTimeout(TgTimeValue)
*/
@Deprecated(since = "X.X.X", forRemoval = true)
public void setRsCloseTimeout(TgTimeValue timeout) {
closeTimeout.set(timeout);
setCloseTimeout(timeout);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package com.tsurugidb.iceaxe.sql.result;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

import com.tsurugidb.iceaxe.session.TgSessionOption.TgTimeoutKey;
import com.tsurugidb.iceaxe.sql.TsurugiSql;
import com.tsurugidb.iceaxe.transaction.TsurugiTransaction;
import com.tsurugidb.iceaxe.transaction.exception.TsurugiTransactionException;
import com.tsurugidb.iceaxe.util.IceaxeInternal;
import com.tsurugidb.iceaxe.util.IceaxeTimeout;
import com.tsurugidb.iceaxe.util.IceaxeTimeoutCloseable;
import com.tsurugidb.iceaxe.util.TgTimeValue;

/**
* Tsurugi SQL Result.
Expand All @@ -18,6 +22,9 @@ public abstract class TsurugiSqlResult implements IceaxeTimeoutCloseable {
private final TsurugiSql sqlStatement;
private final Object sqlParameter;

protected final IceaxeTimeout connectTimeout;

Check warning on line 25 in modules/iceaxe-core/src/main/java/com/tsurugidb/iceaxe/sql/result/TsurugiSqlResult.java

View workflow job for this annotation

GitHub Actions / Checkstyle

javadoc.JavadocVariableCheck

Missing a Javadoc comment.
protected final IceaxeTimeout closeTimeout;

Check warning on line 26 in modules/iceaxe-core/src/main/java/com/tsurugidb/iceaxe/sql/result/TsurugiSqlResult.java

View workflow job for this annotation

GitHub Actions / Checkstyle

javadoc.JavadocVariableCheck

Missing a Javadoc comment.

/**
* Creates a new instance.
* <p>
Expand All @@ -28,13 +35,19 @@ public abstract class TsurugiSqlResult implements IceaxeTimeoutCloseable {
* @param transaction transaction
* @param ps SQL definition
* @param parameter SQL parameter
* @param connectKey connect timeout key
* @param closeKey close timeout key
*/
@IceaxeInternal
public TsurugiSqlResult(int sqlExecuteId, TsurugiTransaction transaction, TsurugiSql ps, Object parameter) {
public TsurugiSqlResult(int sqlExecuteId, TsurugiTransaction transaction, TsurugiSql ps, Object parameter, TgTimeoutKey connectKey, TgTimeoutKey closeKey) {
this.iceaxeSqlExecuteId = sqlExecuteId;
this.ownerTransaction = transaction;
this.sqlStatement = ps;
this.sqlParameter = parameter;

var sessionOption = transaction.getSessionOption();
this.connectTimeout = new IceaxeTimeout(sessionOption, connectKey);
this.closeTimeout = new IceaxeTimeout(sessionOption, closeKey);
}

/**
Expand All @@ -50,6 +63,48 @@ protected void initialize() throws IOException {
ownerTransaction.addChild(this);
}

/**
* set connect timeout.
*
* @param time time value
* @param unit time unit
* @since X.X.X
*/
public void setConnectTimeout(long time, TimeUnit unit) {
setConnectTimeout(TgTimeValue.of(time, unit));
}

/**
* set connect timeout.
*
* @param timeout time
* @since X.X.X
*/
public void setConnectTimeout(TgTimeValue timeout) {
connectTimeout.set(timeout);
}

/**
* set close timeout.
*
* @param time timeout time
* @param unit timeout unit
* @since X.X.X
*/
public void setCloseTimeout(long time, TimeUnit unit) {
setCloseTimeout(TgTimeValue.of(time, unit));
}

/**
* set close timeout.
*
* @param timeout time
* @since X.X.X
*/
public void setCloseTimeout(TgTimeValue timeout) {
closeTimeout.set(timeout);
}

/**
* get iceaxe SQL executeId.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import com.tsurugidb.iceaxe.transaction.exception.TsurugiTransactionException;
import com.tsurugidb.iceaxe.util.IceaxeInternal;
import com.tsurugidb.iceaxe.util.IceaxeIoUtil;
import com.tsurugidb.iceaxe.util.IceaxeTimeout;
import com.tsurugidb.iceaxe.util.TgTimeValue;
import com.tsurugidb.tsubakuro.sql.ExecuteResult;
import com.tsurugidb.tsubakuro.util.FutureResponse;
Expand All @@ -41,8 +40,6 @@ public class TsurugiStatementResult extends TsurugiSqlResult {

private FutureResponse<ExecuteResult> lowResultFuture;
private TgResultCount resultCount = null;
private final IceaxeTimeout checkTimeout;
private final IceaxeTimeout closeTimeout;
private List<TsurugiStatementResultEventListener> eventListenerList = null;
private boolean checkResultOnClose = true;

Expand All @@ -59,11 +56,7 @@ public class TsurugiStatementResult extends TsurugiSqlResult {
*/
@IceaxeInternal
public TsurugiStatementResult(int sqlExecuteId, TsurugiTransaction transaction, TsurugiSql ps, Object parameter) {
super(sqlExecuteId, transaction, ps, parameter);

var sessionOption = transaction.getSessionOption();
this.checkTimeout = new IceaxeTimeout(sessionOption, TgTimeoutKey.RESULT_CONNECT);
this.closeTimeout = new IceaxeTimeout(sessionOption, TgTimeoutKey.RESULT_CLOSE);
super(sqlExecuteId, transaction, ps, parameter, TgTimeoutKey.RESULT_CONNECT, TgTimeoutKey.RESULT_CLOSE);
}

/**
Expand Down Expand Up @@ -106,37 +99,22 @@ public void initialize(FutureResponse<ExecuteResult> lowResultFuture) throws IOE
*
* @param time timeout time
* @param unit timeout unit
* @see #setConnectTimeout(long, TimeUnit)
*/
@Deprecated(since = "X.X.X", forRemoval = true)
public void setCheckTimeout(long time, TimeUnit unit) {
setCheckTimeout(TgTimeValue.of(time, unit));
setConnectTimeout(time, unit);
}

/**
* set check-timeout.
*
* @param timeout time
* @see #setConnectTimeout(TgTimeValue)
*/
@Deprecated(since = "X.X.X", forRemoval = true)
public void setCheckTimeout(TgTimeValue timeout) {
checkTimeout.set(timeout);
}

/**
* set close-timeout.
*
* @param time timeout time
* @param unit timeout unit
*/
public void setCloseTimeout(long time, TimeUnit unit) {
setCloseTimeout(TgTimeValue.of(time, unit));
}

/**
* set close-timeout.
*
* @param timeout time
*/
public void setCloseTimeout(TgTimeValue timeout) {
closeTimeout.set(timeout);
setConnectTimeout(timeout);
}

/**
Expand Down Expand Up @@ -206,7 +184,7 @@ public final synchronized void checkLowResult() throws IOException, InterruptedE
LOG.trace("lowResult get start");
try {
var lowExecuteResult = IceaxeIoUtil.getAndCloseFutureInTransaction(lowResultFuture, //
checkTimeout, IceaxeErrorCode.RESULT_CONNECT_TIMEOUT, //
connectTimeout, IceaxeErrorCode.RESULT_CONNECT_TIMEOUT, //
IceaxeErrorCode.RESULT_CLOSE_TIMEOUT);
this.resultCount = new TgResultCount(lowExecuteResult);
} catch (TsurugiTransactionException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void futureCloseTimeout_specified() throws Exception {
void futureCloseTimeout_set() throws Exception {
var sessionOption = TgSessionOption.of();

testFutureCloseTimeout(sessionOption, rs -> rs.setRsCloseTimeout(1, TimeUnit.SECONDS));
testFutureCloseTimeout(sessionOption, rs -> rs.setCloseTimeout(1, TimeUnit.SECONDS));
}

// FIXME rs.close()内部でgetLowResultSet()を呼んでいるため、rs.close()でのfutureクローズタイムアウト単独は実行できない
Expand Down Expand Up @@ -94,6 +94,14 @@ void lowCloseTimeout_specified() throws Exception {
void lowCloseTimeout_set() throws Exception {
var sessionOption = TgSessionOption.of();

testLowCloseTimeout(sessionOption, ps -> ps.setCloseTimeout(1, TimeUnit.SECONDS));
}

@Test
@SuppressWarnings("removal") // TODO remove this test
void lowCloseTimeout_set_old() throws Exception {
var sessionOption = TgSessionOption.of();

testLowCloseTimeout(sessionOption, ps -> ps.setRsCloseTimeout(1, TimeUnit.SECONDS));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ void connectTimeout_specified() throws Exception {
void connectTimeout_set() throws Exception {
var sessionOption = TgSessionOption.of();

testConnectTimeout(sessionOption, rs -> rs.setConnectTimeout(1, TimeUnit.SECONDS));
}

@Test
@SuppressWarnings("removal") // TODO remove this test
void connectTimeout_set_old() throws Exception {
var sessionOption = TgSessionOption.of();

testConnectTimeout(sessionOption, rs -> rs.setRsConnectTimeout(1, TimeUnit.SECONDS));
}

Expand Down Expand Up @@ -90,6 +98,14 @@ void futureCloseTimeout_specified() throws Exception {
void futureCloseTimeout_set() throws Exception {
var sessionOption = TgSessionOption.of();

testFutureCloseTimeout(sessionOption, rs -> rs.setConnectTimeout(1, TimeUnit.SECONDS));
}

@Test
@SuppressWarnings("removal") // TODO remove this test
void futureCloseTimeout_set_old() throws Exception {
var sessionOption = TgSessionOption.of();

testFutureCloseTimeout(sessionOption, rs -> rs.setRsConnectTimeout(1, TimeUnit.SECONDS));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ void connectTimeout_specified() throws Exception {
void connectTimeout_set() throws Exception {
var sessionOption = TgSessionOption.of();

testConnectTimeout(sessionOption, rs -> rs.setConnectTimeout(1, TimeUnit.SECONDS));
}

@Test
@SuppressWarnings("removal") // TODO remove this test
void connectTimeout_set_old() throws Exception {
var sessionOption = TgSessionOption.of();

testConnectTimeout(sessionOption, rs -> rs.setCheckTimeout(1, TimeUnit.SECONDS));
}

Expand Down Expand Up @@ -90,6 +98,14 @@ void futureCloseTimeout_specified() throws Exception {
void futureCloseTimeout_set() throws Exception {
var sessionOption = TgSessionOption.of();

testFutureCloseTimeout(sessionOption, rs -> rs.setConnectTimeout(1, TimeUnit.SECONDS));
}

@Test
@SuppressWarnings("removal") // TODO remove this test
void futureCloseTimeout_set_old() throws Exception {
var sessionOption = TgSessionOption.of();

testFutureCloseTimeout(sessionOption, rs -> rs.setCheckTimeout(1, TimeUnit.SECONDS));
}

Expand Down

0 comments on commit 36552bb

Please sign in to comment.