mirror of
https://github.com/jetty/jetty.project.git
synced 2025-03-04 04:49:12 +00:00
Issue #2525 - Clean up SharedBlockingCallback.
Small cleanups and added test for thread interruption. Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
This commit is contained in:
parent
625d1f7726
commit
317a8a5c66
@ -245,7 +245,7 @@ public class HttpConfiguration
|
||||
* idle timeout; >0 for a timeout in ms applied to the total blocking operation.
|
||||
* @deprecated Replaced by {@link #getMinResponseDataRate()} and {@link #getMinRequestDataRate()}
|
||||
*/
|
||||
@ManagedAttribute("Total timeout in ms for blocking I/O operations. DEPRECATED!")
|
||||
@ManagedAttribute(value = "Total timeout in ms for blocking I/O operations. DEPRECATED!", readonly = true)
|
||||
@Deprecated
|
||||
public long getBlockingTimeout()
|
||||
{
|
||||
|
@ -48,7 +48,7 @@ import org.eclipse.jetty.util.log.Logger;
|
||||
*/
|
||||
public class SharedBlockingCallback
|
||||
{
|
||||
static final Logger LOG = Log.getLogger(SharedBlockingCallback.class);
|
||||
private static final Logger LOG = Log.getLogger(SharedBlockingCallback.class);
|
||||
|
||||
private static Throwable IDLE = new ConstantThrowable("IDLE");
|
||||
private static Throwable SUCCEEDED = new ConstantThrowable("SUCCEEDED");
|
||||
|
@ -18,13 +18,8 @@
|
||||
|
||||
package org.eclipse.jetty.util;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InterruptedIOException;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
@ -35,6 +30,13 @@ import org.hamcrest.Matchers;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.sameInstance;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
public class SharedBlockingCallbackTest
|
||||
{
|
||||
final AtomicInteger notComplete = new AtomicInteger();
|
||||
@ -52,14 +54,8 @@ public class SharedBlockingCallbackTest
|
||||
super.notComplete(blocker);
|
||||
notComplete.incrementAndGet();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
public SharedBlockingCallbackTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testDone() throws Exception
|
||||
{
|
||||
@ -211,7 +207,7 @@ public class SharedBlockingCallbackTest
|
||||
{
|
||||
try (Blocker blocker=sbcb.acquire())
|
||||
{
|
||||
SharedBlockingCallback.LOG.info("Blocker not complete "+blocker+" warning is expected...");
|
||||
// Immediately close() without calling succeeded().
|
||||
}
|
||||
|
||||
Assert.assertEquals(1,notComplete.get());
|
||||
@ -220,7 +216,6 @@ public class SharedBlockingCallbackTest
|
||||
@Test
|
||||
public void testBlockerTimeout() throws Exception
|
||||
{
|
||||
SharedBlockingCallback.LOG.info("Succeeded after ... warning is expected...");
|
||||
Blocker b0=null;
|
||||
try
|
||||
{
|
||||
@ -239,7 +234,6 @@ public class SharedBlockingCallbackTest
|
||||
}
|
||||
|
||||
Assert.assertEquals(0,notComplete.get());
|
||||
|
||||
|
||||
try (Blocker blocker=sbcb.acquire())
|
||||
{
|
||||
@ -248,4 +242,32 @@ public class SharedBlockingCallbackTest
|
||||
blocker.succeeded();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInterruptedException() throws Exception
|
||||
{
|
||||
Blocker blocker0;
|
||||
try (Blocker blocker = sbcb.acquire())
|
||||
{
|
||||
blocker0 = blocker;
|
||||
Thread.currentThread().interrupt();
|
||||
try
|
||||
{
|
||||
blocker.block();
|
||||
fail();
|
||||
}
|
||||
catch (InterruptedIOException ignored)
|
||||
{
|
||||
}
|
||||
}
|
||||
// Blocker.close() has been called by try-with-resources.
|
||||
// Simulate callback completion, must not throw.
|
||||
blocker0.succeeded();
|
||||
|
||||
try (Blocker blocker = sbcb.acquire())
|
||||
{
|
||||
assertThat(blocker, not(sameInstance(blocker0)));
|
||||
blocker.succeeded();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user