Java Code Examples for com.danikula.videocache.sourcestorage.SourceInfoStorage

The following examples show how to use com.danikula.videocache.sourcestorage.SourceInfoStorage. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: AndriodVideoCache   Source File: HttpProxyCacheTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testReuseSourceInfo() throws Exception {
    SourceInfoStorage sourceInfoStorage = SourceInfoStorageFactory.newSourceInfoStorage(RuntimeEnvironment.application);
    HttpUrlSource source = new HttpUrlSource(HTTP_DATA_URL, sourceInfoStorage);
    File cacheFile = newCacheFile();
    HttpProxyCache proxyCache = new HttpProxyCache(source, new FileCache(cacheFile));
    processRequest(proxyCache, "GET /" + HTTP_DATA_URL + " HTTP/1.1");

    HttpUrlSource notOpenableSource = ProxyCacheTestUtils.newNotOpenableHttpUrlSource(HTTP_DATA_URL, sourceInfoStorage);
    HttpProxyCache proxyCache2 = new HttpProxyCache(notOpenableSource, new FileCache(cacheFile));
    Response response = processRequest(proxyCache2, "GET /" + HTTP_DATA_URL + " HTTP/1.1");
    proxyCache.shutdown();

    assertThat(response.data).isEqualTo(loadAssetFile(ASSETS_DATA_NAME));
    assertThat(response.contentLength).isEqualTo(HTTP_DATA_SIZE);
    assertThat(response.contentType).isEqualTo("image/jpeg");
}
 
Example 2
Source Project: AndroidVideoCache   Source File: HttpProxyCacheTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testReuseSourceInfo() throws Exception {
    SourceInfoStorage sourceInfoStorage = SourceInfoStorageFactory.newSourceInfoStorage(RuntimeEnvironment.application);
    HttpUrlSource source = new HttpUrlSource(HTTP_DATA_URL, sourceInfoStorage);
    File cacheFile = newCacheFile();
    HttpProxyCache proxyCache = new HttpProxyCache(source, new FileCache(cacheFile));
    processRequest(proxyCache, "GET /" + HTTP_DATA_URL + " HTTP/1.1");

    HttpUrlSource notOpenableSource = ProxyCacheTestUtils.newNotOpenableHttpUrlSource(HTTP_DATA_URL, sourceInfoStorage);
    HttpProxyCache proxyCache2 = new HttpProxyCache(notOpenableSource, new FileCache(cacheFile));
    Response response = processRequest(proxyCache2, "GET /" + HTTP_DATA_URL + " HTTP/1.1");
    proxyCache.shutdown();

    assertThat(response.data).isEqualTo(loadAssetFile(ASSETS_DATA_NAME));
    assertThat(response.contentLength).isEqualTo(HTTP_DATA_SIZE);
    assertThat(response.contentType).isEqualTo("image/jpeg");
}
 
Example 3
Source Project: AndriodVideoCache   Source File: HttpUrlSourceTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test(expected = NullPointerException.class)
public void testHeaderInjectorNullNotAcceptable() throws Exception {
    HeaderInjector mockedHeaderInjector = Mockito.mock(HeaderInjector.class);
    when(mockedHeaderInjector.addHeaders(Mockito.anyString())).thenReturn(null);
    SourceInfoStorage emptySourceInfoStorage = SourceInfoStorageFactory.newEmptySourceInfoStorage();
    HttpUrlSource source = new HttpUrlSource(HTTP_DATA_URL_ONE_REDIRECT, emptySourceInfoStorage, mockedHeaderInjector);
    source.open(0);
    fail("source.open should throw NPE!");
}
 
Example 4
Source Project: AndriodVideoCache   Source File: HttpProxyCacheTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test(expected = ProxyCacheException.class)
public void testTouchSourceForAbsentSourceInfoAndCache() throws Exception {
    SourceInfoStorage sourceInfoStorage = SourceInfoStorageFactory.newEmptySourceInfoStorage();
    HttpUrlSource source = ProxyCacheTestUtils.newNotOpenableHttpUrlSource(HTTP_DATA_URL, sourceInfoStorage);
    HttpProxyCache proxyCache = new HttpProxyCache(source, new FileCache(newCacheFile()));
    processRequest(proxyCache, "GET /" + HTTP_DATA_URL + " HTTP/1.1");
    proxyCache.shutdown();
    fail("Angry source should throw error! There is no file and caches source info");
}
 
