Merge remote-tracking branch 'origin/master'

This commit is contained in:
Simone Bordet 2011-11-21 23:47:03 +01:00
commit e1d05939b8
2 changed files with 36 additions and 32 deletions

View File

@ -338,9 +338,13 @@ public class SelectChannelEndPointTest
_manager.register(server);
int writes = 100000;
final byte[] bytes="HelloWorld".getBytes("UTF-8");
final CountDownLatch latch = new CountDownLatch(writes);
final InputStream in = new BufferedInputStream(client.getInputStream());
final long start = System.currentTimeMillis();
client.getOutputStream().write(bytes);
client.getOutputStream().flush();
new Thread()
{
public void run()
@ -350,29 +354,38 @@ public class SelectChannelEndPointTest
while (latch.getCount()>0)
{
// Verify echo server to client
for (char c : "HelloWorld".toCharArray())
for (byte b0 : bytes)
{
int b = in.read();
assertTrue(b>0);
assertEquals(c,(char)b);
assertEquals(0xff&b0,b);
}
latch.countDown();
Thread.yield();
}
}
catch(Exception e)
catch(ThreadDeath t)
{
throw t;
}
catch(Throwable e)
{
System.err.println("latch="+latch.getCount());
System.err.println("time="+(System.currentTimeMillis()-start));
e.printStackTrace();
}
}
}.start();
byte[] bytes="HelloWorld".getBytes("UTF-8");
// Write client to server
for (int i=0;i<writes;i++)
for (int i=1;i<writes;i++)
{
client.getOutputStream().write(bytes);
Thread.yield();
}
client.getOutputStream().flush();
assertTrue(latch.await(100,TimeUnit.SECONDS));
}
}

View File

@ -28,6 +28,8 @@ import java.util.Collection;
import java.util.Date;
import java.util.Enumeration;
import java.util.Locale;
import java.util.Timer;
import java.util.TimerTask;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
@ -64,6 +66,7 @@ public class Dump extends HttpServlet
private static final Logger LOG = Log.getLogger(Dump.class);
boolean fixed;
Timer _timer;
/* ------------------------------------------------------------ */
@Override
@ -77,6 +80,8 @@ public class Dump extends HttpServlet
fixed=true;
throw new UnavailableException("Unavailable test",Integer.parseInt(config.getInitParameter("unavailable")));
}
_timer=new Timer(true);
}
/* ------------------------------------------------------------ */
@ -168,40 +173,26 @@ public class Dump extends HttpServlet
request.setAttribute("RESUME",Boolean.TRUE);
final long resume=Long.parseLong(request.getParameter("resume"));
new Thread(new Runnable()
final Continuation continuation = ContinuationSupport.getContinuation(request);
_timer.schedule(new TimerTask()
{
@Override
public void run()
{
try
{
Thread.sleep(resume);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
Continuation continuation = ContinuationSupport.getContinuation(request);
continuation.resume();
}
}).start();
},resume);
}
if (request.getParameter("complete")!=null)
{
final long complete=Long.parseLong(request.getParameter("complete"));
new Thread(new Runnable()
_timer.schedule(new TimerTask()
{
@Override
public void run()
{
try
{
Thread.sleep(complete);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
try
{
response.setContentType("text/html");
@ -209,13 +200,12 @@ public class Dump extends HttpServlet
Continuation continuation = ContinuationSupport.getContinuation(request);
continuation.complete();
}
catch (IOException e)
catch(Exception e)
{
e.printStackTrace();
}
}
}).start();
},complete);
}
if (request.getParameter("suspend")!=null && request.getAttribute("SUSPEND")!=Boolean.TRUE)
@ -796,7 +786,7 @@ public class Dump extends HttpServlet
}
catch (Exception e)
{
getServletContext().log("dump", e);
getServletContext().log("dump "+e);
}
String lines= request.getParameter("lines");
@ -839,6 +829,7 @@ public class Dump extends HttpServlet
@Override
public synchronized void destroy()
{
_timer.cancel();
}
/* ------------------------------------------------------------ */