diff --git a/jetty-http2/http2-hpack/src/test/java/org/eclipse/jetty/http2/hpack/HpackTest.java b/jetty-http2/http2-hpack/src/test/java/org/eclipse/jetty/http2/hpack/HpackTest.java index 5eed59ae8f9..31c1ee21d8f 100644 --- a/jetty-http2/http2-hpack/src/test/java/org/eclipse/jetty/http2/hpack/HpackTest.java +++ b/jetty-http2/http2-hpack/src/test/java/org/eclipse/jetty/http2/hpack/HpackTest.java @@ -19,6 +19,7 @@ package org.eclipse.jetty.http2.hpack; import java.nio.ByteBuffer; +import java.util.concurrent.TimeUnit; import org.eclipse.jetty.http.BadMessageException; import org.eclipse.jetty.http.DateGenerator; @@ -42,7 +43,7 @@ public class HpackTest { final static HttpField ServerJetty = new PreEncodedHttpField(HttpHeader.SERVER,"jetty"); final static HttpField XPowerJetty = new PreEncodedHttpField(HttpHeader.X_POWERED_BY,"jetty"); - final static HttpField Date = new PreEncodedHttpField(HttpHeader.DATE,DateGenerator.formatDate(System.currentTimeMillis())); + final static HttpField Date = new PreEncodedHttpField(HttpHeader.DATE,DateGenerator.formatDate(TimeUnit.NANOSECONDS.toMillis(System.nanoTime()))); @Test public void encodeDecodeResponseTest() diff --git a/jetty-io/src/test/java/org/eclipse/jetty/io/SelectChannelEndPointTest.java b/jetty-io/src/test/java/org/eclipse/jetty/io/SelectChannelEndPointTest.java index e0a30bb8af0..02268ce0d09 100644 --- a/jetty-io/src/test/java/org/eclipse/jetty/io/SelectChannelEndPointTest.java +++ b/jetty-io/src/test/java/org/eclipse/jetty/io/SelectChannelEndPointTest.java @@ -189,7 +189,7 @@ public class SelectChannelEndPointTest EndPoint _endp = getEndPoint(); try { - _last = System.currentTimeMillis(); + _last = TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); boolean progress = true; while (progress) { @@ -293,7 +293,7 @@ public class SelectChannelEndPointTest // wait for read timeout client.setSoTimeout(500); - long start = System.currentTimeMillis(); + long start = TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); try { client.getInputStream().read(); @@ -301,7 +301,7 @@ public class SelectChannelEndPointTest } catch (SocketTimeoutException e) { - long duration = System.currentTimeMillis() - start; + long duration = TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) - start; Assert.assertThat("timeout duration", duration, greaterThanOrEqualTo(400L)); } @@ -351,7 +351,7 @@ public class SelectChannelEndPointTest } // wait for read timeout - long start = System.currentTimeMillis(); + long start = TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); try { client.getInputStream().read(); @@ -359,7 +359,7 @@ public class SelectChannelEndPointTest } catch (SocketTimeoutException e) { - assertTrue(System.currentTimeMillis() - start >= 400); + assertTrue(TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) - start >= 400); } // write then shutdown @@ -403,7 +403,7 @@ public class SelectChannelEndPointTest _lastEndPoint.setIdleTimeout(10 * specifiedTimeout); Thread.sleep((11 * specifiedTimeout) / 10); - long start = System.currentTimeMillis(); + long start = TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); try { int b = clientInputStream.read(); @@ -411,7 +411,7 @@ public class SelectChannelEndPointTest } catch (SocketTimeoutException e) { - int elapsed = Long.valueOf(System.currentTimeMillis() - start).intValue(); + int elapsed = Long.valueOf(TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) - start).intValue(); Assert.assertThat("Expected timeout", elapsed, greaterThanOrEqualTo(3 * specifiedTimeout / 4)); } @@ -431,9 +431,11 @@ public class SelectChannelEndPointTest @Test public void testIdle() throws Exception { + int idleTimeout = 1000; + Socket client = newClient(); - client.setSoTimeout(3000); + client.setSoTimeout(idleTimeout*10); SocketChannel server = _connector.accept(); server.configureBlocking(false); @@ -452,14 +454,13 @@ public class SelectChannelEndPointTest } Assert.assertTrue(_lastEndPointLatch.await(1, TimeUnit.SECONDS)); - int idleTimeout = 500; _lastEndPoint.setIdleTimeout(idleTimeout); // read until idle shutdown received - long start = System.currentTimeMillis(); + long start = TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); int b = client.getInputStream().read(); assertEquals(-1, b); - long idle = System.currentTimeMillis() - start; + long idle = TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) - start; assertTrue(idle > idleTimeout / 2); assertTrue(idle < idleTimeout * 2); @@ -509,10 +510,10 @@ public class SelectChannelEndPointTest clientOutputStream.flush(); // read until idle shutdown received - long start = System.currentTimeMillis(); + long start = TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); int b = clientInputStream.read(); assertEquals('E', b); - long idle = System.currentTimeMillis() - start; + long idle = TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) - start; assertTrue(idle > idleTimeout / 2); assertTrue(idle < idleTimeout * 2); @@ -551,7 +552,7 @@ public class SelectChannelEndPointTest BufferedOutputStream out = new BufferedOutputStream(client.getOutputStream()); final CountDownLatch latch = new CountDownLatch(writes); final InputStream in = new BufferedInputStream(client.getInputStream()); - final long start = System.currentTimeMillis(); + final long start = TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); out.write(bytes); out.write(count); out.flush(); @@ -586,7 +587,7 @@ public class SelectChannelEndPointTest count = count * 10 + (b - '0'); b = in.read(); } - last = System.currentTimeMillis(); + last = TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); //if (latch.getCount()%1000==0) // System.out.println(writes-latch.getCount()); @@ -597,7 +598,7 @@ public class SelectChannelEndPointTest catch (Throwable e) { - long now = System.currentTimeMillis(); + long now = TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); System.err.println("count=" + count); System.err.println("latch=" + latch.getCount()); System.err.println("time=" + (now - start)); diff --git a/jetty-monitor/src/test/java/org/eclipse/jetty/monitor/ThreadMonitorTest.java b/jetty-monitor/src/test/java/org/eclipse/jetty/monitor/ThreadMonitorTest.java index 9d34ae0b83f..6072763179e 100644 --- a/jetty-monitor/src/test/java/org/eclipse/jetty/monitor/ThreadMonitorTest.java +++ b/jetty-monitor/src/test/java/org/eclipse/jetty/monitor/ThreadMonitorTest.java @@ -120,8 +120,8 @@ public class ThreadMonitorTest public void spin() { long result=-1; - long end=System.currentTimeMillis()+DURATION+1000; - while (!done && System.currentTimeMillis()",Integer.toString(period)); - long start=System.currentTimeMillis(); + long start=TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); String request = "GET "+uri+" HTTP/1.1\r\n"+ "Host: localhost\r\n"+ diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/ConnectorTimeoutTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/ConnectorTimeoutTest.java index 111b22daad3..e20051ff9d5 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/ConnectorTimeoutTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/ConnectorTimeoutTest.java @@ -101,14 +101,14 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture "\r\n").getBytes("utf-8")); os.flush(); - long start = System.currentTimeMillis(); + long start = TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); IO.toString(is); Thread.sleep(sleepTime); Assert.assertEquals(-1, is.read()); - Assert.assertTrue(System.currentTimeMillis() - start > minimumTestRuntime); - Assert.assertTrue(System.currentTimeMillis() - start < maximumTestRuntime); + Assert.assertTrue(TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) - start > minimumTestRuntime); + Assert.assertTrue(TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) - start < maximumTestRuntime); } @Test(timeout=60000) @@ -134,14 +134,14 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture os.write(contentB); os.flush(); - long start = System.currentTimeMillis(); + long start = TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); IO.toString(is); Thread.sleep(sleepTime); Assert.assertEquals(-1, is.read()); - Assert.assertTrue(System.currentTimeMillis() - start > minimumTestRuntime); - Assert.assertTrue(System.currentTimeMillis() - start < maximumTestRuntime); + Assert.assertTrue(TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) - start > minimumTestRuntime); + Assert.assertTrue(TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) - start < maximumTestRuntime); } @Test(timeout=60000) @@ -273,8 +273,8 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture // further writes will get broken pipe or similar try { - long end=System.currentTimeMillis()+MAX_IDLE_TIME+3000; - while (System.currentTimeMillis()=2000) + if ((TimeUnit.NANOSECONDS.toMillis(System.nanoTime())-start)>=2000) Assert.fail(); offset = checkContains(response,offset,"HTTP/1.1 200"); diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/RequestTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/RequestTest.java index 41c18f8103d..318a3ffcdc5 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/RequestTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/RequestTest.java @@ -1561,13 +1561,13 @@ public class RequestTest "\r\n"+ buf; - long start=System.currentTimeMillis(); + long start=TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); String rawResponse = _connector.getResponse(request); HttpTester.Response response = HttpTester.parseResponse(rawResponse); assertThat("Response.status", response.getStatus(), is(400)); assertThat("Response body content", response.getContent(),containsString(BadMessageException.class.getName())); assertThat("Response body content", response.getContent(),containsString(IllegalStateException.class.getName())); - long now=System.currentTimeMillis(); + long now=TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); assertTrue((now-start)<5000); } } @@ -1605,13 +1605,13 @@ public class RequestTest "\r\n"+ buf; - long start=System.currentTimeMillis(); + long start=TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); String rawResponse = _connector.getResponse(request); HttpTester.Response response = HttpTester.parseResponse(rawResponse); assertThat("Response.status", response.getStatus(), is(400)); assertThat("Response body content", response.getContent(),containsString(BadMessageException.class.getName())); assertThat("Response body content", response.getContent(),containsString(IllegalStateException.class.getName())); - long now=System.currentTimeMillis(); + long now=TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); assertTrue((now-start)<5000); } } diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/ServerConnectorTimeoutTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/ServerConnectorTimeoutTest.java index ef6345d7e25..b8a561822c5 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/ServerConnectorTimeoutTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/ServerConnectorTimeoutTest.java @@ -123,9 +123,9 @@ public class ServerConnectorTimeoutTest extends ConnectorTimeoutTest socket.setSoTimeout(10 * MAX_IDLE_TIME); socket.getOutputStream().write(request.getBytes(StandardCharsets.UTF_8)); InputStream inputStream = socket.getInputStream(); - long start = System.currentTimeMillis(); + long start = TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); String response = IO.toString(inputStream); - long timeElapsed = System.currentTimeMillis() - start; + long timeElapsed = TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) - start; Assert.assertTrue("Time elapsed should be at least MAX_IDLE_TIME",timeElapsed > MAX_IDLE_TIME); return response; } diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/StressTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/StressTest.java index 07c03338390..d5e2368f853 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/StressTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/StressTest.java @@ -27,6 +27,7 @@ import java.net.Socket; import java.util.Queue; import java.util.Random; import java.util.concurrent.ConcurrentLinkedQueue; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import javax.servlet.ServletException; @@ -344,12 +345,12 @@ public class StressTest { if (persistent) { - long start=System.currentTimeMillis(); + long start=TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); Socket socket= new Socket("localhost", _connector.getLocalPort()); socket.setSoTimeout(30000); socket.setSoLinger(false,0); - long connected=System.currentTimeMillis(); + long connected=TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); for (int i=0;i<__tests.length;i++) { @@ -367,12 +368,12 @@ public class StressTest Thread.yield(); } - long written=System.currentTimeMillis(); + long written=TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); String response = IO.toString(socket.getInputStream()); socket.close(); - long end=System.currentTimeMillis(); + long end=TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); int bodies = count(response,"HTTP/1.1 200 OK"); if (__tests.length!=bodies) @@ -406,7 +407,7 @@ public class StressTest { String uri=__tests[i]+"/"+name+"/"+i; - long start=System.currentTimeMillis(); + long start=TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); String close="Connection: close\r\n"; String request = "GET "+uri+" HTTP/1.1\r\n"+ @@ -418,16 +419,16 @@ public class StressTest socket.setSoTimeout(10000); socket.setSoLinger(false,0); - _latencies[0].add(new Long(System.currentTimeMillis()-start)); + _latencies[0].add(new Long(TimeUnit.NANOSECONDS.toMillis(System.nanoTime())-start)); socket.getOutputStream().write(request.getBytes()); socket.getOutputStream().flush(); - _latencies[1].add(new Long(System.currentTimeMillis()-start)); + _latencies[1].add(new Long(TimeUnit.NANOSECONDS.toMillis(System.nanoTime())-start)); String response = IO.toString(socket.getInputStream()); socket.close(); - long end=System.currentTimeMillis(); + long end=TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); String endOfResponse = "\r\n\r\n"; assertTrue("response = '" + response + "'", response.contains(endOfResponse)); @@ -459,7 +460,7 @@ public class StressTest @Override public void handle(String target, final Request baseRequest, final HttpServletRequest request, final HttpServletResponse response) throws IOException, ServletException { - long now=System.currentTimeMillis(); + long now=TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); long start=Long.parseLong(baseRequest.getHeader("start")); long received=baseRequest.getTimeStamp(); @@ -474,7 +475,7 @@ public class StressTest response.getOutputStream().print("DATA "+request.getPathInfo()+"\n\n"); baseRequest.setHandled(true); - _latencies[4].add(new Long(System.currentTimeMillis()-start)); + _latencies[4].add(new Long(TimeUnit.NANOSECONDS.toMillis(System.nanoTime())-start)); return; } diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/session/FileSessionManagerTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/session/FileSessionManagerTest.java index 782a39779ca..fa9a3f85e88 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/session/FileSessionManagerTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/session/FileSessionManagerTest.java @@ -18,9 +18,6 @@ package org.eclipse.jetty.server.session; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; - import java.io.File; import java.io.FilenameFilter; import java.util.Collections; @@ -189,7 +186,7 @@ public class FileSessionManagerTest //not be removed by the startup process exp = System.currentTimeMillis() - 1000L; String name6 = Long.toString(exp)+"_foo_0.0.0.0_abcdefg"; - File f6 = new File(testDir, name5); + File f6 = new File(testDir, name6); if (f6.exists()) Assert.assertTrue(f6.delete()); f6.createNewFile(); @@ -237,7 +234,7 @@ public class FileSessionManagerTest long now = System.currentTimeMillis(); //create a file for session abc that expired 5sec ago - long exp = now -5000L; + long exp = now - 5000L; String name1 = Long.toString(exp)+"__0.0.0.0_abc"; File f1 = new File(testDir, name1); if (f1.exists()) @@ -285,7 +282,7 @@ public class FileSessionManagerTest File testDir = MavenTestingUtils.getTargetTestingDir("hashes"); FS.ensureEmpty(testDir); - String expectedFilename = (System.currentTimeMillis()+ 10000)+"__0.0.0.0_validFile123"; + String expectedFilename = (System.currentTimeMillis() + 10000)+"__0.0.0.0_validFile123"; Assert.assertTrue(new File(testDir, expectedFilename).createNewFile()); Assert.assertTrue("File should exist!", new File(testDir, expectedFilename).exists()); @@ -299,7 +296,7 @@ public class FileSessionManagerTest ds.setStoreDir(testDir); handler.start(); - Session session = handler.getSession("validFile123"); + handler.getSession("validFile123"); Assert.assertTrue("File shouldn't exist!", !new File(testDir,expectedFilename).exists()); } diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/session/SessionCookieTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/session/SessionCookieTest.java index b3221583928..f0c935b29b9 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/session/SessionCookieTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/session/SessionCookieTest.java @@ -28,6 +28,8 @@ import org.junit.Test; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import java.util.concurrent.TimeUnit; + /** * SessionCookieTest */ @@ -169,7 +171,7 @@ public class SessionCookieTest mgr.setSessionCache(store); mgr.setSessionIdManager(idMgr); - long now = System.currentTimeMillis(); + long now = TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); Session session = new Session(null, new SessionData("123", "_foo", "0.0.0.0", now, now, now, 30)); diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SSLSelectChannelConnectorLoadTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SSLSelectChannelConnectorLoadTest.java index 17dfb8c25d1..d2157cf8e4b 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SSLSelectChannelConnectorLoadTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SSLSelectChannelConnectorLoadTest.java @@ -124,7 +124,7 @@ public class SSLSelectChannelConnectorLoadTest tasks[i] = threadPool.submit(workers[i]); } - long start = System.currentTimeMillis(); + long start = TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); while (true) { Thread.sleep(1000); @@ -135,7 +135,7 @@ public class SSLSelectChannelConnectorLoadTest if (done) break; } - long end = System.currentTimeMillis(); + long end = TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); //System.err.println(); //System.err.println("Elapsed time: " + TimeUnit.MILLISECONDS.toSeconds(end - start) + "s"); @@ -170,7 +170,7 @@ public class SSLSelectChannelConnectorLoadTest tasks[i] = threadPool.submit(workers[i]); } - long start = System.currentTimeMillis(); + long start = TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); while (true) { Thread.sleep(1000); @@ -181,7 +181,7 @@ public class SSLSelectChannelConnectorLoadTest if (done) break; } - long end = System.currentTimeMillis(); + long end = TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); // System.err.println(); // System.err.println("Elapsed time: " + TimeUnit.MILLISECONDS.toSeconds(end - start) + "s"); diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SelectChannelServerSslTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SelectChannelServerSslTest.java index 7802d2517ab..d054024340f 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SelectChannelServerSslTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SelectChannelServerSslTest.java @@ -82,7 +82,11 @@ public class SelectChannelServerSslTest extends HttpServerTestBase @Override protected Socket newSocket(String host, int port) throws Exception { - return __sslContext.getSocketFactory().createSocket(host,port); + Socket socket = __sslContext.getSocketFactory().createSocket(host,port); + socket.setSoTimeout(10000); + socket.setTcpNoDelay(true); + socket.setSoLinger(false,0); + return socket; } @Override diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/server/handler/gzip/GzipDefaultTest.java b/jetty-servlets/src/test/java/org/eclipse/jetty/server/handler/gzip/GzipDefaultTest.java index cb55a92efff..c07ef77faa8 100644 --- a/jetty-servlets/src/test/java/org/eclipse/jetty/server/handler/gzip/GzipDefaultTest.java +++ b/jetty-servlets/src/test/java/org/eclipse/jetty/server/handler/gzip/GzipDefaultTest.java @@ -283,7 +283,7 @@ public class GzipDefaultTest try { tester.start(); - HttpTester.Response http = tester.assertIsResponseGzipCompressed("GET","file.txt",System.currentTimeMillis() - 4000); + HttpTester.Response http = tester.assertIsResponseGzipCompressed("GET","file.txt",TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) - 4000); Assert.assertEquals("Accept-Encoding, User-Agent",http.get("Vary")); } finally @@ -304,7 +304,7 @@ public class GzipDefaultTest try { tester.start(); - HttpTester.Response http = tester.assertIsResponseGzipCompressed("GET","test.svg",System.currentTimeMillis() - 4000); + HttpTester.Response http = tester.assertIsResponseGzipCompressed("GET","test.svg",TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) - 4000); Assert.assertEquals("Accept-Encoding, User-Agent",http.get("Vary")); } finally diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/DataRateLimitedServletTest.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/DataRateLimitedServletTest.java index 0c370cf0085..c2a3924b425 100644 --- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/DataRateLimitedServletTest.java +++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/DataRateLimitedServletTest.java @@ -28,6 +28,7 @@ import java.io.OutputStream; import java.nio.charset.StandardCharsets; import java.nio.file.Path; import java.util.Arrays; +import java.util.concurrent.TimeUnit; import org.eclipse.jetty.server.HttpConfiguration; import org.eclipse.jetty.server.LocalConnector; @@ -108,9 +109,9 @@ public class DataRateLimitedServletTest } } - long start=System.currentTimeMillis(); + long start=TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); String response = connector.getResponse("GET /context/stream/content.txt HTTP/1.0\r\n\r\n"); - long duration=System.currentTimeMillis()-start; + long duration=TimeUnit.NANOSECONDS.toMillis(System.nanoTime())-start; assertThat("Response",response,containsString("200 OK")); assertThat("Response Length",response.length(),greaterThan(1024*1024)); diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/DoSFilterTest.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/DoSFilterTest.java index db00a99ab78..542c6bd658b 100644 --- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/DoSFilterTest.java +++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/DoSFilterTest.java @@ -25,6 +25,7 @@ import static org.junit.Assert.assertThat; import java.net.InetSocketAddress; import java.util.Collections; import java.util.Enumeration; +import java.util.concurrent.TimeUnit; import javax.servlet.FilterConfig; import javax.servlet.ServletContext; @@ -170,7 +171,7 @@ public class DoSFilterTest extends AbstractDoSFilterTest for (int i = 0; i < 5; i++) { Thread.sleep(sleep); - if (rateTracker.isRateExceeded(System.currentTimeMillis())) + if (rateTracker.isRateExceeded(TimeUnit.NANOSECONDS.toMillis(System.nanoTime()))) exceeded = true; } return exceeded; diff --git a/jetty-util-ajax/src/test/java/org/eclipse/jetty/util/ajax/JSONPojoConvertorFactoryTest.java b/jetty-util-ajax/src/test/java/org/eclipse/jetty/util/ajax/JSONPojoConvertorFactoryTest.java index b3ee44dbdce..642033d90ac 100644 --- a/jetty-util-ajax/src/test/java/org/eclipse/jetty/util/ajax/JSONPojoConvertorFactoryTest.java +++ b/jetty-util-ajax/src/test/java/org/eclipse/jetty/util/ajax/JSONPojoConvertorFactoryTest.java @@ -22,6 +22,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import java.util.Map; +import java.util.concurrent.TimeUnit; import org.junit.Test; @@ -43,7 +44,7 @@ public class JSONPojoConvertorFactoryTest jsonIn.addConvertor(Enum.class, new JSONEnumConvertor()); Foo foo = new Foo(); - foo._name = "Foo @ " + System.currentTimeMillis(); + foo._name = "Foo @ " + TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); foo._int1 = 1; foo._int2 = new Integer(2); foo._long1 = 1000001l; @@ -89,7 +90,7 @@ public class JSONPojoConvertorFactoryTest jsonIn.addConvertor(Enum.class, new JSONEnumConvertor()); Foo foo = new Foo(); - foo._name = "Foo @ " + System.currentTimeMillis(); + foo._name = "Foo @ " + TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); foo._int1 = 1; foo._int2 = new Integer(2); foo._long1 = 1000001l; diff --git a/jetty-util-ajax/src/test/java/org/eclipse/jetty/util/ajax/JSONPojoConvertorTest.java b/jetty-util-ajax/src/test/java/org/eclipse/jetty/util/ajax/JSONPojoConvertorTest.java index caca688816f..2166dbcc601 100644 --- a/jetty-util-ajax/src/test/java/org/eclipse/jetty/util/ajax/JSONPojoConvertorTest.java +++ b/jetty-util-ajax/src/test/java/org/eclipse/jetty/util/ajax/JSONPojoConvertorTest.java @@ -23,6 +23,8 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import java.util.concurrent.TimeUnit; + import org.junit.Test; @@ -41,7 +43,7 @@ public class JSONPojoConvertorTest // json.addConvertor(Enum.class, new JSONEnumConvertor(true)); Foo foo = new Foo(); - foo._name = "Foo @ " + System.currentTimeMillis(); + foo._name = "Foo @ " + TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); foo._int1 = 1; foo._int2 = new Integer(2); foo._long1 = 1000001l; @@ -89,7 +91,7 @@ public class JSONPojoConvertorTest new String[]{"boolean2"})); Foo foo = new Foo(); - foo._name = "Foo @ " + System.currentTimeMillis(); + foo._name = "Foo @ " + TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); foo._int1 = 1; foo._int2 = new Integer(2); foo._long1 = 1000001l; diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/DateCacheTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/DateCacheTest.java index ea9d0f6ce49..d95acb63ef3 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/DateCacheTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/DateCacheTest.java @@ -48,7 +48,7 @@ public class DateCacheTest Thread.sleep(2000); - long now=System.currentTimeMillis(); + long now=TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); long end=now+3000; String f=dc.formatNow(now); String last=f; @@ -67,7 +67,7 @@ public class DateCacheTest misses++; TimeUnit.MILLISECONDS.sleep(100); - now=System.currentTimeMillis(); + now=TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); } Assert.assertThat(hits,Matchers.greaterThan(misses)); } diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/FutureCallbackTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/FutureCallbackTest.java index 7b10908ca0f..8ef08e185c3 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/FutureCallbackTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/FutureCallbackTest.java @@ -43,7 +43,7 @@ public class FutureCallbackTest { FutureCallback fcb= new FutureCallback(); - long start=System.currentTimeMillis(); + long start=TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); try { fcb.get(500,TimeUnit.MILLISECONDS); @@ -52,7 +52,7 @@ public class FutureCallbackTest catch(TimeoutException e) { } - Assert.assertThat(System.currentTimeMillis()-start,Matchers.greaterThan(50L)); + Assert.assertThat(TimeUnit.NANOSECONDS.toMillis(System.nanoTime())-start,Matchers.greaterThan(50L)); } @Test @@ -63,9 +63,9 @@ public class FutureCallbackTest Assert.assertTrue(fcb.isDone()); Assert.assertFalse(fcb.isCancelled()); - long start=System.currentTimeMillis(); + long start=TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); Assert.assertEquals(null,fcb.get()); - Assert.assertThat(System.currentTimeMillis()-start,Matchers.lessThan(500L)); + Assert.assertThat(TimeUnit.NANOSECONDS.toMillis(System.nanoTime())-start,Matchers.lessThan(500L)); } @Test @@ -84,10 +84,10 @@ public class FutureCallbackTest }).start(); latch.await(); - long start=System.currentTimeMillis(); + long start=TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); Assert.assertEquals(null,fcb.get(10000,TimeUnit.MILLISECONDS)); - Assert.assertThat(System.currentTimeMillis()-start,Matchers.greaterThan(10L)); - Assert.assertThat(System.currentTimeMillis()-start,Matchers.lessThan(1000L)); + Assert.assertThat(TimeUnit.NANOSECONDS.toMillis(System.nanoTime())-start,Matchers.greaterThan(10L)); + Assert.assertThat(TimeUnit.NANOSECONDS.toMillis(System.nanoTime())-start,Matchers.lessThan(1000L)); Assert.assertTrue(fcb.isDone()); Assert.assertFalse(fcb.isCancelled()); @@ -104,7 +104,7 @@ public class FutureCallbackTest Assert.assertTrue(fcb.isDone()); Assert.assertFalse(fcb.isCancelled()); - long start=System.currentTimeMillis(); + long start=TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); try { fcb.get(); @@ -114,7 +114,7 @@ public class FutureCallbackTest { Assert.assertEquals(ex,ee.getCause()); } - Assert.assertThat(System.currentTimeMillis()-start,Matchers.lessThan(100L)); + Assert.assertThat(TimeUnit.NANOSECONDS.toMillis(System.nanoTime())-start,Matchers.lessThan(100L)); } @Test @@ -134,7 +134,7 @@ public class FutureCallbackTest }).start(); latch.await(); - long start=System.currentTimeMillis(); + long start=TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); try { fcb.get(10000,TimeUnit.MILLISECONDS); @@ -144,8 +144,8 @@ public class FutureCallbackTest { Assert.assertEquals(ex,ee.getCause()); } - Assert.assertThat(System.currentTimeMillis()-start,Matchers.greaterThan(10L)); - Assert.assertThat(System.currentTimeMillis()-start,Matchers.lessThan(1000L)); + Assert.assertThat(TimeUnit.NANOSECONDS.toMillis(System.nanoTime())-start,Matchers.greaterThan(10L)); + Assert.assertThat(TimeUnit.NANOSECONDS.toMillis(System.nanoTime())-start,Matchers.lessThan(5000L)); Assert.assertTrue(fcb.isDone()); Assert.assertFalse(fcb.isCancelled()); @@ -161,7 +161,7 @@ public class FutureCallbackTest Assert.assertTrue(fcb.isDone()); Assert.assertTrue(fcb.isCancelled()); - long start=System.currentTimeMillis(); + long start=TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); try { fcb.get(); @@ -171,7 +171,7 @@ public class FutureCallbackTest { Assert.assertThat(e.getCause(),Matchers.instanceOf(CancellationException.class)); } - Assert.assertThat(System.currentTimeMillis()-start,Matchers.lessThan(100L)); + Assert.assertThat(TimeUnit.NANOSECONDS.toMillis(System.nanoTime())-start,Matchers.lessThan(100L)); } @Test @@ -190,7 +190,7 @@ public class FutureCallbackTest }).start(); latch.await(); - long start=System.currentTimeMillis(); + long start=TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); try { fcb.get(10000,TimeUnit.MILLISECONDS); @@ -200,8 +200,8 @@ public class FutureCallbackTest { Assert.assertThat(e.getCause(),Matchers.instanceOf(CancellationException.class)); } - Assert.assertThat(System.currentTimeMillis()-start,Matchers.greaterThan(10L)); - Assert.assertThat(System.currentTimeMillis()-start,Matchers.lessThan(1000L)); + Assert.assertThat(TimeUnit.NANOSECONDS.toMillis(System.nanoTime())-start,Matchers.greaterThan(10L)); + Assert.assertThat(TimeUnit.NANOSECONDS.toMillis(System.nanoTime())-start,Matchers.lessThan(1000L)); Assert.assertTrue(fcb.isDone()); Assert.assertTrue(fcb.isCancelled()); diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/MultiPartInputStreamTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/MultiPartInputStreamTest.java index 5e6d1398b35..87ee8352495 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/MultiPartInputStreamTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/MultiPartInputStreamTest.java @@ -36,6 +36,7 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; import java.util.Collection; +import java.util.concurrent.TimeUnit; import javax.servlet.MultipartConfigElement; import javax.servlet.ReadListener; @@ -57,7 +58,7 @@ public class MultiPartInputStreamTest private static final String FILENAME = "stuff.txt"; protected String _contentType = "multipart/form-data, boundary=AaB03x"; protected String _multi = createMultipartRequestString(FILENAME); - protected String _dirname = System.getProperty("java.io.tmpdir")+File.separator+"myfiles-"+System.currentTimeMillis(); + protected String _dirname = System.getProperty("java.io.tmpdir")+File.separator+"myfiles-"+TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); protected File _tmpDir = new File(_dirname); public MultiPartInputStreamTest () diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/ScannerTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/ScannerTest.java index cff1078645b..4918e433e19 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/ScannerTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/ScannerTest.java @@ -25,6 +25,7 @@ import java.io.OutputStream; import java.util.List; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.TimeUnit; import org.eclipse.jetty.toolchain.test.AdvancedRunner; import org.eclipse.jetty.toolchain.test.FS; @@ -239,7 +240,7 @@ public class ScannerTest // Create a new file by writing to it. - long now = System.currentTimeMillis(); + long now = TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); File file = new File(_directory,"st"); try (OutputStream out = new FileOutputStream(file,true)) { @@ -300,7 +301,7 @@ public class ScannerTest { File file = new File(_directory,string); if (file.exists()) - file.setLastModified(System.currentTimeMillis()); + file.setLastModified(TimeUnit.NANOSECONDS.toMillis(System.nanoTime())); else file.createNewFile(); } diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/SharedBlockingCallbackTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/SharedBlockingCallbackTest.java index f7384f87c1e..524ddd08277 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/SharedBlockingCallbackTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/SharedBlockingCallbackTest.java @@ -67,10 +67,10 @@ public class SharedBlockingCallbackTest try (Blocker blocker=sbcb.acquire()) { blocker.succeeded(); - start=System.currentTimeMillis(); + start=TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); blocker.block(); } - Assert.assertThat(System.currentTimeMillis()-start,Matchers.lessThan(500L)); + Assert.assertThat(TimeUnit.NANOSECONDS.toMillis(System.nanoTime())-start,Matchers.lessThan(500L)); Assert.assertEquals(0,notComplete.get()); } @@ -94,11 +94,11 @@ public class SharedBlockingCallbackTest }).start(); latch.await(); - start=System.currentTimeMillis(); + start=TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); blocker.block(); } - Assert.assertThat(System.currentTimeMillis()-start,Matchers.greaterThan(10L)); - Assert.assertThat(System.currentTimeMillis()-start,Matchers.lessThan(1000L)); + Assert.assertThat(TimeUnit.NANOSECONDS.toMillis(System.nanoTime())-start,Matchers.greaterThan(10L)); + Assert.assertThat(TimeUnit.NANOSECONDS.toMillis(System.nanoTime())-start,Matchers.lessThan(1000L)); Assert.assertEquals(0,notComplete.get()); } @@ -118,10 +118,10 @@ public class SharedBlockingCallbackTest } catch(IOException ee) { - start=System.currentTimeMillis(); + start=TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); Assert.assertEquals(ex,ee.getCause()); } - Assert.assertThat(System.currentTimeMillis()-start,Matchers.lessThan(100L)); + Assert.assertThat(TimeUnit.NANOSECONDS.toMillis(System.nanoTime())-start,Matchers.lessThan(100L)); Assert.assertEquals(0,notComplete.get()); } @@ -149,7 +149,7 @@ public class SharedBlockingCallbackTest }).start(); latch.await(); - start=System.currentTimeMillis(); + start=TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); blocker.block(); } Assert.fail(); @@ -158,8 +158,8 @@ public class SharedBlockingCallbackTest { Assert.assertEquals(ex,ee.getCause()); } - Assert.assertThat(System.currentTimeMillis()-start,Matchers.greaterThan(10L)); - Assert.assertThat(System.currentTimeMillis()-start,Matchers.lessThan(1000L)); + Assert.assertThat(TimeUnit.NANOSECONDS.toMillis(System.nanoTime())-start,Matchers.greaterThan(10L)); + Assert.assertThat(TimeUnit.NANOSECONDS.toMillis(System.nanoTime())-start,Matchers.lessThan(1000L)); Assert.assertEquals(0,notComplete.get()); } @@ -193,16 +193,16 @@ public class SharedBlockingCallbackTest latch.await(); - long start=System.currentTimeMillis(); + long start=TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); try (Blocker blocker=sbcb.acquire()) { - Assert.assertThat(System.currentTimeMillis()-start,Matchers.greaterThan(10L)); - Assert.assertThat(System.currentTimeMillis()-start,Matchers.lessThan(500L)); + Assert.assertThat(TimeUnit.NANOSECONDS.toMillis(System.nanoTime())-start,Matchers.greaterThan(10L)); + Assert.assertThat(TimeUnit.NANOSECONDS.toMillis(System.nanoTime())-start,Matchers.lessThan(500L)); blocker.succeeded(); blocker.block(); } - Assert.assertThat(System.currentTimeMillis()-start,Matchers.lessThan(600L)); + Assert.assertThat(TimeUnit.NANOSECONDS.toMillis(System.nanoTime())-start,Matchers.lessThan(600L)); Assert.assertEquals(0,notComplete.get()); } diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/StringUtilTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/StringUtilTest.java index c918f098d62..dfce5f4b588 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/StringUtilTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/StringUtilTest.java @@ -19,6 +19,7 @@ package org.eclipse.jetty.util; import java.nio.charset.StandardCharsets; +import java.util.concurrent.TimeUnit; import org.junit.Assert; import org.junit.Test; @@ -175,31 +176,31 @@ public class StringUtilTest Utf8StringBuffer strbuf = new Utf8StringBuffer(bytes.length); for (int i=0;i<10;i++) { - long s1=System.currentTimeMillis(); + long s1=TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); for (int j=1000000; j-->0;) { calc+=new String(bytes,0,bytes.length,StandardCharsets.UTF_8).hashCode(); } - long s2=System.currentTimeMillis(); + long s2=TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); for (int j=1000000; j-->0;) { calc+=StringUtil.toUTF8String(bytes,0,bytes.length).hashCode(); } - long s3=System.currentTimeMillis(); + long s3=TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); for (int j=1000000; j-->0;) { Utf8StringBuffer buffer = new Utf8StringBuffer(bytes.length); buffer.append(bytes,0,bytes.length); calc+=buffer.toString().hashCode(); } - long s4=System.currentTimeMillis(); + long s4=TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); for (int j=1000000; j-->0;) { strbuf.reset(); strbuf.append(bytes,0,bytes.length); calc+=strbuf.toString().hashCode(); } - long s5=System.currentTimeMillis(); + long s5=TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); System.err.println((s2-s1)+", "+(s3-s2)+", "+(s4-s3)+", "+(s5-s4)); } diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/component/LifeCycleListenerTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/component/LifeCycleListenerTest.java index 842eccb0585..0856cad8796 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/component/LifeCycleListenerTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/component/LifeCycleListenerTest.java @@ -22,6 +22,8 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import java.util.concurrent.TimeUnit; + import org.eclipse.jetty.util.log.StacklessLogging; import org.junit.Test; @@ -187,13 +189,13 @@ public class LifeCycleListenerTest public void lifeCycleStarted(LifeCycle event) { started = true; - startedTime = System.currentTimeMillis(); + startedTime = TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); } public void lifeCycleStarting(LifeCycle event) { starting = true; - startingTime = System.currentTimeMillis(); + startingTime = TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); // need to sleep to make sure the starting and started times are not // the same @@ -210,13 +212,13 @@ public class LifeCycleListenerTest public void lifeCycleStopped(LifeCycle event) { stopped = true; - stoppedTime = System.currentTimeMillis(); + stoppedTime = TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); } public void lifeCycleStopping(LifeCycle event) { stopping = true; - stoppingTime = System.currentTimeMillis(); + stoppingTime = TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); // need to sleep to make sure the stopping and stopped times are not // the same diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/thread/QueuedThreadPoolTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/thread/QueuedThreadPoolTest.java index fff2e15b7d9..adbee42813e 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/thread/QueuedThreadPoolTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/thread/QueuedThreadPoolTest.java @@ -220,9 +220,9 @@ public class QueuedThreadPoolTest } }); - long beforeStop = System.currentTimeMillis(); + long beforeStop = TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); tp.stop(); - long afterStop = System.currentTimeMillis(); + long afterStop = TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); assertTrue(tp.isStopped()); assertTrue(afterStop - beforeStop < 1000); } @@ -230,7 +230,7 @@ public class QueuedThreadPoolTest private void waitForIdle(QueuedThreadPool tp, int idle) { - long now=System.currentTimeMillis(); + long now=TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); long start=now; while (tp.getIdleThreads()!=idle && (now-start)<10000) { @@ -240,14 +240,14 @@ public class QueuedThreadPoolTest } catch(InterruptedException e) {} - now=System.currentTimeMillis(); + now=TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); } Assert.assertEquals(idle, tp.getIdleThreads()); } private void waitForThreads(QueuedThreadPool tp, int threads) { - long now=System.currentTimeMillis(); + long now=TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); long start=now; while (tp.getThreads()!=threads && (now-start)<10000) { @@ -257,7 +257,7 @@ public class QueuedThreadPoolTest } catch(InterruptedException e) {} - now=System.currentTimeMillis(); + now=TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); } assertEquals(threads,tp.getThreads()); } diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/thread/ReservedThreadExecutorTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/thread/ReservedThreadExecutorTest.java index 8bd3b2a29f6..f53267ea6fd 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/thread/ReservedThreadExecutorTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/thread/ReservedThreadExecutorTest.java @@ -30,6 +30,7 @@ import java.util.concurrent.Executor; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; +import org.hamcrest.Matchers; import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -58,6 +59,7 @@ public class ReservedThreadExecutorTest @Before public void before() throws Exception { + System.gc(); _executor = new TestExecutor(); _reservedExecutor = new ReservedThreadExecutor(_executor, SIZE); _reservedExecutor.start(); @@ -152,46 +154,30 @@ public class ReservedThreadExecutorTest _reservedExecutor.setIdleTimeout(IDLE,TimeUnit.MILLISECONDS); _reservedExecutor.start(); - // Reserved threads are lazily started. - assertThat(_executor._queue.size(), is(0)); - - assertThat(_reservedExecutor.tryExecute(NOOP),is(false)); + TimeUnit.MILLISECONDS.sleep(IDLE/2); + _reservedExecutor.tryExecute(NOOP); _executor.execute(); - waitForNoPending(); - - CountDownLatch latch = new CountDownLatch(1); - Runnable waitForLatch = ()->{try {latch.await();} catch(Exception e){}}; - assertThat(_reservedExecutor.tryExecute(waitForLatch),is(true)); + TimeUnit.MILLISECONDS.sleep(IDLE/2); + _reservedExecutor.tryExecute(NOOP); _executor.execute(); - - assertThat(_reservedExecutor.tryExecute(NOOP),is(false)); + TimeUnit.MILLISECONDS.sleep(IDLE/2); + _reservedExecutor.tryExecute(NOOP); _executor.execute(); - waitForNoPending(); - - latch.countDown(); - waitForAvailable(2); - - // Check that regular moderate activity keeps the pool a moderate size TimeUnit.MILLISECONDS.sleep(IDLE/2); - assertThat(_reservedExecutor.tryExecute(NOOP),is(true)); - waitForAvailable(2); + _reservedExecutor.tryExecute(NOOP); + _executor.execute(); TimeUnit.MILLISECONDS.sleep(IDLE/2); - assertThat(_reservedExecutor.tryExecute(NOOP),is(true)); + _reservedExecutor.tryExecute(NOOP); + _executor.execute(); + waitForAvailable(1); + int available = _reservedExecutor.getAvailable(); + + assertThat(available,Matchers.greaterThan(0)); TimeUnit.MILLISECONDS.sleep(IDLE/2); - assertThat(_reservedExecutor.tryExecute(NOOP),is(true)); - waitForAvailable(1); TimeUnit.MILLISECONDS.sleep(IDLE/2); - assertThat(_reservedExecutor.tryExecute(NOOP),is(true)); - waitForAvailable(1); TimeUnit.MILLISECONDS.sleep(IDLE/2); - assertThat(_reservedExecutor.tryExecute(NOOP),is(true)); - waitForAvailable(1); - - // check fully idle goes to zero - TimeUnit.MILLISECONDS.sleep(IDLE); - assertThat(_reservedExecutor.getAvailable(),is(0)); - + assertThat(_reservedExecutor.getAvailable(),Matchers.lessThan(available)); } protected void waitForNoPending() throws InterruptedException diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/thread/SchedulerTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/thread/SchedulerTest.java index 83cd4d219a1..7a74b9b42f5 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/thread/SchedulerTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/thread/SchedulerTest.java @@ -66,6 +66,7 @@ public class SchedulerTest @Before public void before() throws Exception { + System.gc(); _scheduler.start(); } diff --git a/tests/test-integration/src/test/java/org/eclipse/jetty/test/DigestPostTest.java b/tests/test-integration/src/test/java/org/eclipse/jetty/test/DigestPostTest.java index 4003f6d26b1..0ff935b5d6e 100644 --- a/tests/test-integration/src/test/java/org/eclipse/jetty/test/DigestPostTest.java +++ b/tests/test-integration/src/test/java/org/eclipse/jetty/test/DigestPostTest.java @@ -192,7 +192,7 @@ public class DigestPostTest int n=result.indexOf("nonce="); String nonce=result.substring(n+7,result.indexOf('"',n+7)); MessageDigest md = MessageDigest.getInstance("MD5"); - byte[] b= md.digest(String.valueOf(System.currentTimeMillis()).getBytes(org.eclipse.jetty.util.StringUtil.__ISO_8859_1)); + byte[] b= md.digest(String.valueOf(TimeUnit.NANOSECONDS.toMillis(System.nanoTime())).getBytes(org.eclipse.jetty.util.StringUtil.__ISO_8859_1)); String cnonce=encode(b); String digest="Digest username=\"testuser\" realm=\"test\" nonce=\""+nonce+"\" uri=\"/test/\" algorithm=MD5 response=\""+ newResponse("POST","/test/",cnonce,"testuser","test","password",nonce,"auth")+ @@ -244,7 +244,7 @@ public class DigestPostTest int n=result.indexOf("nonce="); String nonce=result.substring(n+7,result.indexOf('"',n+7)); MessageDigest md = MessageDigest.getInstance("MD5"); - byte[] b= md.digest(String.valueOf(System.currentTimeMillis()).getBytes(StringUtil.__ISO_8859_1)); + byte[] b= md.digest(String.valueOf(TimeUnit.NANOSECONDS.toMillis(System.nanoTime())).getBytes(StringUtil.__ISO_8859_1)); String cnonce=encode(b); String digest="Digest username=\"testuser\" realm=\"test\" nonce=\""+nonce+"\" uri=\"/test/\" algorithm=MD5 response=\""+ newResponse("POST","/test/",cnonce,"testuser","test","password",nonce,"auth")+ diff --git a/tests/test-loginservice/src/test/java/org/eclipse/jetty/DataSourceLoginServiceTest.java b/tests/test-loginservice/src/test/java/org/eclipse/jetty/DataSourceLoginServiceTest.java index 31dabb43aa1..bb39993a75f 100644 --- a/tests/test-loginservice/src/test/java/org/eclipse/jetty/DataSourceLoginServiceTest.java +++ b/tests/test-loginservice/src/test/java/org/eclipse/jetty/DataSourceLoginServiceTest.java @@ -149,7 +149,7 @@ public class DataSourceLoginServiceTest stopClient(); - String newpwd = String.valueOf(System.currentTimeMillis()); + String newpwd = String.valueOf(TimeUnit.NANOSECONDS.toMillis(System.nanoTime())); changePassword("jetty", newpwd); diff --git a/tests/test-sessions/test-hazelcast-sessions/src/test/java/org/eclipse/jetty/hazelcast/session/ClusteredLastAccessTimeTest.java b/tests/test-sessions/test-hazelcast-sessions/src/test/java/org/eclipse/jetty/hazelcast/session/ClusteredLastAccessTimeTest.java index 4ae5d4b95fe..c0f672e3ea5 100644 --- a/tests/test-sessions/test-hazelcast-sessions/src/test/java/org/eclipse/jetty/hazelcast/session/ClusteredLastAccessTimeTest.java +++ b/tests/test-sessions/test-hazelcast-sessions/src/test/java/org/eclipse/jetty/hazelcast/session/ClusteredLastAccessTimeTest.java @@ -18,6 +18,8 @@ package org.eclipse.jetty.hazelcast.session; +import java.util.concurrent.TimeUnit; + import org.eclipse.jetty.server.session.AbstractClusteredLastAccessTimeTest; import org.eclipse.jetty.server.session.SessionDataStoreFactory; import org.junit.After; @@ -35,7 +37,7 @@ public class ClusteredLastAccessTimeTest public SessionDataStoreFactory createSessionDataStoreFactory() { factory = new HazelcastSessionDataStoreFactory(); - factory.setMapName( Long.toString( System.currentTimeMillis() ) ); + factory.setMapName( Long.toString( TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) ) ); return factory; } diff --git a/tests/test-sessions/test-hazelcast-sessions/src/test/java/org/eclipse/jetty/hazelcast/session/ClusteredOrphanedSessionTest.java b/tests/test-sessions/test-hazelcast-sessions/src/test/java/org/eclipse/jetty/hazelcast/session/ClusteredOrphanedSessionTest.java index bcdca5689a7..f7eb430e07a 100644 --- a/tests/test-sessions/test-hazelcast-sessions/src/test/java/org/eclipse/jetty/hazelcast/session/ClusteredOrphanedSessionTest.java +++ b/tests/test-sessions/test-hazelcast-sessions/src/test/java/org/eclipse/jetty/hazelcast/session/ClusteredOrphanedSessionTest.java @@ -19,6 +19,8 @@ package org.eclipse.jetty.hazelcast.session; +import java.util.concurrent.TimeUnit; + import org.eclipse.jetty.server.session.AbstractClusteredOrphanedSessionTest; import org.eclipse.jetty.server.session.SessionDataStoreFactory; import org.junit.After; @@ -39,7 +41,7 @@ public class ClusteredOrphanedSessionTest public SessionDataStoreFactory createSessionDataStoreFactory() { factory = new HazelcastSessionDataStoreFactory(); - factory.setMapName( Long.toString( System.currentTimeMillis() ) ); + factory.setMapName( Long.toString( TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) ) ); return factory; } diff --git a/tests/test-sessions/test-hazelcast-sessions/src/test/java/org/eclipse/jetty/hazelcast/session/ClusteredSessionMigrationTest.java b/tests/test-sessions/test-hazelcast-sessions/src/test/java/org/eclipse/jetty/hazelcast/session/ClusteredSessionMigrationTest.java index ad594633e03..7303228e950 100644 --- a/tests/test-sessions/test-hazelcast-sessions/src/test/java/org/eclipse/jetty/hazelcast/session/ClusteredSessionMigrationTest.java +++ b/tests/test-sessions/test-hazelcast-sessions/src/test/java/org/eclipse/jetty/hazelcast/session/ClusteredSessionMigrationTest.java @@ -19,6 +19,8 @@ package org.eclipse.jetty.hazelcast.session; +import java.util.concurrent.TimeUnit; + import org.eclipse.jetty.server.session.AbstractClusteredSessionMigrationTest; import org.eclipse.jetty.server.session.SessionDataStoreFactory; import org.junit.After; @@ -38,7 +40,7 @@ public class ClusteredSessionMigrationTest public SessionDataStoreFactory createSessionDataStoreFactory() { factory = new HazelcastSessionDataStoreFactory(); - factory.setMapName( Long.toString( System.currentTimeMillis() ) ); + factory.setMapName( Long.toString( TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) ) ); return factory; } diff --git a/tests/test-sessions/test-hazelcast-sessions/src/test/java/org/eclipse/jetty/hazelcast/session/ClusteredSessionScavengingTest.java b/tests/test-sessions/test-hazelcast-sessions/src/test/java/org/eclipse/jetty/hazelcast/session/ClusteredSessionScavengingTest.java index 40a725933ad..5a8079bd015 100644 --- a/tests/test-sessions/test-hazelcast-sessions/src/test/java/org/eclipse/jetty/hazelcast/session/ClusteredSessionScavengingTest.java +++ b/tests/test-sessions/test-hazelcast-sessions/src/test/java/org/eclipse/jetty/hazelcast/session/ClusteredSessionScavengingTest.java @@ -19,6 +19,8 @@ package org.eclipse.jetty.hazelcast.session; +import java.util.concurrent.TimeUnit; + import org.eclipse.jetty.server.session.AbstractClusteredSessionScavengingTest; import org.eclipse.jetty.server.session.SessionDataStoreFactory; import org.junit.After; @@ -39,7 +41,7 @@ public class ClusteredSessionScavengingTest public SessionDataStoreFactory createSessionDataStoreFactory() { factory = new HazelcastSessionDataStoreFactory(); - factory.setMapName( Long.toString( System.currentTimeMillis() ) ); + factory.setMapName( Long.toString( TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) ) ); return factory; } diff --git a/tests/test-sessions/test-hazelcast-sessions/src/test/java/org/eclipse/jetty/hazelcast/session/ModifyMaxInactiveIntervalTest.java b/tests/test-sessions/test-hazelcast-sessions/src/test/java/org/eclipse/jetty/hazelcast/session/ModifyMaxInactiveIntervalTest.java index 1dde727c417..17299dabd2b 100644 --- a/tests/test-sessions/test-hazelcast-sessions/src/test/java/org/eclipse/jetty/hazelcast/session/ModifyMaxInactiveIntervalTest.java +++ b/tests/test-sessions/test-hazelcast-sessions/src/test/java/org/eclipse/jetty/hazelcast/session/ModifyMaxInactiveIntervalTest.java @@ -19,6 +19,8 @@ package org.eclipse.jetty.hazelcast.session; +import java.util.concurrent.TimeUnit; + import org.eclipse.jetty.server.session.AbstractModifyMaxInactiveIntervalTest; import org.eclipse.jetty.server.session.SessionDataStoreFactory; import org.junit.After; @@ -39,7 +41,7 @@ public class ModifyMaxInactiveIntervalTest public SessionDataStoreFactory createSessionDataStoreFactory() { factory = new HazelcastSessionDataStoreFactory(); - factory.setMapName( Long.toString( System.currentTimeMillis() ) ); + factory.setMapName( Long.toString( TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) ) ); return factory; } diff --git a/tests/test-sessions/test-hazelcast-sessions/src/test/java/org/eclipse/jetty/hazelcast/session/NonClusteredSessionScavengingTest.java b/tests/test-sessions/test-hazelcast-sessions/src/test/java/org/eclipse/jetty/hazelcast/session/NonClusteredSessionScavengingTest.java index 1fbe3cd78dc..48feedd8641 100644 --- a/tests/test-sessions/test-hazelcast-sessions/src/test/java/org/eclipse/jetty/hazelcast/session/NonClusteredSessionScavengingTest.java +++ b/tests/test-sessions/test-hazelcast-sessions/src/test/java/org/eclipse/jetty/hazelcast/session/NonClusteredSessionScavengingTest.java @@ -25,6 +25,8 @@ import org.junit.After; import static org.junit.Assert.*; +import java.util.concurrent.TimeUnit; + /** * NonClusteredSessionScavengingTest */ @@ -67,7 +69,7 @@ public class NonClusteredSessionScavengingTest public SessionDataStoreFactory createSessionDataStoreFactory() { factory = new HazelcastSessionDataStoreFactory(); - factory.setMapName( Long.toString( System.currentTimeMillis() ) ); + factory.setMapName( Long.toString( TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) ) ); return factory; } diff --git a/tests/test-sessions/test-hazelcast-sessions/src/test/java/org/eclipse/jetty/hazelcast/session/SessionExpiryTest.java b/tests/test-sessions/test-hazelcast-sessions/src/test/java/org/eclipse/jetty/hazelcast/session/SessionExpiryTest.java index 387e6a5407f..25d68ec76d7 100644 --- a/tests/test-sessions/test-hazelcast-sessions/src/test/java/org/eclipse/jetty/hazelcast/session/SessionExpiryTest.java +++ b/tests/test-sessions/test-hazelcast-sessions/src/test/java/org/eclipse/jetty/hazelcast/session/SessionExpiryTest.java @@ -19,6 +19,8 @@ package org.eclipse.jetty.hazelcast.session; +import java.util.concurrent.TimeUnit; + import org.eclipse.jetty.server.session.AbstractSessionExpiryTest; import org.eclipse.jetty.server.session.SessionDataStoreFactory; import org.junit.After; @@ -37,7 +39,7 @@ public class SessionExpiryTest public SessionDataStoreFactory createSessionDataStoreFactory() { factory = new HazelcastSessionDataStoreFactory(); - factory.setMapName( Long.toString( System.currentTimeMillis() ) ); + factory.setMapName( Long.toString( TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) ) ); return factory; } diff --git a/tests/test-sessions/test-hazelcast-sessions/src/test/java/org/eclipse/jetty/hazelcast/session/SessionInvalidateCreateScavengeTest.java b/tests/test-sessions/test-hazelcast-sessions/src/test/java/org/eclipse/jetty/hazelcast/session/SessionInvalidateCreateScavengeTest.java index a80a3c26d3e..c95fe4b8729 100644 --- a/tests/test-sessions/test-hazelcast-sessions/src/test/java/org/eclipse/jetty/hazelcast/session/SessionInvalidateCreateScavengeTest.java +++ b/tests/test-sessions/test-hazelcast-sessions/src/test/java/org/eclipse/jetty/hazelcast/session/SessionInvalidateCreateScavengeTest.java @@ -19,6 +19,8 @@ package org.eclipse.jetty.hazelcast.session; +import java.util.concurrent.TimeUnit; + import org.eclipse.jetty.server.session.AbstractSessionInvalidateCreateScavengeTest; import org.eclipse.jetty.server.session.SessionDataStoreFactory; import org.junit.After; @@ -39,7 +41,7 @@ public class SessionInvalidateCreateScavengeTest public SessionDataStoreFactory createSessionDataStoreFactory() { factory = new HazelcastSessionDataStoreFactory(); - factory.setMapName( Long.toString( System.currentTimeMillis() ) ); + factory.setMapName( Long.toString( TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) ) ); return factory; } diff --git a/tests/test-sessions/test-hazelcast-sessions/src/test/java/org/eclipse/jetty/hazelcast/session/client/ClientLastAccessTimeTest.java b/tests/test-sessions/test-hazelcast-sessions/src/test/java/org/eclipse/jetty/hazelcast/session/client/ClientLastAccessTimeTest.java index 1e547e49eab..1abe697b973 100644 --- a/tests/test-sessions/test-hazelcast-sessions/src/test/java/org/eclipse/jetty/hazelcast/session/client/ClientLastAccessTimeTest.java +++ b/tests/test-sessions/test-hazelcast-sessions/src/test/java/org/eclipse/jetty/hazelcast/session/client/ClientLastAccessTimeTest.java @@ -22,6 +22,9 @@ import com.hazelcast.config.Config; import com.hazelcast.config.MapConfig; import com.hazelcast.core.Hazelcast; import com.hazelcast.core.HazelcastInstance; + +import java.util.concurrent.TimeUnit; + import org.eclipse.jetty.hazelcast.session.HazelcastSessionDataStoreFactory; import org.eclipse.jetty.server.session.AbstractClusteredLastAccessTimeTest; import org.eclipse.jetty.server.session.SessionDataStoreFactory; @@ -32,7 +35,7 @@ public class ClientLastAccessTimeTest extends AbstractClusteredLastAccessTimeTest { - private static final String MAP_NAME = Long.toString( System.currentTimeMillis() ); + private static final String MAP_NAME = Long.toString( TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) ); private HazelcastInstance hazelcastInstance; diff --git a/tests/test-sessions/test-hazelcast-sessions/src/test/java/org/eclipse/jetty/hazelcast/session/client/ClientModifyMaxInactiveIntervalTest.java b/tests/test-sessions/test-hazelcast-sessions/src/test/java/org/eclipse/jetty/hazelcast/session/client/ClientModifyMaxInactiveIntervalTest.java index 1781e14eee6..d438dc2f9e7 100644 --- a/tests/test-sessions/test-hazelcast-sessions/src/test/java/org/eclipse/jetty/hazelcast/session/client/ClientModifyMaxInactiveIntervalTest.java +++ b/tests/test-sessions/test-hazelcast-sessions/src/test/java/org/eclipse/jetty/hazelcast/session/client/ClientModifyMaxInactiveIntervalTest.java @@ -23,6 +23,9 @@ import com.hazelcast.config.Config; import com.hazelcast.config.MapConfig; import com.hazelcast.core.Hazelcast; import com.hazelcast.core.HazelcastInstance; + +import java.util.concurrent.TimeUnit; + import org.eclipse.jetty.hazelcast.session.HazelcastSessionDataStoreFactory; import org.eclipse.jetty.server.session.AbstractModifyMaxInactiveIntervalTest; import org.eclipse.jetty.server.session.SessionDataStoreFactory; @@ -36,7 +39,7 @@ public class ClientModifyMaxInactiveIntervalTest extends AbstractModifyMaxInactiveIntervalTest { - private static final String MAP_NAME = Long.toString( System.currentTimeMillis() ); + private static final String MAP_NAME = Long.toString( TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) ); private HazelcastInstance hazelcastInstance; diff --git a/tests/test-sessions/test-hazelcast-sessions/src/test/java/org/eclipse/jetty/hazelcast/session/client/ClientNonClusteredSessionScavengingTest.java b/tests/test-sessions/test-hazelcast-sessions/src/test/java/org/eclipse/jetty/hazelcast/session/client/ClientNonClusteredSessionScavengingTest.java index d4d9935feb7..4bf51699292 100644 --- a/tests/test-sessions/test-hazelcast-sessions/src/test/java/org/eclipse/jetty/hazelcast/session/client/ClientNonClusteredSessionScavengingTest.java +++ b/tests/test-sessions/test-hazelcast-sessions/src/test/java/org/eclipse/jetty/hazelcast/session/client/ClientNonClusteredSessionScavengingTest.java @@ -31,6 +31,8 @@ import org.junit.Before; import static org.junit.Assert.*; +import java.util.concurrent.TimeUnit; + public class ClientNonClusteredSessionScavengingTest extends AbstractNonClusteredSessionScavengingTest { @@ -60,7 +62,7 @@ public class ClientNonClusteredSessionScavengingTest fail( e.getMessage() ); } } - private static final String MAP_NAME = Long.toString( System.currentTimeMillis() ); + private static final String MAP_NAME = Long.toString( TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) ); private HazelcastInstance hazelcastInstance; diff --git a/tests/test-sessions/test-hazelcast-sessions/src/test/java/org/eclipse/jetty/hazelcast/session/client/ClientOrphanedSessionTest.java b/tests/test-sessions/test-hazelcast-sessions/src/test/java/org/eclipse/jetty/hazelcast/session/client/ClientOrphanedSessionTest.java index fca6559a356..5250dd68c9d 100644 --- a/tests/test-sessions/test-hazelcast-sessions/src/test/java/org/eclipse/jetty/hazelcast/session/client/ClientOrphanedSessionTest.java +++ b/tests/test-sessions/test-hazelcast-sessions/src/test/java/org/eclipse/jetty/hazelcast/session/client/ClientOrphanedSessionTest.java @@ -23,6 +23,9 @@ import com.hazelcast.config.Config; import com.hazelcast.config.MapConfig; import com.hazelcast.core.Hazelcast; import com.hazelcast.core.HazelcastInstance; + +import java.util.concurrent.TimeUnit; + import org.eclipse.jetty.hazelcast.session.HazelcastSessionDataStoreFactory; import org.eclipse.jetty.server.session.AbstractClusteredOrphanedSessionTest; import org.eclipse.jetty.server.session.SessionDataStoreFactory; @@ -33,7 +36,7 @@ public class ClientOrphanedSessionTest extends AbstractClusteredOrphanedSessionTest { - private static final String MAP_NAME = Long.toString( System.currentTimeMillis() ); + private static final String MAP_NAME = Long.toString( TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) ); private HazelcastInstance hazelcastInstance; diff --git a/tests/test-sessions/test-hazelcast-sessions/src/test/java/org/eclipse/jetty/hazelcast/session/client/ClientSessionExpiryTest.java b/tests/test-sessions/test-hazelcast-sessions/src/test/java/org/eclipse/jetty/hazelcast/session/client/ClientSessionExpiryTest.java index 4cff3cfbf71..160ce45a046 100644 --- a/tests/test-sessions/test-hazelcast-sessions/src/test/java/org/eclipse/jetty/hazelcast/session/client/ClientSessionExpiryTest.java +++ b/tests/test-sessions/test-hazelcast-sessions/src/test/java/org/eclipse/jetty/hazelcast/session/client/ClientSessionExpiryTest.java @@ -23,6 +23,9 @@ import com.hazelcast.config.Config; import com.hazelcast.config.MapConfig; import com.hazelcast.core.Hazelcast; import com.hazelcast.core.HazelcastInstance; + +import java.util.concurrent.TimeUnit; + import org.eclipse.jetty.hazelcast.session.HazelcastSessionDataStoreFactory; import org.eclipse.jetty.server.session.AbstractSessionExpiryTest; import org.eclipse.jetty.server.session.SessionDataStoreFactory; @@ -33,7 +36,7 @@ public class ClientSessionExpiryTest extends AbstractSessionExpiryTest { - private static final String MAP_NAME = Long.toString( System.currentTimeMillis() ); + private static final String MAP_NAME = Long.toString( TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) ); private HazelcastInstance hazelcastInstance; diff --git a/tests/test-sessions/test-hazelcast-sessions/src/test/java/org/eclipse/jetty/hazelcast/session/client/ClientSessionInvalidateCreateScavengeTest.java b/tests/test-sessions/test-hazelcast-sessions/src/test/java/org/eclipse/jetty/hazelcast/session/client/ClientSessionInvalidateCreateScavengeTest.java index c80773c93fe..371389498b5 100644 --- a/tests/test-sessions/test-hazelcast-sessions/src/test/java/org/eclipse/jetty/hazelcast/session/client/ClientSessionInvalidateCreateScavengeTest.java +++ b/tests/test-sessions/test-hazelcast-sessions/src/test/java/org/eclipse/jetty/hazelcast/session/client/ClientSessionInvalidateCreateScavengeTest.java @@ -23,6 +23,9 @@ import com.hazelcast.config.Config; import com.hazelcast.config.MapConfig; import com.hazelcast.core.Hazelcast; import com.hazelcast.core.HazelcastInstance; + +import java.util.concurrent.TimeUnit; + import org.eclipse.jetty.hazelcast.session.HazelcastSessionDataStoreFactory; import org.eclipse.jetty.server.session.AbstractSessionInvalidateCreateScavengeTest; import org.eclipse.jetty.server.session.SessionDataStoreFactory; @@ -32,7 +35,7 @@ import org.junit.Before; public class ClientSessionInvalidateCreateScavengeTest extends AbstractSessionInvalidateCreateScavengeTest { - private static final String MAP_NAME = Long.toString( System.currentTimeMillis() ); + private static final String MAP_NAME = Long.toString( TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) ); private HazelcastInstance hazelcastInstance; diff --git a/tests/test-sessions/test-hazelcast-sessions/src/test/java/org/eclipse/jetty/hazelcast/session/client/ClientSessionMigrationTest.java b/tests/test-sessions/test-hazelcast-sessions/src/test/java/org/eclipse/jetty/hazelcast/session/client/ClientSessionMigrationTest.java index 188f8ea2347..284a6a8d9ce 100644 --- a/tests/test-sessions/test-hazelcast-sessions/src/test/java/org/eclipse/jetty/hazelcast/session/client/ClientSessionMigrationTest.java +++ b/tests/test-sessions/test-hazelcast-sessions/src/test/java/org/eclipse/jetty/hazelcast/session/client/ClientSessionMigrationTest.java @@ -23,6 +23,9 @@ import com.hazelcast.config.Config; import com.hazelcast.config.MapConfig; import com.hazelcast.core.Hazelcast; import com.hazelcast.core.HazelcastInstance; + +import java.util.concurrent.TimeUnit; + import org.eclipse.jetty.hazelcast.session.HazelcastSessionDataStoreFactory; import org.eclipse.jetty.server.session.AbstractClusteredSessionMigrationTest; import org.eclipse.jetty.server.session.SessionDataStoreFactory; @@ -35,7 +38,7 @@ import org.junit.Before; public class ClientSessionMigrationTest extends AbstractClusteredSessionMigrationTest { - private static final String MAP_NAME = Long.toString( System.currentTimeMillis() ); + private static final String MAP_NAME = Long.toString( TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) ); private HazelcastInstance hazelcastInstance; diff --git a/tests/test-sessions/test-hazelcast-sessions/src/test/java/org/eclipse/jetty/hazelcast/session/client/ClientSessionScavengingTest.java b/tests/test-sessions/test-hazelcast-sessions/src/test/java/org/eclipse/jetty/hazelcast/session/client/ClientSessionScavengingTest.java index d4e2bb47cb1..fe5959c9356 100644 --- a/tests/test-sessions/test-hazelcast-sessions/src/test/java/org/eclipse/jetty/hazelcast/session/client/ClientSessionScavengingTest.java +++ b/tests/test-sessions/test-hazelcast-sessions/src/test/java/org/eclipse/jetty/hazelcast/session/client/ClientSessionScavengingTest.java @@ -23,6 +23,9 @@ import com.hazelcast.config.Config; import com.hazelcast.config.MapConfig; import com.hazelcast.core.Hazelcast; import com.hazelcast.core.HazelcastInstance; + +import java.util.concurrent.TimeUnit; + import org.eclipse.jetty.hazelcast.session.HazelcastSessionDataStoreFactory; import org.eclipse.jetty.server.session.AbstractClusteredSessionScavengingTest; import org.eclipse.jetty.server.session.SessionDataStoreFactory; @@ -33,7 +36,7 @@ public class ClientSessionScavengingTest extends AbstractClusteredSessionScavengingTest { - private static final String MAP_NAME = Long.toString( System.currentTimeMillis() ); + private static final String MAP_NAME = Long.toString( TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) ); private HazelcastInstance hazelcastInstance; diff --git a/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/AttributeNameTest.java b/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/AttributeNameTest.java index c28f4fede76..b6c5746519e 100644 --- a/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/AttributeNameTest.java +++ b/tests/test-sessions/test-mongodb-sessions/src/test/java/org/eclipse/jetty/nosql/mongodb/AttributeNameTest.java @@ -24,6 +24,7 @@ import static org.junit.Assert.assertTrue; import java.io.IOException; import java.io.PrintWriter; +import java.util.concurrent.TimeUnit; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; @@ -145,7 +146,7 @@ public class AttributeNameTest if ("init".equals(action)) { Session session = (Session)request.getSession(true); - session.setAttribute("a.b.c",System.currentTimeMillis()); + session.setAttribute("a.b.c",TimeUnit.NANOSECONDS.toMillis(System.nanoTime())); sendResult(session,httpServletResponse.getWriter()); } diff --git a/tests/test-sessions/test-sessions-common/src/test/java/org/eclipse/jetty/server/session/SaveOptimizeTest.java b/tests/test-sessions/test-sessions-common/src/test/java/org/eclipse/jetty/server/session/SaveOptimizeTest.java index 4265204acd7..4e51832572f 100644 --- a/tests/test-sessions/test-sessions-common/src/test/java/org/eclipse/jetty/server/session/SaveOptimizeTest.java +++ b/tests/test-sessions/test-sessions-common/src/test/java/org/eclipse/jetty/server/session/SaveOptimizeTest.java @@ -26,6 +26,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import java.io.IOException; +import java.util.concurrent.TimeUnit; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; @@ -532,7 +533,7 @@ public class SaveOptimizeTest { HttpSession session = request.getSession(false); assertNotNull(session); - session.setAttribute("ttt", new Long(System.currentTimeMillis())); + session.setAttribute("ttt", new Long(TimeUnit.NANOSECONDS.toMillis(System.nanoTime()))); } else if ("max".equalsIgnoreCase(action)) {