Example 5
Source Project: AndriodVideoCache   Source File: HttpProxyCacheTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test(expected = ProxyCacheException.class)
public void testTouchSourceForExistedSourceInfoAndAbsentCache() throws Exception {
    SourceInfoStorage sourceInfoStorage = SourceInfoStorageFactory.newSourceInfoStorage(RuntimeEnvironment.application);
    sourceInfoStorage.put(HTTP_DATA_URL, new SourceInfo(HTTP_DATA_URL, HTTP_DATA_SIZE, "image/jpg"));
    HttpUrlSource source = ProxyCacheTestUtils.newNotOpenableHttpUrlSource(HTTP_DATA_URL, sourceInfoStorage);
    HttpProxyCache proxyCache = new HttpProxyCache(source, new FileCache(newCacheFile()));
    processRequest(proxyCache, "GET /" + HTTP_DATA_URL + " HTTP/1.1");
    proxyCache.shutdown();
    fail("Angry source should throw error! There is no cache file");
}
 
Example 6
Source Project: AndriodVideoCache   Source File: HttpProxyCacheTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testTouchSourceForExistedSourceInfoAndCache() throws Exception {
    SourceInfoStorage sourceInfoStorage = SourceInfoStorageFactory.newSourceInfoStorage(RuntimeEnvironment.application);
    sourceInfoStorage.put(HTTP_DATA_URL, new SourceInfo(HTTP_DATA_URL, HTTP_DATA_SIZE, "cached/mime"));
    HttpUrlSource source = ProxyCacheTestUtils.newNotOpenableHttpUrlSource(HTTP_DATA_URL, sourceInfoStorage);
    File file = newCacheFile();
    IoUtils.saveToFile(loadAssetFile(ASSETS_DATA_NAME), file);
    HttpProxyCache proxyCache = new HttpProxyCache(source, new FileCache(file));
    Response response = processRequest(proxyCache, "GET /" + HTTP_DATA_URL + " HTTP/1.1");
    proxyCache.shutdown();
    assertThat(response.data).isEqualTo(loadAssetFile(ASSETS_DATA_NAME));
    assertThat(response.contentLength).isEqualTo(HTTP_DATA_SIZE);
    assertThat(response.contentType).isEqualTo("cached/mime");
}
 
Example 7
Source Project: AndriodVideoCache   Source File: ProxyCacheTestUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static HttpUrlSource newNotOpenableHttpUrlSource(String url, SourceInfoStorage sourceInfoStorage) throws ProxyCacheException {
    HttpUrlSource httpUrlSource = new HttpUrlSource(url, sourceInfoStorage);
    HttpUrlSource source = spy(httpUrlSource);
    doAnswer(new Answer() {
        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            System.out.print("Can't open!!!");
            throw new RuntimeException();
        }
    }).when(source).open(anyInt());
    return source;
}
 
Example 8
Source Project: AndriodVideoCache   Source File: HttpUrlSource.java    License: Apache License 2.0 5 votes vote down vote up
public HttpUrlSource(String url, SourceInfoStorage sourceInfoStorage, HeaderInjector headerInjector) {
    this.sourceInfoStorage = checkNotNull(sourceInfoStorage);
    this.headerInjector = checkNotNull(headerInjector);
    SourceInfo sourceInfo = sourceInfoStorage.get(url);
    this.sourceInfo = sourceInfo != null ? sourceInfo :
            new SourceInfo(url, Integer.MIN_VALUE, ProxyCacheUtils.getSupposablyMime(url));
}
 
Example 9
Source Project: AndriodVideoCache   Source File: Config.java    License: Apache License 2.0 5 votes vote down vote up
Config(File cacheRoot, FileNameGenerator fileNameGenerator, DiskUsage diskUsage, SourceInfoStorage sourceInfoStorage, HeaderInjector headerInjector) {
    this.cacheRoot = cacheRoot;
    this.fileNameGenerator = fileNameGenerator;
    this.diskUsage = diskUsage;
    this.sourceInfoStorage = sourceInfoStorage;
    this.headerInjector = headerInjector;
}
 
Example 10
Source Project: DKVideoPlayer   Source File: HttpUrlSource.java    License: Apache License 2.0 5 votes vote down vote up
public HttpUrlSource(String url, SourceInfoStorage sourceInfoStorage, HeaderInjector headerInjector) {
    this.sourceInfoStorage = checkNotNull(sourceInfoStorage);
    this.headerInjector = checkNotNull(headerInjector);
    SourceInfo sourceInfo = sourceInfoStorage.get(url);
    this.sourceInfo = sourceInfo != null ? sourceInfo :
            new SourceInfo(url, Integer.MIN_VALUE, ProxyCacheUtils.getSupposablyMime(url));
}
 
Example 11
Source Project: DKVideoPlayer   Source File: Config.java    License: Apache License 2.0 5 votes vote down vote up
Config(File cacheRoot, FileNameGenerator fileNameGenerator, DiskUsage diskUsage, SourceInfoStorage sourceInfoStorage, HeaderInjector headerInjector) {
    this.cacheRoot = cacheRoot;
    this.fileNameGenerator = fileNameGenerator;
    this.diskUsage = diskUsage;
    this.sourceInfoStorage = sourceInfoStorage;
    this.headerInjector = headerInjector;
}
 
