reduce fragility of tests

Signed-off-by: Greg Wilkins <gregw@webtide.com>
This commit is contained in:
Greg Wilkins 2018-02-19 19:22:32 +11:00
parent 4147e3734e
commit ec51926622
51 changed files with 242 additions and 192 deletions

View File

@ -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()

View File

@ -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));

View File

@ -120,8 +120,8 @@ public class ThreadMonitorTest
public void spin()
{
long result=-1;
long end=System.currentTimeMillis()+DURATION+1000;
while (!done && System.currentTimeMillis()<end)
long end=TimeUnit.NANOSECONDS.toMillis(System.nanoTime())+DURATION+1000;
while (!done && TimeUnit.NANOSECONDS.toMillis(System.nanoTime())<end)
{
for (int i=0;i<1000000000;i++)
result^=i;

View File

@ -79,9 +79,9 @@ public class PropertyUserStoreTest
public void awaitCount(int expectedCount) throws InterruptedException
{
long timeout = System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(10);
long timeout = TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) + TimeUnit.SECONDS.toMillis(10);
while (userCount.get() != expectedCount && (System.currentTimeMillis() < timeout))
while (userCount.get() != expectedCount && (TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) < timeout))
{
TimeUnit.MILLISECONDS.sleep(100);
}

View File

@ -302,6 +302,8 @@ public class JDBCSessionDataStore extends AbstractSessionDataStore
public PreparedStatement getExpiredSessionsStatement (Connection connection, String canonicalContextPath, String vhost, long expiry)
throws SQLException
{
// TODO expiry should be a delay rather than an absolute time.
if (_dbAdaptor == null)
throw new IllegalStateException("No DB adaptor");
@ -324,6 +326,8 @@ public class JDBCSessionDataStore extends AbstractSessionDataStore
public PreparedStatement getMyExpiredSessionsStatement (Connection connection, SessionContext sessionContext, long expiry)
throws SQLException
{
// TODO expiry should be a delay rather than an absolute time.
if (_dbAdaptor == null)
throw new IllegalStateException("No DB adaptor");

View File

@ -28,6 +28,7 @@ import java.nio.charset.StandardCharsets;
import java.util.Random;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.TimeUnit;
import javax.servlet.AsyncContext;
import javax.servlet.AsyncEvent;
@ -133,7 +134,7 @@ public class AsyncStressTest
int period = _random.nextInt(290)+10;
String uri=__paths[p][0].replace("<PERIOD>",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"+

View File

@ -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()<end)
long end=TimeUnit.NANOSECONDS.toMillis(System.nanoTime())+MAX_IDLE_TIME+3000;
while (TimeUnit.NANOSECONDS.toMillis(System.nanoTime())<end)
{
os.write("THIS DATA SHOULD NOT BE PARSED!\n\n".getBytes("utf-8"));
os.flush();
@ -395,7 +395,7 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture
.getBytes("utf-8"));
os.flush();
long start = System.currentTimeMillis();
long start = TimeUnit.NANOSECONDS.toMillis(System.nanoTime());
try
{
Thread.sleep(250);
@ -420,7 +420,7 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture
{
e.printStackTrace();
}
long duration=System.currentTimeMillis() - start;
long duration=TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) - start;
Assert.assertThat(duration,Matchers.greaterThan(500L));
// read the response
@ -454,7 +454,7 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture
.getBytes("utf-8"));
os.flush();
long start = System.currentTimeMillis();
long start = TimeUnit.NANOSECONDS.toMillis(System.nanoTime());
try (StacklessLogging stackless = new StacklessLogging(HttpChannel.class))
{
Thread.sleep(300);
@ -478,7 +478,7 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture
catch(Exception e)
{
}
long duration=System.currentTimeMillis() - start;
long duration=TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) - start;
Assert.assertThat(duration,Matchers.greaterThan(500L));
try
@ -526,7 +526,7 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture
if (i%1028==0)
{
Thread.sleep(20);
// System.err.println("read "+System.currentTimeMillis());
// System.err.println("read "+TimeUnit.NANOSECONDS.toMillis(System.nanoTime()));
}
line=is.readLine();
Assert.assertThat(line,Matchers.notNullValue());
@ -562,7 +562,7 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture
while(line.length()!=0)
line=is.readLine();
long start=System.currentTimeMillis();
long start=TimeUnit.NANOSECONDS.toMillis(System.nanoTime());
try (StacklessLogging stackless = new StacklessLogging(HttpChannel.class,AbstractConnection.class))
{
for (int i=0;i<(128*1024);i++)
@ -570,7 +570,7 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture
if (i%1028==0)
{
Thread.sleep(20);
// System.err.println("read "+System.currentTimeMillis());
// System.err.println("read "+TimeUnit.NANOSECONDS.toMillis(System.nanoTime()));
}
line=is.readLine();
if (line==null)
@ -579,7 +579,7 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture
}
catch(Throwable e)
{}
long end=System.currentTimeMillis();
long end=TimeUnit.NANOSECONDS.toMillis(System.nanoTime());
long duration = end-start;
Assert.assertThat(duration,Matchers.lessThan(20L*128L));
}
@ -598,7 +598,7 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture
os.flush();
Thread.sleep(sleepTime);
long start = System.currentTimeMillis();
long start = TimeUnit.NANOSECONDS.toMillis(System.nanoTime());
try
{
String response = IO.toString(is);
@ -613,7 +613,7 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture
{
e.printStackTrace();
}
Assert.assertTrue(System.currentTimeMillis() - start < maximumTestRuntime);
Assert.assertTrue(TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) - start < maximumTestRuntime);
}
@ -627,7 +627,7 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture
Assert.assertFalse(client.isClosed());
Thread.sleep(sleepTime);
long start = System.currentTimeMillis();
long start = TimeUnit.NANOSECONDS.toMillis(System.nanoTime());
try
{
String response = IO.toString(is);
@ -642,7 +642,7 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture
{
e.printStackTrace();
}
Assert.assertTrue(System.currentTimeMillis() - start < maximumTestRuntime);
Assert.assertTrue(TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) - start < maximumTestRuntime);
}
@ -666,7 +666,7 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture
"\r\n").getBytes("utf-8"));
os.flush();
long start = System.currentTimeMillis();
long start = TimeUnit.NANOSECONDS.toMillis(System.nanoTime());
try
{
String response = IO.toString(is);
@ -681,7 +681,7 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture
{
e.printStackTrace();
}
int duration = (int)(System.currentTimeMillis() - start);
int duration = (int)(TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) - start);
Assert.assertThat(duration,Matchers.greaterThanOrEqualTo(MAX_IDLE_TIME));
Assert.assertThat(duration,Matchers.lessThan(maximumTestRuntime));
}
@ -707,7 +707,7 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture
"1234567890").getBytes("utf-8"));
os.flush();
long start = System.currentTimeMillis();
long start = TimeUnit.NANOSECONDS.toMillis(System.nanoTime());
try
{
String response = IO.toString(is);
@ -722,7 +722,7 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture
{
e.printStackTrace();
}
int duration = (int)(System.currentTimeMillis() - start);
int duration = (int)(TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) - start);
Assert.assertThat(duration+100,Matchers.greaterThanOrEqualTo(MAX_IDLE_TIME));
Assert.assertThat(duration-100,Matchers.lessThan(maximumTestRuntime));
}

