Skip to content
Permalink
Browse files

fix: remove currentTimeMillis from code, tests are OK (#1617)

  • Loading branch information
davecramer committed Nov 26, 2019
1 parent 9a193de commit ff4a66d29d863cb4a6d2aecee2faec424f8d51d7
@@ -397,7 +397,7 @@ public void run() {
* @throws SQLException if a connection error occurs or the timeout is reached
*/
public Connection getResult(long timeout) throws SQLException {
long expiry = System.currentTimeMillis() + timeout;
long expiry = System.nanoTime() / 1000 + timeout;
synchronized (this) {
while (true) {
if (result != null) {
@@ -416,7 +416,7 @@ public Connection getResult(long timeout) throws SQLException {
}
}

long delay = expiry - System.currentTimeMillis();
long delay = expiry - System.nanoTime() / 1000;
if (delay <= 0) {
abandoned = true;
throw new PSQLException(GT.tr("Connection attempt timed out."),
@@ -717,7 +717,7 @@ public synchronized void processNotifies(int timeoutMillis) throws SQLException
long startTime = 0;
int oldTimeout = 0;
if (useTimeout) {
startTime = System.currentTimeMillis();
startTime = System.nanoTime() / 1000;
try {
oldTimeout = pgStream.getSocket().getSoTimeout();
} catch (SocketException e) {
@@ -747,7 +747,7 @@ public synchronized void processNotifies(int timeoutMillis) throws SQLException
SQLWarning warning = receiveNoticeResponse();
addWarning(warning);
if (useTimeout) {
long newTimeMillis = System.currentTimeMillis();
long newTimeMillis = System.nanoTime() / 1000;
timeoutMillis += startTime - newTimeMillis; // Overflows after 49 days, ignore that
startTime = newTimeMillis;
if (timeoutMillis == 0) {
@@ -5,8 +5,6 @@

package org.postgresql.hostchooser;

import static java.lang.System.currentTimeMillis;

import org.postgresql.util.HostSpec;

import java.util.ArrayList;
@@ -28,7 +26,7 @@
* @param hostStatus Latest known status for the host.
*/
public static void reportHostStatus(HostSpec hostSpec, HostStatus hostStatus) {
long now = currentTimeMillis();
long now = System.nanoTime() / 1000;
synchronized (hostStatusMap) {
HostSpecStatus hostSpecStatus = hostStatusMap.get(hostSpec);
if (hostSpecStatus == null) {
@@ -51,7 +49,7 @@ public static void reportHostStatus(HostSpec hostSpec, HostStatus hostStatus) {
static List<HostSpec> getCandidateHosts(HostSpec[] hostSpecs,
HostRequirement targetServerType, long hostRecheckMillis) {
List<HostSpec> candidates = new ArrayList<HostSpec>(hostSpecs.length);
long latestAllowedUpdate = currentTimeMillis() - hostRecheckMillis;
long latestAllowedUpdate = System.nanoTime() / 1000 - hostRecheckMillis;
synchronized (hostStatusMap) {
for (HostSpec hostSpec : hostSpecs) {
HostSpecStatus hostInfo = hostStatusMap.get(hostSpec);

0 comments on commit ff4a66d

Please sign in to comment.
You can’t perform that action at this time.