Example 12
Source Project: GSYVideoPlayer   Source File: HttpUrlSource.java    License: Apache License 2.0 5 votes vote down vote up
public HttpUrlSource(String url, SourceInfoStorage sourceInfoStorage, HeaderInjector headerInjector) {
    this.sourceInfoStorage = checkNotNull(sourceInfoStorage);
    this.headerInjector = checkNotNull(headerInjector);
    SourceInfo sourceInfo = sourceInfoStorage.get(url);
    this.sourceInfo = sourceInfo != null ? sourceInfo :
            new SourceInfo(url, Integer.MIN_VALUE, ProxyCacheUtils.getSupposablyMime(url));
}
 
Example 13
Source Project: GSYVideoPlayer   Source File: Config.java    License: Apache License 2.0 5 votes vote down vote up
Config(File cacheRoot, FileNameGenerator fileNameGenerator, DiskUsage diskUsage, SourceInfoStorage sourceInfoStorage, HeaderInjector headerInjector) {
    this.cacheRoot = cacheRoot;
    this.fileNameGenerator = fileNameGenerator;
    this.diskUsage = diskUsage;
    this.sourceInfoStorage = sourceInfoStorage;
    this.headerInjector = headerInjector;
}
 
Example 14
Source Project: AndroidVideoCache   Source File: HttpUrlSourceTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test(expected = NullPointerException.class)
public void testHeaderInjectorNullNotAcceptable() throws Exception {
    HeaderInjector mockedHeaderInjector = Mockito.mock(HeaderInjector.class);
    when(mockedHeaderInjector.addHeaders(Mockito.anyString())).thenReturn(null);
    SourceInfoStorage emptySourceInfoStorage = SourceInfoStorageFactory.newEmptySourceInfoStorage();
    HttpUrlSource source = new HttpUrlSource(HTTP_DATA_URL_ONE_REDIRECT, emptySourceInfoStorage, mockedHeaderInjector);
    source.open(0);
    fail("source.open should throw NPE!");
}
 
Example 15
Source Project: AndroidVideoCache   Source File: HttpProxyCacheTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test(expected = ProxyCacheException.class)
public void testTouchSourceForAbsentSourceInfoAndCache() throws Exception {
    SourceInfoStorage sourceInfoStorage = SourceInfoStorageFactory.newEmptySourceInfoStorage();
    HttpUrlSource source = ProxyCacheTestUtils.newNotOpenableHttpUrlSource(HTTP_DATA_URL, sourceInfoStorage);
    HttpProxyCache proxyCache = new HttpProxyCache(source, new FileCache(newCacheFile()));
    processRequest(proxyCache, "GET /" + HTTP_DATA_URL + " HTTP/1.1");
    proxyCache.shutdown();
    fail("Angry source should throw error! There is no file and caches source info");
}
 
Example 16
Source Project: AndroidVideoCache   Source File: HttpProxyCacheTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test(expected = ProxyCacheException.class)
public void testTouchSourceForExistedSourceInfoAndAbsentCache() throws Exception {
    SourceInfoStorage sourceInfoStorage = SourceInfoStorageFactory.newSourceInfoStorage(RuntimeEnvironment.application);
    sourceInfoStorage.put(HTTP_DATA_URL, new SourceInfo(HTTP_DATA_URL, HTTP_DATA_SIZE, "image/jpg"));
    HttpUrlSource source = ProxyCacheTestUtils.newNotOpenableHttpUrlSource(HTTP_DATA_URL, sourceInfoStorage);
    HttpProxyCache proxyCache = new HttpProxyCache(source, new FileCache(newCacheFile()));
    processRequest(proxyCache, "GET /" + HTTP_DATA_URL + " HTTP/1.1");
    proxyCache.shutdown();
    fail("Angry source should throw error! There is no cache file");
}
 
Example 17
Source Project: AndroidVideoCache   Source File: HttpProxyCacheTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testTouchSourceForExistedSourceInfoAndCache() throws Exception {
    SourceInfoStorage sourceInfoStorage = SourceInfoStorageFactory.newSourceInfoStorage(RuntimeEnvironment.application);
    sourceInfoStorage.put(HTTP_DATA_URL, new SourceInfo(HTTP_DATA_URL, HTTP_DATA_SIZE, "cached/mime"));
    HttpUrlSource source = ProxyCacheTestUtils.newNotOpenableHttpUrlSource(HTTP_DATA_URL, sourceInfoStorage);
    File file = newCacheFile();
    IoUtils.saveToFile(loadAssetFile(ASSETS_DATA_NAME), file);
    HttpProxyCache proxyCache = new HttpProxyCache(source, new FileCache(file));
    Response response = processRequest(proxyCache, "GET /" + HTTP_DATA_URL + " HTTP/1.1");
    proxyCache.shutdown();
    assertThat(response.data).isEqualTo(loadAssetFile(ASSETS_DATA_NAME));
    assertThat(response.contentLength).isEqualTo(HTTP_DATA_SIZE);
    assertThat(response.contentType).isEqualTo("cached/mime");
}
 
