Search in sources :

Example 6 with ResourceWeakReference

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

the class ActiveResourcesTest method queueIdle_withQueuedReferenceRetrievedFromGet_retentionDisabled_doesNotNotify.

@Test
public void queueIdle_withQueuedReferenceRetrievedFromGet_retentionDisabled_doesNotNotify() {
    resources = new ActiveResources(/*isActiveResourceRetentionAllowed=*/
    false);
    EngineResource<Object> engineResource = new EngineResource<>(resource, /*isCacheable=*/
    true, /*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 7 with ResourceWeakReference

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

the class ActiveResourcesTest method get_withQueuedReference_returnsResource.

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

Example 8 with ResourceWeakReference

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

the class ActiveResourcesTest method queueIdle_withQueuedReferenceDeactivated_doesNotNotifyListener.

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

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

the class ActiveResourcesTest method queueIdle_afterReferenceQueuedThenReactivated_doesNotNotifyListener.

@Test
public void queueIdle_afterReferenceQueuedThenReactivated_doesNotNotifyListener() {
    EngineResource<Object> first = new EngineResource<>(resource, /*isCacheable=*/
    true, /*isRecyclable=*/
    true);
    resources.activate(key, first);
    ResourceWeakReference weakRef = resources.activeEngineResources.get(key);
    CountDownLatch latch = getLatchForClearedRef();
    weakRef.enqueue();
    EngineResource<Object> second = new EngineResource<>(resource, /*isCacheable=*/
    true, /*isRecyclable=*/
    true);
    resources.activate(key, second);
    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 10 with ResourceWeakReference

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

the class ActiveResourcesTest method queueIdle_withCacheableResourceInActive_callListener.

@Test
public void queueIdle_withCacheableResourceInActive_callListener() {
    EngineResource<Object> engineResource = new EngineResource<>(resource, /*isCacheable=*/
    true, /*isRecyclable=*/
    true);
    resources.activate(key, engineResource);
    ResourceWeakReference weakRef = resources.activeEngineResources.get(key);
    enqueueAndWaitForRef(weakRef);
    ArgumentCaptor<EngineResource<?>> captor = getEngineResourceCaptor();
    verify(listener).onResourceReleased(eq(key), captor.capture());
    EngineResource<?> released = captor.getValue();
    assertThat(released.getResource()).isEqualTo(resource);
    assertThat(released.isCacheable()).isTrue();
    released.recycle();
    verify(resource, never()).recycle();
}
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