Search in sources :

Example 1 with EzyFutureMap

use of com.tvd12.ezyfox.concurrent.EzyFutureMap in project ezyhttp by youngmonkeys.

the class ResourceDownloadManagerTest method drainButFutureNull.

@SuppressWarnings("rawtypes")
@Test
public void drainButFutureNull() throws Exception {
    // given
    info("start drainButFutureNull");
    ResourceDownloadManager sut = new ResourceDownloadManager(100, 1, 1024);
    EzyFutureMap futureMap = FieldUtil.getFieldValue(sut, "futureMap");
    InputStream inputStream = mock(InputStream.class);
    when(inputStream.read(any(byte[].class))).thenAnswer(it -> {
        Thread.sleep(200);
        return 0;
    });
    OutputStream outputStream = mock(OutputStream.class);
    // when
    sut.drainAsync(inputStream, outputStream, it -> {
    });
    futureMap.clear();
    // then
    Thread.sleep(300);
    sut.stop();
    info("finsihed drainButFutureNull");
}
Also used : EzyFutureMap(com.tvd12.ezyfox.concurrent.EzyFutureMap) ResourceDownloadManager(com.tvd12.ezyhttp.core.resources.ResourceDownloadManager) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 2 with EzyFutureMap

use of com.tvd12.ezyfox.concurrent.EzyFutureMap in project ezyhttp by youngmonkeys.

the class ResourceUploadManagerTest method drainOfferAgainGetMaxQueueCapacityAndFutureNullTest.

@Test
public void drainOfferAgainGetMaxQueueCapacityAndFutureNullTest() throws Exception {
    // given
    ResourceUploadManager sut = new ResourceUploadManager(1, 1, 1);
    InputStream inputStream = mock(InputStream.class);
    when(inputStream.read(any())).thenReturn(1);
    OutputStream outputStream = mock(OutputStream.class);
    EzyFutureMap<?> futureMap = FieldUtil.getFieldValue(sut, "futureMap");
    // when
    for (int i = 0; i < 1000; ++i) {
        try {
            sut.drainAsync(inputStream, outputStream, response -> {
            });
        } catch (Exception ignored) {
        }
        futureMap.clear();
    }
    // then
    sut.stop();
    sut.destroy();
    verify(inputStream, atLeastOnce()).read(any());
    verify(outputStream, atLeastOnce()).write(any(), anyInt(), anyInt());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ResourceUploadManager(com.tvd12.ezyhttp.core.resources.ResourceUploadManager) MaxUploadSizeException(com.tvd12.ezyhttp.core.exception.MaxUploadSizeException) IOException(java.io.IOException) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 3 with EzyFutureMap

use of com.tvd12.ezyfox.concurrent.EzyFutureMap in project ezyhttp by youngmonkeys.

the class ResourceUploadManagerTest method drainButFutureNull.

@SuppressWarnings("rawtypes")
@Test
public void drainButFutureNull() throws Exception {
    // given
    ResourceUploadManager sut = new ResourceUploadManager(100, 1, 1024);
    EzyFutureMap futureMap = FieldUtil.getFieldValue(sut, "futureMap");
    InputStream inputStream = mock(InputStream.class);
    when(inputStream.read(any(byte[].class))).thenAnswer(it -> {
        Thread.sleep(200);
        return 0;
    });
    OutputStream outputStream = mock(OutputStream.class);
    // when
    sut.drainAsync(inputStream, outputStream, it -> {
    });
    futureMap.clear();
    // then
    Thread.sleep(300);
    sut.stop();
}
Also used : EzyFutureMap(com.tvd12.ezyfox.concurrent.EzyFutureMap) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ResourceUploadManager(com.tvd12.ezyhttp.core.resources.ResourceUploadManager) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 4 with EzyFutureMap

use of com.tvd12.ezyfox.concurrent.EzyFutureMap in project ezyhttp by youngmonkeys.

the class HttpClientProxyTest method closeWithRemainTasks.

@Test
public void closeWithRemainTasks() {
    // given
    HttpClientProxy sut = new HttpClientProxy(1, 100, HttpClient.builder().build());
    EzyFutureMap<Request> futures = FieldUtil.getFieldValue(sut, "futures");
    Request request = mock(Request.class);
    futures.addFuture(request);
    sut.start();
    // when
    sut.close();
    // then
    verify(request, times(1)).getURL();
}
Also used : HelloRequest(com.tvd12.ezyhttp.client.test.request.HelloRequest) HttpClientProxy(com.tvd12.ezyhttp.client.HttpClientProxy) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest) BaseTest(com.tvd12.test.base.BaseTest)

Example 5 with EzyFutureMap

use of com.tvd12.ezyfox.concurrent.EzyFutureMap in project ezyhttp by youngmonkeys.

the class ResourceDownloadManagerTest method drainOfferAgainGetMaxQueueCapacityAndFutureNullTest.

@Test
public void drainOfferAgainGetMaxQueueCapacityAndFutureNullTest() throws Exception {
    // given
    ResourceDownloadManager sut = new ResourceDownloadManager(1, 1, 1);
    InputStream inputStream = mock(InputStream.class);
    when(inputStream.read(any())).thenReturn(1);
    OutputStream outputStream = mock(OutputStream.class);
    EzyFutureMap<?> futureMap = FieldUtil.getFieldValue(sut, "futureMap");
    // when
    for (int i = 0; i < 1000; ++i) {
        try {
            sut.drainAsync(inputStream, outputStream, response -> {
            });
        } catch (Exception ignored) {
        }
        futureMap.clear();
    }
    // then
    sut.stop();
    sut.destroy();
    verify(inputStream, atLeastOnce()).read(any());
    verify(outputStream, atLeastOnce()).write(any(), anyInt(), anyInt());
}
Also used : ResourceDownloadManager(com.tvd12.ezyhttp.core.resources.ResourceDownloadManager) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Aggregations

BaseTest (com.tvd12.test.base.BaseTest)5 Test (org.testng.annotations.Test)5 EzyFutureMap (com.tvd12.ezyfox.concurrent.EzyFutureMap)2 ResourceDownloadManager (com.tvd12.ezyhttp.core.resources.ResourceDownloadManager)2 ResourceUploadManager (com.tvd12.ezyhttp.core.resources.ResourceUploadManager)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 InputStream (java.io.InputStream)2 OutputStream (java.io.OutputStream)2 HttpClientProxy (com.tvd12.ezyhttp.client.HttpClientProxy)1 HelloRequest (com.tvd12.ezyhttp.client.test.request.HelloRequest)1 MaxUploadSizeException (com.tvd12.ezyhttp.core.exception.MaxUploadSizeException)1 IOException (java.io.IOException)1 BeforeTest (org.testng.annotations.BeforeTest)1