com.danikula.videocache.sourcestorage.SourceInfoStorage Java Examples

The following examples show how to use com.danikula.videocache.sourcestorage.SourceInfoStorage. 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 File: HttpProxyCacheTest.java    From AndroidVideoCache with 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 File: HttpProxyCacheTest.java    From AndriodVideoCache with 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 File: HttpUrlSourceTest.java    From AndriodVideoCache with 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 File: Config.java    From AndroidVideoCache with 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 #5
Source File: HttpUrlSource.java    From AndroidVideoCache with 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 #6
Source File: ProxyCacheTestUtils.java    From AndroidVideoCache with 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 #7
Source File: HttpProxyCacheTest.java    From AndroidVideoCache with 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 #8
Source File: HttpProxyCacheTest.java    From AndroidVideoCache with 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 #9
Source File: HttpProxyCacheTest.java    From AndroidVideoCache with 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 #10
Source File: HttpUrlSourceTest.java    From AndroidVideoCache with 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 #11
Source File: Config.java    From GSYVideoPlayer with 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 File: HttpUrlSource.java    From GSYVideoPlayer with 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 File: Config.java    From DKVideoPlayer with 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 File: HttpUrlSource.java    From DKVideoPlayer with 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 #15
Source File: Config.java    From AndriodVideoCache with 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 #16
Source File: HttpUrlSource.java    From AndriodVideoCache with 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 #17
Source File: ProxyCacheTestUtils.java    From AndriodVideoCache with 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 #18
Source File: HttpProxyCacheTest.java    From AndriodVideoCache with 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 #19
Source File: HttpProxyCacheTest.java    From AndriodVideoCache with 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 #20
Source File: HttpProxyCacheTest.java    From AndriodVideoCache with 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 #21
Source File: HttpUrlSource.java    From GSYVideoPlayer with Apache License 2.0 4 votes vote down vote up
public HttpUrlSource(String url, SourceInfoStorage sourceInfoStorage) {
    this(url, sourceInfoStorage, new EmptyHeadersInjector());
}
 
Example #22
Source File: HttpUrlSource.java    From DKVideoPlayer with Apache License 2.0 4 votes vote down vote up
public HttpUrlSource(String url, SourceInfoStorage sourceInfoStorage) {
    this(url, sourceInfoStorage, new EmptyHeadersInjector());
}
 
Example #23
Source File: HttpUrlSourceTest.java    From AndroidVideoCache with 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 #24
Source File: HttpUrlSource.java    From AndriodVideoCache with Apache License 2.0 4 votes vote down vote up
public HttpUrlSource(String url, SourceInfoStorage sourceInfoStorage) {
    this(url, sourceInfoStorage, new EmptyHeadersInjector());
}
 
Example #25
Source File: HttpUrlSource.java    From AndroidVideoCache with Apache License 2.0 4 votes vote down vote up
public HttpUrlSource(String url, SourceInfoStorage sourceInfoStorage) {
    this(url, sourceInfoStorage, new EmptyHeadersInjector());
}
 
Example #26
Source File: HttpUrlSourceTest.java    From AndriodVideoCache with 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");
}