use of com.bumptech.glide.load.Key in project glide by bumptech.
the class ApplicationVersionSignatureTest method testKeyForSignatureIsTheSameAcrossCallsInTheSamePackage.
@Test
public void testKeyForSignatureIsTheSameAcrossCallsInTheSamePackage() throws NoSuchAlgorithmException, UnsupportedEncodingException {
Key first = ApplicationVersionSignature.obtain(RuntimeEnvironment.application);
Key second = ApplicationVersionSignature.obtain(RuntimeEnvironment.application);
KeyAssertions.assertSame(first, second);
}
use of com.bumptech.glide.load.Key in project glide by bumptech.
the class EngineKeyTest method testDiffersIfSignatureDiffers.
@Test
public void testDiffersIfSignatureDiffers() throws UnsupportedEncodingException, NoSuchAlgorithmException {
EngineKey first = harness.build();
Key signature = mock(Key.class);
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
MessageDigest digest = (MessageDigest) invocationOnMock.getArguments()[0];
digest.update("signature".getBytes("UTF-8"));
return null;
}
}).when(signature).updateDiskCacheKey(any(MessageDigest.class));
harness.signature = signature;
EngineKey second = harness.build();
KeyAssertions.assertDifferent(first, second, false);
}
use of com.bumptech.glide.load.Key in project Rocket by mozilla-tw.
the class ApplicationVersionSignature method obtain.
/**
* Returns the signature {@link com.bumptech.glide.load.Key} for version code of the Application
* of the given Context.
*/
public static Key obtain(Context context) {
String packageName = context.getPackageName();
Key result = PACKAGE_NAME_TO_KEY.get(packageName);
if (result == null) {
Key toAdd = obtainVersionSignature(context);
result = PACKAGE_NAME_TO_KEY.putIfAbsent(packageName, toAdd);
// There wasn't a previous mapping, so toAdd is now the Key.
if (result == null) {
result = toAdd;
}
}
return result;
}
use of com.bumptech.glide.load.Key in project glide by bumptech.
the class ActiveResourcesTest method queueIdle_withQueuedReferenceRetrievedFromGetAndNotCacheable_doesNotNotifyListener.
@Test
public void queueIdle_withQueuedReferenceRetrievedFromGetAndNotCacheable_doesNotNotifyListener() {
EngineResource<Object> engineResource = new EngineResource<>(resource, /*isCacheable=*/
false, /*isRecyclable=*/
true);
resources.activate(key, engineResource);
ResourceWeakReference weakRef = resources.activeEngineResources.get(key);
CountDownLatch latch = getLatchForClearedRef();
weakRef.enqueue();
resources.get(key);
waitForLatch(latch);
verify(listener, never()).onResourceReleased(any(Key.class), any(EngineResource.class));
}
use of com.bumptech.glide.load.Key in project glide by bumptech.
the class ActiveResourcesTest method queueIdle_afterResourceRemovedFromActive_doesNotCallListener.
@Test
public void queueIdle_afterResourceRemovedFromActive_doesNotCallListener() {
EngineResource<Object> engineResource = new EngineResource<>(resource, /*isCacheable=*/
true, /*isRecyclable=*/
true);
resources.activate(key, engineResource);
ResourceWeakReference weakRef = resources.activeEngineResources.get(key);
resources.deactivate(key);
enqueueAndWaitForRef(weakRef);
verify(listener, never()).onResourceReleased(any(Key.class), any(EngineResource.class));
}
Aggregations