mirror of
https://github.com/zhigang1992/AndroidVideoCache.git
synced 2026-05-09 06:37:58 +08:00
notify CacheListener after cache is completed with original file
This commit is contained in:
@@ -134,6 +134,7 @@ class ProxyCache {
|
||||
notifyNewCacheDataAvailable(offset, sourceAvailable);
|
||||
}
|
||||
tryComplete();
|
||||
onSourceRead();
|
||||
} catch (Throwable e) {
|
||||
readSourceErrorsCount.incrementAndGet();
|
||||
onError(e);
|
||||
@@ -143,6 +144,12 @@ class ProxyCache {
|
||||
}
|
||||
}
|
||||
|
||||
private void onSourceRead() {
|
||||
// guaranteed notify listeners after source read and cache completed
|
||||
percentsAvailable = 100;
|
||||
onCachePercentsAvailableChanged(percentsAvailable);
|
||||
}
|
||||
|
||||
private void tryComplete() throws ProxyCacheException {
|
||||
synchronized (stopLock) {
|
||||
if (!isStopped() && cache.available() == source.length()) {
|
||||
|
||||
@@ -166,6 +166,19 @@ public class HttpProxyCacheTest {
|
||||
assertThat(response.data).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCacheListenerCalledAtTheEnd() throws Exception {
|
||||
File file = ProxyCacheTestUtils.newCacheFile();
|
||||
File tempFile = ProxyCacheTestUtils.getTempFile(file);
|
||||
HttpProxyCache proxyCache = new HttpProxyCache(new HttpUrlSource(HTTP_DATA_URL), new FileCache(file));
|
||||
CacheListener listener = Mockito.mock(CacheListener.class);
|
||||
proxyCache.registerCacheListener(listener);
|
||||
processRequest(proxyCache, "GET /" + HTTP_DATA_URL + " HTTP/1.1");
|
||||
|
||||
Mockito.verify(listener).onCacheAvailable(tempFile, HTTP_DATA_URL, 100); // must be called for temp file ...
|
||||
Mockito.verify(listener).onCacheAvailable(file, HTTP_DATA_URL, 100); // .. and for original file too
|
||||
}
|
||||
|
||||
@Test(expected = ProxyCacheException.class)
|
||||
public void testTouchSourceForAbsentSourceInfoAndCache() throws Exception {
|
||||
SourceInfoStorage sourceInfoStorage = SourceInfoStorageFactory.newEmptySourceInfoStorage();
|
||||
|
||||
Reference in New Issue
Block a user