Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0f522f2

Browse filesBrowse files
committed
notify CacheListener after cache is completed with original file
1 parent 71c6301 commit 0f522f2
Copy full SHA for 0f522f2

2 files changed

+20Lines changed: 20 additions & 0 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎library/src/main/java/com/danikula/videocache/ProxyCache.java‎

Copy file name to clipboardExpand all lines: library/src/main/java/com/danikula/videocache/ProxyCache.java
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ private void readSource() {
134134
notifyNewCacheDataAvailable(offset, sourceAvailable);
135135
}
136136
tryComplete();
137+
onSourceRead();
137138
} catch (Throwable e) {
138139
readSourceErrorsCount.incrementAndGet();
139140
onError(e);
@@ -143,6 +144,12 @@ private void readSource() {
143144
}
144145
}
145146

147+
private void onSourceRead() {
148+
// guaranteed notify listeners after source read and cache completed
149+
percentsAvailable = 100;
150+
onCachePercentsAvailableChanged(percentsAvailable);
151+
}
152+
146153
private void tryComplete() throws ProxyCacheException {
147154
synchronized (stopLock) {
148155
if (!isStopped() && cache.available() == source.length()) {
Collapse file

‎test/src/test/java/com/danikula/videocache/HttpProxyCacheTest.java‎

Copy file name to clipboardExpand all lines: test/src/test/java/com/danikula/videocache/HttpProxyCacheTest.java
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,19 @@ public void testLoadEmptyFile() throws Exception {
166166
assertThat(response.data).isEmpty();
167167
}
168168

169+
@Test
170+
public void testCacheListenerCalledAtTheEnd() throws Exception {
171+
File file = ProxyCacheTestUtils.newCacheFile();
172+
File tempFile = ProxyCacheTestUtils.getTempFile(file);
173+
HttpProxyCache proxyCache = new HttpProxyCache(new HttpUrlSource(HTTP_DATA_URL), new FileCache(file));
174+
CacheListener listener = Mockito.mock(CacheListener.class);
175+
proxyCache.registerCacheListener(listener);
176+
processRequest(proxyCache, "GET /" + HTTP_DATA_URL + " HTTP/1.1");
177+
178+
Mockito.verify(listener).onCacheAvailable(tempFile, HTTP_DATA_URL, 100); // must be called for temp file ...
179+
Mockito.verify(listener).onCacheAvailable(file, HTTP_DATA_URL, 100); // .. and for original file too
180+
}
181+
169182
@Test(expected = ProxyCacheException.class)
170183
public void testTouchSourceForAbsentSourceInfoAndCache() throws Exception {
171184
SourceInfoStorage sourceInfoStorage = SourceInfoStorageFactory.newEmptySourceInfoStorage();

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.