View File

@ -25,6 +25,7 @@ import java.nio.channels.SelectableChannel;
import java.nio.channels.SelectionKey;
import java.nio.channels.SocketChannel;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.TimeUnit;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
@ -90,7 +91,7 @@ public class ExtendedServerTest extends HttpServerTestBase
@Override
public Runnable onSelected()
{
_lastSelected=System.currentTimeMillis();
_lastSelected=TimeUnit.NANOSECONDS.toMillis(System.nanoTime());
return super.onSelected();
}
@ -131,11 +132,11 @@ public class ExtendedServerTest extends HttpServerTestBase
{
OutputStream os = client.getOutputStream();
long start=System.currentTimeMillis();
long start=TimeUnit.NANOSECONDS.toMillis(System.nanoTime());
os.write("GET / HTTP/1.0\r\n".getBytes(StandardCharsets.ISO_8859_1));
os.flush();
Thread.sleep(200);
long end=System.currentTimeMillis();
long end=TimeUnit.NANOSECONDS.toMillis(System.nanoTime());
os.write("\r\n".getBytes(StandardCharsets.ISO_8859_1));
// Read the response.

View File

@ -722,9 +722,9 @@ public class HttpConnectionTest
"5;\r\n"+
"12345\r\n";
long start=System.currentTimeMillis();
long start=TimeUnit.NANOSECONDS.toMillis(System.nanoTime());
String response = connector.getResponse(requests, 2000, TimeUnit.MILLISECONDS);
if ((System.currentTimeMillis()-start)>=2000)
if ((TimeUnit.NANOSECONDS.toMillis(System.nanoTime())-start)>=2000)
Assert.fail();
offset = checkContains(response,offset,"HTTP/1.1 200");

View File

@ -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);
}
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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());
}

View File

@ -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));

View File

@ -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");

View File

@ -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

View File

@ -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

View File

@ -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));

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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));
}

View File

@ -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());

View File

@ -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 ()

View File

@ -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();
}

View File

@ -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());
}

View File

@ -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));
}

View File

@ -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

View File

@ -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());
}

View File

@ -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

View File

@ -66,6 +66,7 @@ public class SchedulerTest
@Before
public void before() throws Exception
{
System.gc();
_scheduler.start();
}

View File

@ -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")+

View File

@ -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);

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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());
}

View File

@ -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))
{