Search in sources :

Example 1 with Key

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);
}
Also used : Key(com.bumptech.glide.load.Key) Test(org.junit.Test)

Example 2 with Key

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);
}
Also used : InvocationOnMock(org.mockito.invocation.InvocationOnMock) MessageDigest(java.security.MessageDigest) Key(com.bumptech.glide.load.Key) Test(org.junit.Test)

Example 3 with Key

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;
}
Also used : Key(com.bumptech.glide.load.Key)

Example 4 with Key

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));
}
Also used : ResourceWeakReference(com.bumptech.glide.load.engine.ActiveResources.ResourceWeakReference) CountDownLatch(java.util.concurrent.CountDownLatch) Key(com.bumptech.glide.load.Key) Test(org.junit.Test)

Example 5 with Key

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));
}
Also used : ResourceWeakReference(com.bumptech.glide.load.engine.ActiveResources.ResourceWeakReference) Key(com.bumptech.glide.load.Key) Test(org.junit.Test)

Aggregations

Key (com.bumptech.glide.load.Key)24 Test (org.junit.Test)13 ResourceWeakReference (com.bumptech.glide.load.engine.ActiveResources.ResourceWeakReference)7 File (java.io.File)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 Context (android.content.Context)2 NonNull (android.support.annotation.NonNull)2 DataFetcher (com.bumptech.glide.load.data.DataFetcher)2 ArrayList (java.util.ArrayList)2 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)1 Bitmap (android.graphics.Bitmap)1 VisibleForTesting (android.support.annotation.VisibleForTesting)1 EncodeStrategy (com.bumptech.glide.load.EncodeStrategy)1 Resource (com.bumptech.glide.load.engine.Resource)1 ResourceRemovedListener (com.bumptech.glide.load.engine.cache.MemoryCache.ResourceRemovedListener)1 MediaStoreSignature (com.bumptech.glide.signature.MediaStoreSignature)1 Util.anyResource (com.bumptech.glide.tests.Util.anyResource)1 Util.mockResource (com.bumptech.glide.tests.Util.mockResource)1 LruCache (com.bumptech.glide.util.LruCache)1 Synthetic (com.bumptech.glide.util.Synthetic)1