use of java.util.concurrent.locks.Condition in project RoboZombie by sahan.
the class AsyncEndpointTest method testAsyncErrorCallbackError.
/**
* <p>Tests an erroneous asynchronous request where the implementation of the
* {@link AsyncHandler#onError(Exception)} callback throws an exception.</p>
*
* @since 1.3.0
*/
@Test
public final void testAsyncErrorCallbackError() throws InterruptedException {
Robolectric.getFakeHttpLayer().interceptHttpRequests(false);
String subpath = "/errorcallbackerror", body = "non-JSON-content";
stubFor(get(urlEqualTo(subpath)).willReturn(aResponse().withStatus(200).withBody(body)));
final Lock lock = new ReentrantLock();
final Condition condition = lock.newCondition();
asyncEndpoint.asyncErrorCallbackError(new AsyncHandler<User>() {
@Override
public void onSuccess(HttpResponse httpResponse, User user) {
}
@Override
public void onError(InvocationException error) {
try {
throw new IllegalStateException();
} finally {
lock.lock();
condition.signal();
lock.unlock();
}
}
});
lock.lock();
condition.await();
lock.unlock();
verify(getRequestedFor(urlEqualTo(subpath)));
//verify that the asynchronous request executor has survived the exception
successScenario();
}
use of java.util.concurrent.locks.Condition in project RoboZombie by sahan.
the class AsyncEndpointTest method testAsyncFailure.
/**
* <p>Tests asynchronous request execution with @{@link Async} and
* {@link AsyncHandler#onFailure(HttpResponse)}.</p>
*
* @since 1.3.0
*/
@Test
public final void testAsyncFailure() throws InterruptedException {
Robolectric.getFakeHttpLayer().interceptHttpRequests(false);
String subpath = "/asyncfailure", body = "hello";
stubFor(get(urlEqualTo(subpath)).willReturn(aResponse().withStatus(403).withBody(body)));
final Object[] content = new Object[1];
final Lock lock = new ReentrantLock();
final Condition condition = lock.newCondition();
asyncEndpoint.asyncFailure(new AsyncHandler<String>() {
@Override
public void onSuccess(HttpResponse httpResponse, String e) {
}
@Override
public void onFailure(HttpResponse httpResponse) {
lock.lock();
content[0] = httpResponse;
condition.signal();
lock.unlock();
}
});
lock.lock();
condition.await();
lock.unlock();
verify(getRequestedFor(urlEqualTo(subpath)));
assertTrue(content[0] != null);
}
use of java.util.concurrent.locks.Condition in project RoboZombie by sahan.
the class AsyncEndpointTest method testAsyncError.
/**
* <p>Tests asynchronous request execution with @{@link Async} and
* {@link AsyncHandler#onError(Exception)}.</p>
*
* @since 1.3.0
*/
@Test
public final void testAsyncError() throws InterruptedException {
Robolectric.getFakeHttpLayer().interceptHttpRequests(false);
String subpath = "/asyncerror", body = "non-JSON-content";
stubFor(get(urlEqualTo(subpath)).willReturn(aResponse().withStatus(200).withBody(body)));
final Object[] content = new Object[1];
final Lock lock = new ReentrantLock();
final Condition condition = lock.newCondition();
asyncEndpoint.asyncError(new AsyncHandler<User>() {
@Override
public void onSuccess(HttpResponse httpResponse, User user) {
}
@Override
public void onError(InvocationException error) {
lock.lock();
content[0] = error;
condition.signal();
lock.unlock();
}
});
lock.lock();
condition.await();
lock.unlock();
verify(getRequestedFor(urlEqualTo(subpath)));
assertTrue(content[0] != null);
assertTrue(content[0] instanceof InvocationException);
}
use of java.util.concurrent.locks.Condition in project intellij-community by JetBrains.
the class AwaitNotInLoopInspection method foo.
public void foo() {
Condition condition;
try {
lock.wait();
condition.await();
condition.awaitUninterruptibly();
condition.awaitNanos(300);
condition.awaitUntil(new Date());
condition.await(300, TimeUnit.MICROSECONDS);
} catch (InterruptedException e) {
}
}
use of java.util.concurrent.locks.Condition in project intellij-community by JetBrains.
the class ObjectNotifyInspection method foo.
public void foo() {
final Object bar = new Object();
bar.notify();
notify();
Condition condition = null;
condition.signal();
condition.notify();
condition.notifyAll();
}
Aggregations