Search in sources :

Example 1 with MultiCacheKey

use of com.facebook.cache.common.MultiCacheKey in project fresco by facebook.

the class SmallCacheIfRequestedDiskCachePolicyTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    List<CacheKey> keys = new ArrayList<>(1);
    keys.add(new SimpleCacheKey("http://dummy.uri"));
    mCacheKey = new MultiCacheKey(keys);
    when(mCacheKeyFactory.getEncodedCacheKey(mImageRequest, mCallerContext)).thenReturn(mCacheKey);
    when(mImageRequest.getCacheChoice()).thenReturn(ImageRequest.CacheChoice.DEFAULT);
    when(mImageRequest.isDiskCacheEnabled()).thenReturn(true);
    mIsCancelled = new AtomicBoolean(false);
    mSmallCacheIfRequestedDiskCachePolicy = new SmallCacheIfRequestedDiskCachePolicy(mDefaultBufferedDiskCache, mSmallImageBufferedDiskCache, mCacheKeyFactory);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MultiCacheKey(com.facebook.cache.common.MultiCacheKey) ArrayList(java.util.ArrayList) SimpleCacheKey(com.facebook.cache.common.SimpleCacheKey) CacheKey(com.facebook.cache.common.CacheKey) MultiCacheKey(com.facebook.cache.common.MultiCacheKey) SimpleCacheKey(com.facebook.cache.common.SimpleCacheKey) Before(org.junit.Before)

Example 2 with MultiCacheKey

use of com.facebook.cache.common.MultiCacheKey in project fresco by facebook.

the class BufferedDiskCacheTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    mCloseableReference = CloseableReference.of(mPooledByteBuffer);
    mEncodedImage = new EncodedImage(mCloseableReference);
    List<CacheKey> keys = new ArrayList<>();
    keys.add(new SimpleCacheKey("http://test.uri"));
    keys.add(new SimpleCacheKey("http://tyrone.uri"));
    keys.add(new SimpleCacheKey("http://ian.uri"));
    mCacheKey = new MultiCacheKey(keys);
    mIsCancelled = new AtomicBoolean(false);
    FakeClock fakeClock = new FakeClock();
    mReadPriorityExecutor = new TestExecutorService(fakeClock);
    mWritePriorityExecutor = new TestExecutorService(fakeClock);
    when(mBinaryResource.openStream()).thenReturn(mInputStream);
    when(mBinaryResource.size()).thenReturn(123L);
    when(mByteBufferFactory.newByteBuffer(same(mInputStream), eq(123))).thenReturn(mPooledByteBuffer);
    mockStatic(StagingArea.class);
    when(StagingArea.getInstance()).thenReturn(mStagingArea);
    mBufferedDiskCache = new BufferedDiskCache(mFileCache, mByteBufferFactory, mPooledByteStreams, mReadPriorityExecutor, mWritePriorityExecutor, mImageCacheStatsTracker);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) FakeClock(com.facebook.imagepipeline.testing.FakeClock) MultiCacheKey(com.facebook.cache.common.MultiCacheKey) TestExecutorService(com.facebook.imagepipeline.testing.TestExecutorService) ArrayList(java.util.ArrayList) SimpleCacheKey(com.facebook.cache.common.SimpleCacheKey) EncodedImage(com.facebook.imagepipeline.image.EncodedImage) CacheKey(com.facebook.cache.common.CacheKey) MultiCacheKey(com.facebook.cache.common.MultiCacheKey) SimpleCacheKey(com.facebook.cache.common.SimpleCacheKey) Before(org.junit.Before)

Example 3 with MultiCacheKey

use of com.facebook.cache.common.MultiCacheKey in project fresco by facebook.

the class DiskCacheWriteProducerTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    mDiskCacheWriteProducer = new DiskCacheWriteProducer(mInputProducer, mDiskCachePolicy);
    mForceSmallCacheProducer = new DiskCacheWriteProducer(mInputProducer, mDiskCachePolicy);
    List<CacheKey> keys = new ArrayList<>(1);
    keys.add(new SimpleCacheKey("http://dummy.uri"));
    mCacheKey = new MultiCacheKey(keys);
    mIntermediatePooledByteBuffer = mock(PooledByteBuffer.class);
    mFinalPooledByteBuffer = mock(PooledByteBuffer.class);
    mIntermediateImageReference = CloseableReference.of(mIntermediatePooledByteBuffer);
    mFinalImageReference = CloseableReference.of(mFinalPooledByteBuffer);
    mIntermediateEncodedImage = new EncodedImage(mIntermediateImageReference);
    mFinalEncodedImage = new EncodedImage(mFinalImageReference);
    mProducerContext = new SettableProducerContext(mImageRequest, mRequestId, mProducerListener, mCallerContext, ImageRequest.RequestLevel.FULL_FETCH, false, true, Priority.MEDIUM);
    mLowestLevelProducerContext = new SettableProducerContext(mImageRequest, mRequestId, mProducerListener, mCallerContext, ImageRequest.RequestLevel.DISK_CACHE, false, true, Priority.MEDIUM);
    when(mProducerListener.requiresExtraMap(mRequestId)).thenReturn(true);
    when(mCacheKeyFactory.getEncodedCacheKey(mImageRequest, mCallerContext)).thenReturn(mCacheKey);
    when(mImageRequest.getCacheChoice()).thenReturn(ImageRequest.CacheChoice.DEFAULT);
    when(mImageRequest.isDiskCacheEnabled()).thenReturn(true);
}
Also used : MultiCacheKey(com.facebook.cache.common.MultiCacheKey) ArrayList(java.util.ArrayList) PooledByteBuffer(com.facebook.common.memory.PooledByteBuffer) SimpleCacheKey(com.facebook.cache.common.SimpleCacheKey) EncodedImage(com.facebook.imagepipeline.image.EncodedImage) CacheKey(com.facebook.cache.common.CacheKey) MultiCacheKey(com.facebook.cache.common.MultiCacheKey) SimpleCacheKey(com.facebook.cache.common.SimpleCacheKey)

