Skip to content

Commit

Permalink
revert (#2230)
Browse files Browse the repository at this point in the history
  • Loading branch information
lilgreenbird authored Oct 6, 2023
1 parent b1f7b09 commit 6dcf4ff
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1859,7 +1859,7 @@ Connection connect(Properties propsIn, SQLServerPooledConnection pooledConnectio
if (0 == connectRetryCount) {
// connection retry disabled
throw e;
} else if (++connectRetryAttempt > connectRetryCount) {
} else if (connectRetryAttempt++ > connectRetryCount) {
// maximum connection retry count reached
if (connectionlogger.isLoggable(Level.FINE)) {
connectionlogger.fine("Connection failed. Maximum connection retry count "
Expand Down Expand Up @@ -3249,7 +3249,6 @@ private void login(String primary, String primaryInstanceName, int primaryPortNu
|| (SQLServerException.ERROR_SOCKET_TIMEOUT == driverErrorCode // socket timeout
&& (!isDBMirroring || attemptNumber > 0)) // If mirroring, only close after failover has been tried (attempt >= 1)
|| timerHasExpired(timerExpire)
|| (state.equals(State.CONNECTED) && !isDBMirroring)
// for non-dbmirroring cases, do not retry after tcp socket connection succeeds
) {
// close the connection and throw the error back
Expand Down Expand Up @@ -6329,9 +6328,10 @@ final boolean complete(LogonCommand logonCommand, TDSReader tdsReader) throws SQ
serverName = currentConnectPlaceHolder.getFullServerName();
} else {
serverName = activeConnectionProperties.getProperty(SQLServerDriverStringProperty.SERVER_NAME.toString());
if (null != activeConnectionProperties.getProperty(SQLServerDriverStringProperty.INSTANCE_NAME.toString())) {
serverName += "\\" +
activeConnectionProperties.getProperty(SQLServerDriverStringProperty.INSTANCE_NAME.toString());
if (null != activeConnectionProperties
.getProperty(SQLServerDriverStringProperty.INSTANCE_NAME.toString())) {
serverName += "\\" + activeConnectionProperties
.getProperty(SQLServerDriverStringProperty.INSTANCE_NAME.toString());
}
}

Expand Down Expand Up @@ -7390,7 +7390,8 @@ void endRequestInternal() throws SQLException {
String replaceParameterMarkers(String sqlSrc, int[] paramPositions, Parameter[] params,
boolean isReturnValueSyntax) {
final int MAX_PARAM_NAME_LEN = 6;
char[] sqlDst = new char[sqlSrc.length() + (params.length * (MAX_PARAM_NAME_LEN + OUT.length)) + (params.length * 2)];
char[] sqlDst = new char[sqlSrc.length() + (params.length * (MAX_PARAM_NAME_LEN + OUT.length))
+ (params.length * 2)];
int dstBegin = 0;
int srcBegin = 0;
int nParam = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -478,39 +478,6 @@ public void testConnectCountInLoginAndCorrectRetryCount() {
}
}

/**
* Tests whether connectRetryCount and connectRetryInterval are properly respected in the login loop. As well, tests
* that connection is retried the proper number of times. This is for cases with zero retries.
*/
@Test
public void testConnectCountInLoginAndCorrectRetryCountWithZeroRetry() {
long timerStart = 0;

int connectRetryCount = 0;
int connectRetryInterval = 60;
int longLoginTimeout = loginTimeOutInSeconds * 3; // 90 seconds

try {
SQLServerDataSource ds = new SQLServerDataSource();
ds.setURL(connectionString);
ds.setLoginTimeout(longLoginTimeout);
ds.setConnectRetryCount(connectRetryCount);
ds.setConnectRetryInterval(connectRetryInterval);
ds.setDatabaseName(RandomUtil.getIdentifier("DataBase"));
timerStart = System.currentTimeMillis();

try (Connection con = ds.getConnection()) {
assertTrue(con == null, TestResource.getResource("R_shouldNotConnect"));
}
} catch (Exception e) {
assertTrue(e.getMessage().contains(TestResource.getResource("R_cannotOpenDatabase")), e.getMessage());
long totalTime = System.currentTimeMillis() - timerStart;

// Maximum is unknown, but is needs to be less than longLoginTimeout or else this is an issue.
assertTrue(totalTime < (longLoginTimeout * 1000L), TestResource.getResource("R_executionTooLong"));
}
}

@Test
@Tag(Constants.xAzureSQLDW)
@Tag(Constants.xAzureSQLDB)
Expand Down

0 comments on commit 6dcf4ff

Please sign in to comment.