Skip to content

Commit

Permalink
unify on a single 'timeout' property
Browse files Browse the repository at this point in the history
  • Loading branch information
bbeaudreault committed Aug 27, 2017
1 parent a14aa65 commit 8b72506
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,17 @@
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;

import com.google.common.collect.ImmutableList;
import io.vitess.proto.Query.Field;
import java.util.List;
import java.util.Map;

import javax.annotation.Nullable;

import org.apache.commons.collections4.map.CaseInsensitiveMap;

import com.google.common.collect.ImmutableList;

import io.vitess.proto.Query.Field;

/**
* A wrapper for {@code List<Field>} that also facilitates lookup by field name.
*
Expand Down
42 changes: 7 additions & 35 deletions java/jdbc/src/main/java/io/vitess/jdbc/ConnectionProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -207,21 +207,9 @@ public class ConnectionProperties {
"Should the driver treat java.util.Date as a TIMESTAMP for the purposes of PreparedStatement.setObject()",
true);

private LongConnectionProperty queryTimeout = new LongConnectionProperty(
"queryTimeout",
"The default query timeout, in millis, to use for queries which do not explicitly setQueryTimeout",
Constants.DEFAULT_TIMEOUT
);

private LongConnectionProperty connectionTimeout = new LongConnectionProperty(
"connectionTimeout",
"The timeout, in millis, to use when creating new gRPC connections",
Constants.CONNECTION_TIMEOUT
);

private LongConnectionProperty transactionTimeout = new LongConnectionProperty(
"transactionTimeout",
"The timeout, in millis, to use when committing or rolling back transactions",
private LongConnectionProperty timeout = new LongConnectionProperty(
"timeout",
"The default timeout, in millis, to use for queries, connections, and transaction commit/rollback. Query timeout can be overridden by explicitly calling setQueryTimeout",
Constants.DEFAULT_TIMEOUT
);

Expand Down Expand Up @@ -480,28 +468,12 @@ public void setTreatUtilDateAsTimestamp(boolean treatUtilDateAsTimestamp) {
this.treatUtilDateAsTimestamp.setValue(treatUtilDateAsTimestamp);
}

public long getQueryTimeout() {
return queryTimeout.getValueAsLong();
}

public void setQueryTimeout(long queryTimeout) {
this.queryTimeout.setValue(queryTimeout);
}

public long getConnectionTimeout() {
return connectionTimeout.getValueAsLong();
}

public void setConnectionTimeout(long connectionTimeout) {
this.connectionTimeout.setValue(connectionTimeout);
}

public long getTransactionTimeout() {
return transactionTimeout.getValueAsLong();
public long getTimeout() {
return timeout.getValueAsLong();
}

public void setTransactionTimeout(long transactionTimeout) {
this.transactionTimeout.setValue(transactionTimeout);
public void setTimeout(long timeout) {
this.timeout.setValue(timeout);
}

public String getTarget() {
Expand Down
4 changes: 2 additions & 2 deletions java/jdbc/src/main/java/io/vitess/jdbc/VitessConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public void commit() throws SQLException {
checkAutoCommit(Constants.SQLExceptionMessages.COMMIT_WHEN_AUTO_COMMIT_TRUE);
try {
if (isInTransaction()) {
Context context = createContext(getTransactionTimeout());
Context context = createContext(getTimeout());
this.vtGateTx.commit(context, getTwopcEnabled()).checkedGet();
}
} finally {
Expand All @@ -191,7 +191,7 @@ public void rollback() throws SQLException {
checkAutoCommit(Constants.SQLExceptionMessages.ROLLBACK_WHEN_AUTO_COMMIT_TRUE);
try {
if (isInTransaction()) {
Context context = createContext(getTransactionTimeout());
Context context = createContext(getTimeout());
this.vtGateTx.rollback(context).checkedGet();
}
} finally {
Expand Down
4 changes: 2 additions & 2 deletions java/jdbc/src/main/java/io/vitess/jdbc/VitessStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public VitessStatement(VitessConnection vitessConnection) {
public VitessStatement(VitessConnection vitessConnection, int resultSetType,
int resultSetConcurrency) {
this.vitessConnection = vitessConnection;
this.queryTimeoutInMillis = vitessConnection.getQueryTimeout();
this.queryTimeoutInMillis = vitessConnection.getTimeout();
this.vitessResultSet = null;
this.resultSetType = resultSetType;
this.resultSetConcurrency = resultSetConcurrency;
Expand Down Expand Up @@ -268,7 +268,7 @@ public void setQueryTimeout(int seconds) throws SQLException {
Constants.SQLExceptionMessages.ILLEGAL_VALUE_FOR + "query timeout");
}
this.queryTimeoutInMillis =
(0 == seconds) ? vitessConnection.getQueryTimeout() : (long) seconds * 1000;
(0 == seconds) ? vitessConnection.getTimeout() : (long) seconds * 1000;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ private static void updateVtGateConnHashMap(String identifier, VitessJDBCUrl.Hos
private static VTGateConn getVtGateConn(VitessJDBCUrl.HostInfo hostInfo, VitessConnection connection) {
final String username = connection.getUsername();
final String keyspace = connection.getKeyspace();
final Context context = CommonUtils.createContext(username,connection.getConnectionTimeout());
final Context context = CommonUtils.createContext(username,connection.getTimeout());
RetryingInterceptorConfig retryingConfig = getRetryingInterceptorConfig(connection);
RpcClient client;
if (connection.getUseSSL()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

public class ConnectionPropertiesTest {

private static final int NUM_PROPS = 34;
private static final int NUM_PROPS = 32;

@Test
public void testReflection() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -530,23 +530,23 @@ private void testExecute(int fetchSize, boolean simpleExecute, boolean shouldRun

@Test public void testGetQueryTimeout() throws SQLException {
VitessConnection mockConn = PowerMockito.mock(VitessConnection.class);
Mockito.when(mockConn.getQueryTimeout()).thenReturn((long)Constants.DEFAULT_TIMEOUT);
Mockito.when(mockConn.getTimeout()).thenReturn((long)Constants.DEFAULT_TIMEOUT);

VitessStatement statement = new VitessStatement(mockConn);
Assert.assertEquals(30, statement.getQueryTimeout());
}

@Test public void testGetQueryTimeoutZeroDefault() throws SQLException {
VitessConnection mockConn = PowerMockito.mock(VitessConnection.class);
Mockito.when(mockConn.getQueryTimeout()).thenReturn(0L);
Mockito.when(mockConn.getTimeout()).thenReturn(0L);

VitessStatement statement = new VitessStatement(mockConn);
Assert.assertEquals(0, statement.getQueryTimeout());
}

@Test public void testSetQueryTimeout() throws SQLException {
VitessConnection mockConn = PowerMockito.mock(VitessConnection.class);
Mockito.when(mockConn.getQueryTimeout()).thenReturn((long)Constants.DEFAULT_TIMEOUT);
Mockito.when(mockConn.getTimeout()).thenReturn((long)Constants.DEFAULT_TIMEOUT);

VitessStatement statement = new VitessStatement(mockConn);

Expand Down

0 comments on commit 8b72506

Please sign in to comment.