use of com.tvd12.ezyfox.concurrent.callback.EzyResultCallback in project ezyhttp by youngmonkeys.
the class ResourceDownloadManager method drainAsync.
public void drainAsync(InputStream from, OutputStream to, EzyResultCallback<Boolean> callback) {
Entry entry = new Entry(from, to);
EzyCallableFutureTask future = new EzyCallableFutureTask(callback);
drain(entry, future);
}
use of com.tvd12.ezyfox.concurrent.callback.EzyResultCallback in project ezyhttp by youngmonkeys.
the class ResourceDownloadManagerTest method drainOfferAgainGetMaxQueueCapacityTest.
@Test
public void drainOfferAgainGetMaxQueueCapacityTest() 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);
// when
AtomicReference<Exception> exceptionRef = new AtomicReference<>();
for (int i = 0; i < 100; ++i) {
try {
sut.drainAsync(inputStream, outputStream, new EzyResultCallback<Boolean>() {
@Override
public void onResponse(Boolean response) {
}
@Override
public void onException(Exception e) {
exceptionRef.set(e);
}
});
} catch (Exception ignored) {
}
}
// then
while (exceptionRef.get() == null) {
EzyThreads.sleep(3);
}
Asserts.assertEqualsType(exceptionRef.get(), MaxResourceDownloadCapacity.class);
sut.stop();
sut.destroy();
verify(inputStream, atLeastOnce()).read(any());
verify(outputStream, atLeastOnce()).write(any(), anyInt(), anyInt());
}
use of com.tvd12.ezyfox.concurrent.callback.EzyResultCallback in project ezyhttp by youngmonkeys.
the class ResourceUploadManagerTest method drainOfferAgainGetMaxQueueCapacityTest.
@Test
public void drainOfferAgainGetMaxQueueCapacityTest() 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);
// when
AtomicReference<Exception> exceptionRef = new AtomicReference<>();
for (int i = 0; i < 100; ++i) {
try {
sut.drainAsync(inputStream, outputStream, new EzyResultCallback<Boolean>() {
@Override
public void onResponse(Boolean response) {
}
@Override
public void onException(Exception e) {
exceptionRef.set(e);
}
});
} catch (Exception ignored) {
}
}
// then
while (exceptionRef.get() == null) {
EzyThreads.sleep(3);
}
Asserts.assertEqualsType(exceptionRef.get(), MaxResourceUploadCapacity.class);
sut.stop();
sut.destroy();
verify(inputStream, atLeastOnce()).read(any());
verify(outputStream, atLeastOnce()).write(any(), anyInt(), anyInt());
}
Aggregations