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");
}
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());
}
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();
}
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();
}
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());
}
Aggregations