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);
}
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);
}
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);
}
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)));
}
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);
}
Aggregations