Search in sources :

Example 1 with ResourceWeakReference

use of com.bumptech.glide.load.engine.ActiveResources.ResourceWeakReference 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 2 with ResourceWeakReference

use of com.bumptech.glide.load.engine.ActiveResources.ResourceWeakReference in project glide by bumptech.

the class ActiveResourcesTest method queueIdle_withQueuedReferenceRetrievedFromGet_notifiesListener.

@Test
public void queueIdle_withQueuedReferenceRetrievedFromGet_notifiesListener() {
    EngineResource<Object> engineResource = new EngineResource<>(resource, /*isCacheable=*/
    true, /*isRecyclable=*/
    true);
    resources.activate(key, engineResource);
    ResourceWeakReference weakRef = resources.activeEngineResources.get(key);
    resources.get(key);
    enqueueAndWaitForRef(weakRef);
    ArgumentCaptor<EngineResource<?>> captor = getEngineResourceCaptor();
    verify(listener).onResourceReleased(eq(key), captor.capture());
    assertThat(captor.getValue().getResource()).isEqualTo(resource);
}
Also used : ResourceWeakReference(com.bumptech.glide.load.engine.ActiveResources.ResourceWeakReference) Test(org.junit.Test)

Example 3 with ResourceWeakReference

use of com.bumptech.glide.load.engine.ActiveResources.ResourceWeakReference 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)

Example 4 with ResourceWeakReference

use of com.bumptech.glide.load.engine.ActiveResources.ResourceWeakReference in project glide by bumptech.

the class ActiveResourcesTest method queueIdle_withNotCacheableResourceInActive_doesNotCallListener.

@Test
public void queueIdle_withNotCacheableResourceInActive_doesNotCallListener() {
    EngineResource<Object> engineResource = new EngineResource<>(resource, /*isCacheable=*/
    false, /*isRecyclable=*/
    true);
    resources.activate(key, engineResource);
    ResourceWeakReference weakRef = resources.activeEngineResources.get(key);
    weakRef.enqueue();
    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)

Example 5 with ResourceWeakReference

use of com.bumptech.glide.load.engine.ActiveResources.ResourceWeakReference in project glide by bumptech.

the class ActiveResourcesTest method queueIdle_withNotCacheableResourceInActive_removesResourceFromActive.

@Test
public void queueIdle_withNotCacheableResourceInActive_removesResourceFromActive() {
    EngineResource<Object> engineResource = new EngineResource<>(resource, /*isCacheable=*/
    false, /*isRecyclable=*/
    true);
    resources.activate(key, engineResource);
    ResourceWeakReference weakRef = resources.activeEngineResources.get(key);
    enqueueAndWaitForRef(weakRef);
    assertThat(resources.get(key)).isNull();
}
Also used : ResourceWeakReference(com.bumptech.glide.load.engine.ActiveResources.ResourceWeakReference) Test(org.junit.Test)

Aggregations

ResourceWeakReference (com.bumptech.glide.load.engine.ActiveResources.ResourceWeakReference)13 Test (org.junit.Test)13 Key (com.bumptech.glide.load.Key)7 CountDownLatch (java.util.concurrent.CountDownLatch)4