Code cleanup: replaced anonymous inner classes with lambdas.
This commit is contained in:
parent
172bf27922
commit
b078c910a7
|
@ -20,7 +20,6 @@ package org.eclipse.jetty.client;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.nio.ByteBuffer;
|
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
@ -29,9 +28,6 @@ import javax.servlet.ServletException;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import org.eclipse.jetty.client.api.Response;
|
|
||||||
import org.eclipse.jetty.client.api.Result;
|
|
||||||
import org.eclipse.jetty.http.HttpField;
|
|
||||||
import org.eclipse.jetty.server.Request;
|
import org.eclipse.jetty.server.Request;
|
||||||
import org.eclipse.jetty.server.handler.AbstractHandler;
|
import org.eclipse.jetty.server.handler.AbstractHandler;
|
||||||
import org.eclipse.jetty.util.ssl.SslContextFactory;
|
import org.eclipse.jetty.util.ssl.SslContextFactory;
|
||||||
|
@ -53,22 +49,11 @@ public class HttpResponseAbortTest extends AbstractHttpClientServerTest
|
||||||
final CountDownLatch latch = new CountDownLatch(1);
|
final CountDownLatch latch = new CountDownLatch(1);
|
||||||
client.newRequest("localhost", connector.getLocalPort())
|
client.newRequest("localhost", connector.getLocalPort())
|
||||||
.scheme(scheme)
|
.scheme(scheme)
|
||||||
.onResponseBegin(new Response.BeginListener()
|
.onResponseBegin(response -> response.abort(new Exception()))
|
||||||
|
.send(result ->
|
||||||
{
|
{
|
||||||
@Override
|
Assert.assertTrue(result.isFailed());
|
||||||
public void onBegin(Response response)
|
latch.countDown();
|
||||||
{
|
|
||||||
response.abort(new Exception());
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.send(new Response.CompleteListener()
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public void onComplete(Result result)
|
|
||||||
{
|
|
||||||
Assert.assertTrue(result.isFailed());
|
|
||||||
latch.countDown();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
|
Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
|
||||||
}
|
}
|
||||||
|
@ -81,23 +66,15 @@ public class HttpResponseAbortTest extends AbstractHttpClientServerTest
|
||||||
final CountDownLatch latch = new CountDownLatch(1);
|
final CountDownLatch latch = new CountDownLatch(1);
|
||||||
client.newRequest("localhost", connector.getLocalPort())
|
client.newRequest("localhost", connector.getLocalPort())
|
||||||
.scheme(scheme)
|
.scheme(scheme)
|
||||||
.onResponseHeader(new Response.HeaderListener()
|
.onResponseHeader((response, field) ->
|
||||||
{
|
{
|
||||||
@Override
|
response.abort(new Exception());
|
||||||
public boolean onHeader(Response response, HttpField field)
|
return true;
|
||||||
{
|
|
||||||
response.abort(new Exception());
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.send(new Response.CompleteListener()
|
.send(result ->
|
||||||
{
|
{
|
||||||
@Override
|
Assert.assertTrue(result.isFailed());
|
||||||
public void onComplete(Result result)
|
latch.countDown();
|
||||||
{
|
|
||||||
Assert.assertTrue(result.isFailed());
|
|
||||||
latch.countDown();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
|
Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
|
||||||
}
|
}
|
||||||
|
@ -110,23 +87,11 @@ public class HttpResponseAbortTest extends AbstractHttpClientServerTest
|
||||||
final CountDownLatch latch = new CountDownLatch(1);
|
final CountDownLatch latch = new CountDownLatch(1);
|
||||||
client.newRequest("localhost", connector.getLocalPort())
|
client.newRequest("localhost", connector.getLocalPort())
|
||||||
.scheme(scheme)
|
.scheme(scheme)
|
||||||
.onResponseHeaders(new Response.HeadersListener()
|
.onResponseHeaders(response -> response.abort(new Exception()))
|
||||||
|
.send(result ->
|
||||||
{
|
{
|
||||||
@Override
|
Assert.assertTrue(result.isFailed());
|
||||||
public void onHeaders(Response response)
|
latch.countDown();
|
||||||
{
|
|
||||||
response.abort(new Exception());
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.send(new Response.CompleteListener()
|
|
||||||
{
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onComplete(Result result)
|
|
||||||
{
|
|
||||||
Assert.assertTrue(result.isFailed());
|
|
||||||
latch.countDown();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
|
Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
|
||||||
}
|
}
|
||||||
|
@ -158,22 +123,11 @@ public class HttpResponseAbortTest extends AbstractHttpClientServerTest
|
||||||
final CountDownLatch latch = new CountDownLatch(1);
|
final CountDownLatch latch = new CountDownLatch(1);
|
||||||
client.newRequest("localhost", connector.getLocalPort())
|
client.newRequest("localhost", connector.getLocalPort())
|
||||||
.scheme(scheme)
|
.scheme(scheme)
|
||||||
.onResponseContent(new Response.ContentListener()
|
.onResponseContent((response, content) -> response.abort(new Exception()))
|
||||||
|
.send(result ->
|
||||||
{
|
{
|
||||||
@Override
|
Assert.assertTrue(result.isFailed());
|
||||||
public void onContent(Response response, ByteBuffer content)
|
latch.countDown();
|
||||||
{
|
|
||||||
response.abort(new Exception());
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.send(new Response.CompleteListener()
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public void onComplete(Result result)
|
|
||||||
{
|
|
||||||
Assert.assertTrue(result.isFailed());
|
|
||||||
latch.countDown();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
|
Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
|
||||||
}
|
}
|
||||||
|
@ -207,48 +161,36 @@ public class HttpResponseAbortTest extends AbstractHttpClientServerTest
|
||||||
final CountDownLatch completeLatch = new CountDownLatch(1);
|
final CountDownLatch completeLatch = new CountDownLatch(1);
|
||||||
client.newRequest("localhost", connector.getLocalPort())
|
client.newRequest("localhost", connector.getLocalPort())
|
||||||
.scheme(scheme)
|
.scheme(scheme)
|
||||||
.onRequestSuccess(new org.eclipse.jetty.client.api.Request.SuccessListener()
|
.onRequestSuccess(request ->
|
||||||
{
|
{
|
||||||
@Override
|
try
|
||||||
public void onSuccess(org.eclipse.jetty.client.api.Request request)
|
|
||||||
{
|
{
|
||||||
try
|
abortLatch.await(5, TimeUnit.SECONDS);
|
||||||
{
|
}
|
||||||
abortLatch.await(5, TimeUnit.SECONDS);
|
catch (InterruptedException x)
|
||||||
}
|
{
|
||||||
catch (InterruptedException x)
|
x.printStackTrace();
|
||||||
{
|
|
||||||
x.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.onResponseContent(new Response.ContentListener()
|
.onResponseContent((response, content) ->
|
||||||
{
|
{
|
||||||
@Override
|
try
|
||||||
public void onContent(Response response, ByteBuffer content)
|
|
||||||
{
|
{
|
||||||
try
|
response.abort(new Exception());
|
||||||
{
|
abortLatch.countDown();
|
||||||
response.abort(new Exception());
|
// Delay to let the request side to finish its processing.
|
||||||
abortLatch.countDown();
|
Thread.sleep(1000);
|
||||||
// Delay to let the request side to finish its processing.
|
}
|
||||||
Thread.sleep(1000);
|
catch (InterruptedException x)
|
||||||
}
|
{
|
||||||
catch (InterruptedException x)
|
x.printStackTrace();
|
||||||
{
|
|
||||||
x.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.send(new Response.CompleteListener()
|
.send(result ->
|
||||||
{
|
{
|
||||||
@Override
|
completes.incrementAndGet();
|
||||||
public void onComplete(Result result)
|
Assert.assertTrue(result.isFailed());
|
||||||
{
|
completeLatch.countDown();
|
||||||
completes.incrementAndGet();
|
|
||||||
Assert.assertTrue(result.isFailed());
|
|
||||||
completeLatch.countDown();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
Assert.assertTrue(completeLatch.await(5, TimeUnit.SECONDS));
|
Assert.assertTrue(completeLatch.await(5, TimeUnit.SECONDS));
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue