Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeffery-Wasty committed Apr 23, 2024
1 parent 03c5f6e commit 62a634a
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public class ConfigurableRetryLogic {
private static HashMap<Integer, ConfigRetryRule> cxnRules = new HashMap<>();
private static HashMap<Integer, ConfigRetryRule> stmtRules = new HashMap<>();


private ConfigurableRetryLogic() throws SQLServerException {
timeLastRead = new Date().getTime();
setUpRules();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1366,14 +1366,12 @@ public boolean getCalcBigDecimalPrecision() {

@Override
public void setRetryExec(String retryExec) {
setStringProperty(connectionProps, SQLServerDriverStringProperty.RETRY_EXEC.toString(),
retryExec);
setStringProperty(connectionProps, SQLServerDriverStringProperty.RETRY_EXEC.toString(), retryExec);
}

@Override
public String getRetryExec() {
return getStringProperty(connectionProps, SQLServerDriverStringProperty.RETRY_EXEC.toString(),
null);
return getStringProperty(connectionProps, SQLServerDriverStringProperty.RETRY_EXEC.toString(), null);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ enum SQLServerDriverStringProperty {
SERVER_CERTIFICATE("serverCertificate", ""),
DATETIME_DATATYPE("datetimeParameterType", DatetimeType.DATETIME2.toString()),
ACCESS_TOKEN_CALLBACK_CLASS("accessTokenCallbackClass", ""),
RETRY_EXEC("retryExec","");
RETRY_EXEC("retryExec", "");

private final String name;
private final String defaultValue;
Expand Down
15 changes: 10 additions & 5 deletions src/main/java/com/microsoft/sqlserver/jdbc/SQLServerStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -272,21 +272,25 @@ final void executeStatement(TDSCommand newStmtCmd) throws SQLServerException, SQ
ConfigRetryRule rule = null;

if (null != sqlServerError) {
rule = ConfigurableRetryLogic.getInstance().searchRuleSet(e.getSQLServerError().getErrorNumber(), "statement");
rule = ConfigurableRetryLogic.getInstance().searchRuleSet(e.getSQLServerError().getErrorNumber(),
"statement");
}

if (null != rule && retryAttempt < rule.getRetryCount()) {
boolean meetsQueryMatch = true;
if (!(rule.getRetryQueries().isEmpty())) {
// If query has been defined for the rule, we need to query match
meetsQueryMatch = rule.getRetryQueries().contains(ConfigurableRetryLogic.getInstance().getLastQuery().split(" ")[0]);
meetsQueryMatch = rule.getRetryQueries()
.contains(ConfigurableRetryLogic.getInstance().getLastQuery().split(" ")[0]);
}

if (meetsQueryMatch) {
try {
int timeToWait = rule.getWaitTimes().get(retryAttempt);
if (connection.getQueryTimeoutSeconds() >= 0 && timeToWait > connection.getQueryTimeoutSeconds()) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_InvalidRetryInterval"));
if (connection.getQueryTimeoutSeconds() >= 0
&& timeToWait > connection.getQueryTimeoutSeconds()) {
MessageFormat form = new MessageFormat(
SQLServerException.getErrString("R_InvalidRetryInterval"));
throw new SQLServerException(null, form.format(new Object[] {}), null, 0, true);
}
try {
Expand All @@ -295,7 +299,8 @@ final void executeStatement(TDSCommand newStmtCmd) throws SQLServerException, SQ
Thread.currentThread().interrupt();
}
} catch (IndexOutOfBoundsException exc) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_indexOutOfRange"));
MessageFormat form = new MessageFormat(
SQLServerException.getErrString("R_indexOutOfRange"));
Object[] msgArgs = {retryAttempt};
throw new SQLServerException(this, form.format(msgArgs), null, 0, false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ public static void setupTests() throws Exception {

/**
* Tests that statement retry works with prepared statements.
*
* @throws Exception
* if unable to connect or execute against db
* if unable to connect or execute against db
*/
@Test
public void testStatementRetryPreparedStatement() throws Exception {
Expand All @@ -59,8 +60,9 @@ public void testStatementRetryPreparedStatement() throws Exception {

/**
* Tests that statement retry works with callable statements.
*
* @throws Exception
* if unable to connect or execute against db
* if unable to connect or execute against db
*/
@Test
public void testStatementRetryCallableStatement() throws Exception {
Expand All @@ -85,8 +87,9 @@ public void testStatementRetryCallableStatement() throws Exception {

/**
* Tests that statement retry works with statements. Used in below negative testing.
*
* @throws Exception
* if unable to connect or execute against db
* if unable to connect or execute against db
*/
public void testStatementRetry(String addedRetryParams) throws Exception {
String cxnString = connectionString + addedRetryParams; // 2714 There is already an object named x
Expand All @@ -107,8 +110,9 @@ public void testStatementRetry(String addedRetryParams) throws Exception {

/**
* Tests that statement retry works with statements. A different error is expected here than the test above.
*
* @throws Exception
* if unable to connect or execute against db
* if unable to connect or execute against db
*/
public void testStatementRetryWithShortQueryTimeout(String addedRetryParams) throws Exception {
String cxnString = connectionString + addedRetryParams; // 2714 There is already an object named x
Expand Down Expand Up @@ -156,11 +160,9 @@ public void statementTimingTests() {
} finally {
totalTime = System.currentTimeMillis() - timerStart;
assertTrue(totalTime > TimeUnit.SECONDS.toMillis(5),
"total time: " + totalTime + ", expected minimum time: "
+ TimeUnit.SECONDS.toMillis(5));
assertTrue(totalTime < TimeUnit.SECONDS.toMillis(5 + expectedTime),
"total time: " + totalTime + ", expected maximum time: "
+ TimeUnit.SECONDS.toMillis(5 + expectedTime));
"total time: " + totalTime + ", expected minimum time: " + TimeUnit.SECONDS.toMillis(5));
assertTrue(totalTime < TimeUnit.SECONDS.toMillis(5 + expectedTime), "total time: " + totalTime
+ ", expected maximum time: " + TimeUnit.SECONDS.toMillis(5 + expectedTime));
}

timerStart = System.currentTimeMillis();
Expand All @@ -173,11 +175,9 @@ public void statementTimingTests() {
} finally {
totalTime = System.currentTimeMillis() - timerStart;
assertTrue(totalTime > TimeUnit.SECONDS.toMillis(8),
"total time: " + totalTime + ", expected minimum time: "
+ TimeUnit.SECONDS.toMillis(8));
assertTrue(totalTime < TimeUnit.SECONDS.toMillis(8 + expectedTime),
"total time: " + totalTime + ", expected maximum time: "
+ TimeUnit.SECONDS.toMillis(8 + expectedTime));
"total time: " + totalTime + ", expected minimum time: " + TimeUnit.SECONDS.toMillis(8));
assertTrue(totalTime < TimeUnit.SECONDS.toMillis(8 + expectedTime), "total time: " + totalTime
+ ", expected maximum time: " + TimeUnit.SECONDS.toMillis(8 + expectedTime));
}

timerStart = System.currentTimeMillis();
Expand All @@ -190,11 +190,9 @@ public void statementTimingTests() {
} finally {
totalTime = System.currentTimeMillis() - timerStart;
assertTrue(totalTime > TimeUnit.SECONDS.toMillis(10),
"total time: " + totalTime + ", expected minimum time: "
+ TimeUnit.SECONDS.toMillis(10));
assertTrue(totalTime < TimeUnit.SECONDS.toMillis(10 + expectedTime),
"total time: " + totalTime + ", expected maximum time: "
+ TimeUnit.SECONDS.toMillis(10 + expectedTime));
"total time: " + totalTime + ", expected minimum time: " + TimeUnit.SECONDS.toMillis(10));
assertTrue(totalTime < TimeUnit.SECONDS.toMillis(10 + expectedTime), "total time: " + totalTime
+ ", expected maximum time: " + TimeUnit.SECONDS.toMillis(10 + expectedTime));
}
}

Expand Down Expand Up @@ -251,8 +249,9 @@ public void testCorrectlyFormattedRules() {

/**
* Tests that rules with an invalid retry error correctly fail.
*
* @throws Exception
* for the invalid parameter
* for the invalid parameter
*/
@Test
public void testRetryError() throws Exception {
Expand All @@ -273,8 +272,9 @@ public void testRetryError() throws Exception {

/**
* Tests that rules with an invalid retry count correctly fail.
*
* @throws Exception
* for the invalid parameter
* for the invalid parameter
*/
@Test
public void testRetryCount() throws Exception {
Expand All @@ -295,8 +295,9 @@ public void testRetryCount() throws Exception {

/**
* Tests that rules with an invalid initial retry time correctly fail.
*
* @throws Exception
* for the invalid parameter
* for the invalid parameter
*/
@Test
public void testInitialRetryTime() throws Exception {
Expand All @@ -317,8 +318,9 @@ public void testInitialRetryTime() throws Exception {

/**
* Tests that rules with an invalid operand correctly fail.
*
* @throws Exception
* for the invalid parameter
* for the invalid parameter
*/
@Test
public void testOperand() throws Exception {
Expand All @@ -332,8 +334,9 @@ public void testOperand() throws Exception {

/**
* Tests that rules with an invalid retry change correctly fail.
*
* @throws Exception
* for the invalid parameter
* for the invalid parameter
*/
@Test
public void testRetryChange() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
package com.microsoft.sqlserver.jdbc;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.jupiter.api.Assertions.assertThrows;

import java.io.IOException;
import java.io.Reader;
Expand Down Expand Up @@ -213,8 +213,7 @@ public void testDataSource() throws SQLServerException {
assertEquals(booleanPropValue, ds.getCalcBigDecimalPrecision(),
TestResource.getResource("R_valuesAreDifferent"));
ds.setRetryExec(stringPropValue);
assertEquals(stringPropValue, ds.getRetryExec(),
TestResource.getResource("R_valuesAreDifferent"));
assertEquals(stringPropValue, ds.getRetryExec(), TestResource.getResource("R_valuesAreDifferent"));

ds.setServerCertificate(stringPropValue);
assertEquals(stringPropValue, ds.getServerCertificate(), TestResource.getResource("R_valuesAreDifferent"));
Expand Down

0 comments on commit 62a634a

Please sign in to comment.