Example 18
Source Project: AndroidVideoCache   Source File: ProxyCacheTestUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static HttpUrlSource newNotOpenableHttpUrlSource(String url, SourceInfoStorage sourceInfoStorage) throws ProxyCacheException {
    HttpUrlSource httpUrlSource = new HttpUrlSource(url, sourceInfoStorage);
    HttpUrlSource source = spy(httpUrlSource);
    doAnswer(new Answer() {
        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            System.out.print("Can't open!!!");
            throw new RuntimeException();
        }
    }).when(source).open(anyInt());
    return source;
}
 
Example 19
Source Project: AndroidVideoCache   Source File: HttpUrlSource.java    License: Apache License 2.0 5 votes vote down vote up
public HttpUrlSource(String url, SourceInfoStorage sourceInfoStorage, HeaderInjector headerInjector) {
    this.sourceInfoStorage = checkNotNull(sourceInfoStorage);
    this.headerInjector = checkNotNull(headerInjector);
    SourceInfo sourceInfo = sourceInfoStorage.get(url);
    this.sourceInfo = sourceInfo != null ? sourceInfo :
            new SourceInfo(url, Integer.MIN_VALUE, ProxyCacheUtils.getSupposablyMime(url));
}
 
Example 20
Source Project: AndroidVideoCache   Source File: Config.java    License: Apache License 2.0 5 votes vote down vote up
Config(File cacheRoot, FileNameGenerator fileNameGenerator, DiskUsage diskUsage, SourceInfoStorage sourceInfoStorage, HeaderInjector headerInjector) {
    this.cacheRoot = cacheRoot;
    this.fileNameGenerator = fileNameGenerator;
    this.diskUsage = diskUsage;
    this.sourceInfoStorage = sourceInfoStorage;
    this.headerInjector = headerInjector;
}
 
Example 21
Source Project: AndriodVideoCache   Source File: HttpUrlSourceTest.java    License: Apache License 2.0 4 votes vote down vote up
@Test(expected = RuntimeException.class)
public void testNotOpenableHttpUrlSourceOpen() throws Exception {
    SourceInfoStorage sourceInfoStorage = SourceInfoStorageFactory.newEmptySourceInfoStorage();
    ProxyCacheTestUtils.newNotOpenableHttpUrlSource("", sourceInfoStorage).open(Mockito.anyInt());
    fail("source.open() should throw exception");
}
 
Example 22
Source Project: AndriodVideoCache   Source File: HttpUrlSource.java    License: Apache License 2.0 4 votes vote down vote up
public HttpUrlSource(String url, SourceInfoStorage sourceInfoStorage) {
    this(url, sourceInfoStorage, new EmptyHeadersInjector());
}
 
Example 23
Source Project: DKVideoPlayer   Source File: HttpUrlSource.java    License: Apache License 2.0 4 votes vote down vote up
public HttpUrlSource(String url, SourceInfoStorage sourceInfoStorage) {
    this(url, sourceInfoStorage, new EmptyHeadersInjector());
}
 
Example 24
Source Project: GSYVideoPlayer   Source File: HttpUrlSource.java    License: Apache License 2.0 4 votes vote down vote up
public HttpUrlSource(String url, SourceInfoStorage sourceInfoStorage) {
    this(url, sourceInfoStorage, new EmptyHeadersInjector());
}
 
Example 25
Source Project: AndroidVideoCache   Source File: HttpUrlSourceTest.java    License: Apache License 2.0 4 votes vote down vote up
@Test(expected = RuntimeException.class)
public void testNotOpenableHttpUrlSourceOpen() throws Exception {
    SourceInfoStorage sourceInfoStorage = SourceInfoStorageFactory.newEmptySourceInfoStorage();
    ProxyCacheTestUtils.newNotOpenableHttpUrlSource("", sourceInfoStorage).open(Mockito.anyInt());
    fail("source.open() should throw exception");
}
 
Example 26
Source Project: AndroidVideoCache   Source File: HttpUrlSource.java    License: Apache License 2.0 4 votes vote down vote up
public HttpUrlSource(String url, SourceInfoStorage sourceInfoStorage) {
    this(url, sourceInfoStorage, new EmptyHeadersInjector());
}