Example 4 with MultiCacheKey

use of com.facebook.cache.common.MultiCacheKey in project fresco by facebook.

the class DiskStorageCacheTest method testWithMultiCacheKeys.

@Test
public void testWithMultiCacheKeys() throws Exception {
    CacheKey insertKey1 = new SimpleCacheKey("foo");
    byte[] value1 = new byte[101];
    // just so it's not all zeros for the equality test below.
    value1[50] = 'a';
    mCache.insert(insertKey1, WriterCallbacks.from(value1));
    List<CacheKey> keys1 = new ArrayList<>(2);
    keys1.add(new SimpleCacheKey("bar"));
    keys1.add(new SimpleCacheKey("foo"));
    MultiCacheKey matchingMultiKey = new MultiCacheKey(keys1);
    assertArrayEquals(value1, getContents(mCache.getResource(matchingMultiKey)));
    List<CacheKey> keys2 = new ArrayList<>(2);
    keys2.add(new SimpleCacheKey("one"));
    keys2.add(new SimpleCacheKey("two"));
    MultiCacheKey insertKey2 = new MultiCacheKey(keys2);
    byte[] value2 = new byte[101];
    // just so it's not all zeros for the equality test below.
    value1[50] = 'b';
    mCache.insert(insertKey2, WriterCallbacks.from(value2));
    CacheKey matchingSimpleKey = new SimpleCacheKey("one");
    assertArrayEquals(value2, getContents(mCache.getResource(matchingSimpleKey)));
}
Also used : MultiCacheKey(com.facebook.cache.common.MultiCacheKey) ArrayList(java.util.ArrayList) SimpleCacheKey(com.facebook.cache.common.SimpleCacheKey) CacheKey(com.facebook.cache.common.CacheKey) MultiCacheKey(com.facebook.cache.common.MultiCacheKey) SimpleCacheKey(com.facebook.cache.common.SimpleCacheKey) PrepareOnlyThisForTest(org.powermock.core.classloader.annotations.PrepareOnlyThisForTest) Test(org.junit.Test)

Example 5 with MultiCacheKey

use of com.facebook.cache.common.MultiCacheKey in project fresco by facebook.

the class ImagePipelineTest method testEvictFromDiskCache.

@Test
public void testEvictFromDiskCache() {
    String uriString = "http://dummy/string";
    Uri uri = Uri.parse(uriString);
    CacheKey dummyCacheKey = mock(CacheKey.class);
    List<CacheKey> list = new ArrayList<>();
    list.add(dummyCacheKey);
    MultiCacheKey multiKey = new MultiCacheKey(list);
    when(mCacheKeyFactory.getEncodedCacheKey(any(ImageRequest.class), anyObject())).thenReturn(multiKey);
    mImagePipeline.evictFromDiskCache(uri);
    verify(mMainDiskStorageCache).remove(multiKey);
    verify(mSmallImageDiskStorageCache).remove(multiKey);
}
Also used : MultiCacheKey(com.facebook.cache.common.MultiCacheKey) ImageRequest(com.facebook.imagepipeline.request.ImageRequest) ArrayList(java.util.ArrayList) Uri(android.net.Uri) CacheKey(com.facebook.cache.common.CacheKey) MultiCacheKey(com.facebook.cache.common.MultiCacheKey) BitmapMemoryCacheKey(com.facebook.imagepipeline.cache.BitmapMemoryCacheKey) SimpleCacheKey(com.facebook.cache.common.SimpleCacheKey) Test(org.junit.Test)

Aggregations

CacheKey (com.facebook.cache.common.CacheKey)8 MultiCacheKey (com.facebook.cache.common.MultiCacheKey)8 SimpleCacheKey (com.facebook.cache.common.SimpleCacheKey)8 ArrayList (java.util.ArrayList)8 EncodedImage (com.facebook.imagepipeline.image.EncodedImage)5 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 PooledByteBuffer (com.facebook.common.memory.PooledByteBuffer)3 Before (org.junit.Before)3 Test (org.junit.Test)2 Uri (android.net.Uri)1 BitmapMemoryCacheKey (com.facebook.imagepipeline.cache.BitmapMemoryCacheKey)1 ImageRequest (com.facebook.imagepipeline.request.ImageRequest)1 FakeClock (com.facebook.imagepipeline.testing.FakeClock)1 TestExecutorService (com.facebook.imagepipeline.testing.TestExecutorService)1 PrepareOnlyThisForTest (org.powermock.core.classloader.annotations.PrepareOnlyThisForTest)1