removed excess test code
This commit is contained in:
Greg Wilkins 2016-06-15 10:38:40 +10:00
parent bc87cf0ab4
commit f724d36646
1 changed files with 31 additions and 74 deletions

View File

@ -43,10 +43,8 @@ import org.junit.Test;
public class LocalAsyncContextTest public class LocalAsyncContextTest
{ {
private final Locker _completeLock = new Locker(); private final AtomicReference<Throwable> _completed0 = new AtomicReference<>();
private Throwable __completed; private final AtomicReference<Throwable> _completed1 = new AtomicReference<>();
private Throwable __dispatched;
private final AtomicReference<Throwable> __completed1 = new AtomicReference<>();
protected Server _server; protected Server _server;
protected SuspendHandler _handler; protected SuspendHandler _handler;
protected Connector _connector; protected Connector _connector;
@ -65,11 +63,8 @@ public class LocalAsyncContextTest
_server.setHandler(session); _server.setHandler(session);
_server.start(); _server.start();
try (Locker.Lock lock = _completeLock.lock()) _completed0.set(null);
{ _completed1.set(null);
__completed = null;
}
__completed1.set(null);
} }
protected Connector initConnector() protected Connector initConnector()
@ -95,14 +90,8 @@ public class LocalAsyncContextTest
response = process(null); response = process(null);
check(response, "TIMEOUT"); check(response, "TIMEOUT");
spinAssertEquals(1, () -> spinAssertEquals(1, () -> _completed0.get() == null ? 0 : 1);
{ spinAssertEquals(1, () -> _completed1.get() == null ? 0 : 1);
try (Locker.Lock lock = _completeLock.lock())
{
return __completed == null ? 0 : 1;
}
});
spinAssertEquals(1, () -> __completed1.get() == null ? 0 : 1);
} }
@Test @Test
@ -231,14 +220,8 @@ public class LocalAsyncContextTest
response = process(null); response = process(null);
check(response, "STARTASYNC", "DISPATCHED", "startasync", "STARTASYNC2", "DISPATCHED"); check(response, "STARTASYNC", "DISPATCHED", "startasync", "STARTASYNC2", "DISPATCHED");
spinAssertEquals(1, () -> spinAssertEquals(1, () -> _completed0.get() == null ? 0 : 1);
{ spinAssertEquals(0, () -> _completed1.get() == null ? 0 : 1);
try (Locker.Lock lock = _completeLock.lock())
{
return __completed == null ? 0 : 1;
}
});
spinAssertEquals(0, () -> __completed1.get() == null ? 0 : 1);
} }
protected void check(String response, String... content) protected void check(String response, String... content)
@ -490,56 +473,30 @@ public class LocalAsyncContextTest
public void onComplete(AsyncEvent event) throws IOException public void onComplete(AsyncEvent event) throws IOException
{ {
Throwable complete = new Throwable(); Throwable complete = new Throwable();
Throwable dispatched = HttpChannel.getDispatchedFrom(); if (!_completed0.compareAndSet(null, complete))
try (Locker.Lock lock = _completeLock.lock())
{ {
if (__completed == null) System.err.println("First onCompleted:");
{ _completed0.get().printStackTrace();
__completed = complete; System.err.println("First onCompleted:");
__dispatched = dispatched; complete.printStackTrace();
} _completed0.set(null);
else throw new IllegalStateException();
{
System.err.println("First onCompleted dispatched from:");
if (__dispatched != null)
__dispatched.printStackTrace();
System.err.println("First onCompleted:");
__completed.printStackTrace();
System.err.println("Second onCompleted dispatched from:");
if (dispatched != null)
dispatched.printStackTrace();
complete.printStackTrace();
throw new IllegalStateException();
}
} }
} }
@Override @Override
public void onError(AsyncEvent event) throws IOException public void onError(AsyncEvent event) throws IOException
{ {
Throwable complete = new Throwable(); Throwable complete = new Throwable();
Throwable dispatched = HttpChannel.getDispatchedFrom(); if (!_completed0.compareAndSet(null, complete))
try (Locker.Lock lock = _completeLock.lock()) {
{ System.err.println("First onCompleted:");
if (__completed == null) _completed0.get().printStackTrace();
{ System.err.println("First onCompleted:");
__completed = complete; complete.printStackTrace();
__dispatched = dispatched; _completed0.set(null);
} throw new IllegalStateException();
else }
{
System.err.println("First onCompleted dispatched from:");
if (__dispatched != null)
__dispatched.printStackTrace();
System.err.println("First onCompleted:");
__completed.printStackTrace();
System.err.println("Second onCompleted dispatched from:");
if (dispatched != null)
dispatched.printStackTrace();
complete.printStackTrace();
throw new IllegalStateException();
}
}
} }
@Override @Override
@ -563,11 +520,11 @@ public class LocalAsyncContextTest
public void onComplete(AsyncEvent event) throws IOException public void onComplete(AsyncEvent event) throws IOException
{ {
Throwable complete = new Throwable(); Throwable complete = new Throwable();
if (!__completed1.compareAndSet(null, complete)) if (!_completed1.compareAndSet(null, complete))
{ {
__completed1.get().printStackTrace(); _completed1.get().printStackTrace();
complete.printStackTrace(); complete.printStackTrace();
__completed1.set(null); _completed1.set(null);
throw new IllegalStateException(); throw new IllegalStateException();
} }
} }
@ -576,11 +533,11 @@ public class LocalAsyncContextTest
public void onError(AsyncEvent event) throws IOException public void onError(AsyncEvent event) throws IOException
{ {
Throwable complete = new Throwable(); Throwable complete = new Throwable();
if (!__completed1.compareAndSet(null, complete)) if (!_completed1.compareAndSet(null, complete))
{ {
__completed1.get().printStackTrace(); _completed1.get().printStackTrace();
complete.printStackTrace(); complete.printStackTrace();
__completed1.set(null); _completed1.set(null);
throw new IllegalStateException(); throw new IllegalStateException();
} }
} }