Search in sources :

Example 1 with RequestFutureTask

use of com.tvd12.ezyhttp.client.concurrent.RequestFutureTask in project ezyhttp by youngmonkeys.

the class HttpClientProxy method execute.

public void execute(Request request, RequestCallback<ResponseEntity> callback) {
    EzyFuture future = new RequestFutureTask(callback);
    futures.addFuture(request, future);
    try {
        addRequest(request);
    } catch (Exception e) {
        futures.removeFuture(request);
        throw e;
    }
}
Also used : EzyFuture(com.tvd12.ezyfox.concurrent.EzyFuture) RequestFutureTask(com.tvd12.ezyhttp.client.concurrent.RequestFutureTask) EzyProcessor.processWithException(com.tvd12.ezyfox.util.EzyProcessor.processWithException) RequestQueueFullException(com.tvd12.ezyhttp.client.exception.RequestQueueFullException) IOException(java.io.IOException) ClientNotActiveException(com.tvd12.ezyhttp.client.exception.ClientNotActiveException)

Example 2 with RequestFutureTask

use of com.tvd12.ezyhttp.client.concurrent.RequestFutureTask in project ezyhttp by youngmonkeys.

the class RequestFutureTaskTest method setResultNotNull.

@Test
public void setResultNotNull() throws Exception {
    // given
    RequestFutureTask sut = new RequestFutureTask();
    Object result = new Object();
    // when
    sut.setResult(result);
    // then
    Asserts.assertEquals(result, sut.get());
}
Also used : RequestFutureTask(com.tvd12.ezyhttp.client.concurrent.RequestFutureTask) Test(org.testng.annotations.Test)

Example 3 with RequestFutureTask

use of com.tvd12.ezyhttp.client.concurrent.RequestFutureTask in project ezyhttp by youngmonkeys.

the class RequestFutureTaskTest method setExceptionNull.

@Test
public void setExceptionNull() {
    // given
    RequestFutureTask sut = new RequestFutureTask();
    // when
    Throwable e = Asserts.assertThrows(() -> sut.setException(null));
    // then
    Asserts.assertThat(e).isEqualsType(NullPointerException.class);
}
Also used : RequestFutureTask(com.tvd12.ezyhttp.client.concurrent.RequestFutureTask) Test(org.testng.annotations.Test)

Example 4 with RequestFutureTask

use of com.tvd12.ezyhttp.client.concurrent.RequestFutureTask in project ezyhttp by youngmonkeys.

the class RequestFutureTaskTest method setResultNull.

@Test
public void setResultNull() {
    // given
    RequestFutureTask sut = new RequestFutureTask();
    // when
    Throwable e = Asserts.assertThrows(() -> sut.setResult(null));
    // then
    Asserts.assertThat(e).isEqualsType(NullPointerException.class);
}
Also used : RequestFutureTask(com.tvd12.ezyhttp.client.concurrent.RequestFutureTask) Test(org.testng.annotations.Test)

Example 5 with RequestFutureTask

use of com.tvd12.ezyhttp.client.concurrent.RequestFutureTask in project ezyhttp by youngmonkeys.

the class RequestFutureTaskTest method setExceptionNotNull.

@Test
public void setExceptionNotNull() {
    // given
    RequestFutureTask sut = new RequestFutureTask();
    Exception exception = new Exception("just test");
    // when
    sut.setException(exception);
    // then
    Throwable e = Asserts.assertThrows(sut::get);
    Asserts.assertThat(e).isEqualsTo(exception);
}
Also used : RequestFutureTask(com.tvd12.ezyhttp.client.concurrent.RequestFutureTask) Test(org.testng.annotations.Test)

Aggregations

RequestFutureTask (com.tvd12.ezyhttp.client.concurrent.RequestFutureTask)5 Test (org.testng.annotations.Test)4 EzyFuture (com.tvd12.ezyfox.concurrent.EzyFuture)1 EzyProcessor.processWithException (com.tvd12.ezyfox.util.EzyProcessor.processWithException)1 ClientNotActiveException (com.tvd12.ezyhttp.client.exception.ClientNotActiveException)1 RequestQueueFullException (com.tvd12.ezyhttp.client.exception.RequestQueueFullException)1 IOException (java.io.IOException)1