Java Code Examples for com.android.volley.utils.CacheTestUtils#makeRandomCacheEntry()

The following examples show how to use com.android.volley.utils.CacheTestUtils#makeRandomCacheEntry() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CacheDispatcherTest.java    From volley with Apache License 2.0 6 votes vote down vote up
@Test
public void softExpiredCacheHit() throws Exception {
    Cache.Entry entry = CacheTestUtils.makeRandomCacheEntry(null, false, true);
    when(mCache.get(anyString())).thenReturn(entry);
    mDispatcher.processRequest(mRequest);

    // Soft expiration needs to use the deferred Runnable variant of postResponse,
    // so make sure it gets to run.
    ArgumentCaptor<Runnable> runnable = ArgumentCaptor.forClass(Runnable.class);
    verify(mDelivery).postResponse(any(Request.class), any(Response.class), runnable.capture());
    runnable.getValue().run();
    // This way we can verify the behavior of the Runnable as well.
    verify(mNetworkQueue).put(mRequest);
    assertSame(entry, mRequest.getCacheEntry());

    verify(mDelivery, never()).postError(any(Request.class), any(VolleyError.class));
}
 
Example 2
Source File: CacheDispatcherTest.java    From volley with Apache License 2.0 6 votes vote down vote up
@Test
public void processRequestNotifiesListener() throws Exception {
    RequestQueue.RequestEventListener listener = mock(RequestQueue.RequestEventListener.class);
    RequestQueue queue = new RequestQueue(mCache, mNetwork, 0, mDelivery);
    queue.addRequestEventListener(listener);
    mRequest.setRequestQueue(queue);

    Cache.Entry entry = CacheTestUtils.makeRandomCacheEntry(null, false, false);
    when(mCache.get(anyString())).thenReturn(entry);
    mDispatcher.processRequest(mRequest);

    InOrder inOrder = inOrder(listener);
    inOrder.verify(listener)
            .onRequestEvent(mRequest, RequestQueue.RequestEvent.REQUEST_CACHE_LOOKUP_STARTED);
    inOrder.verify(listener)
            .onRequestEvent(mRequest, RequestQueue.RequestEvent.REQUEST_CACHE_LOOKUP_FINISHED);
    inOrder.verifyNoMoreInteractions();
}
 
Example 3
Source File: ResponseDeliveryTest.java    From product-emm with Apache License 2.0 5 votes vote down vote up
@Before public void setUp() throws Exception {
    // Make the delivery just run its posted responses immediately.
    mDelivery = new ImmediateResponseDelivery();
    mRequest = new MockRequest();
    mRequest.setSequence(1);
    byte[] data = new byte[16];
    Cache.Entry cacheEntry = CacheTestUtils.makeRandomCacheEntry(data);
    mSuccessResponse = Response.success(data, cacheEntry);
}
 
Example 4
Source File: CacheDispatcherTest.java    From CrossBow with Apache License 2.0 5 votes vote down vote up
@Test public void softExpiredCacheHit() throws Exception {
    Cache.Entry entry = CacheTestUtils.makeRandomCacheEntry(null, false, true);
    mCache.setEntryToReturn(entry);
    mCacheQueue.add(mRequest);
    mCacheQueue.waitUntilEmpty(TIMEOUT_MILLIS);
    assertTrue(mDelivery.postResponse_called);
    assertFalse(mDelivery.postError_called);
    assertTrue(mNetworkQueue.size() > 0);
    Request request = mNetworkQueue.take();
    assertSame(entry, request.getCacheEntry());
}
 
Example 5
Source File: CacheDispatcherTest.java    From android-project-wo2b with Apache License 2.0 5 votes vote down vote up
public void testSoftExpiredCacheHit() throws Exception {
    Cache.Entry entry = CacheTestUtils.makeRandomCacheEntry(null, false, true);
    mCache.setEntryToReturn(entry);
    mCacheQueue.add(mRequest);
    mCacheQueue.waitUntilEmpty(TIMEOUT_MILLIS);
    assertTrue(mDelivery.postResponse_called);
    assertFalse(mDelivery.postError_called);
    assertTrue(mNetworkQueue.size() > 0);
    Request request = mNetworkQueue.take();
    assertSame(entry, request.getCacheEntry());
}
 
Example 6
Source File: CacheDispatcherTest.java    From android-discourse with Apache License 2.0 5 votes vote down vote up
public void testNonExpiredCacheHit() throws Exception {
    Cache.Entry entry = CacheTestUtils.makeRandomCacheEntry(null, false, false);
    mCache.setEntryToReturn(entry);
    mCacheQueue.add(mRequest);
    mCacheQueue.waitUntilEmpty(TIMEOUT_MILLIS);
    assertTrue(mDelivery.postResponse_called);
    assertFalse(mDelivery.postError_called);
}
 
Example 7
Source File: CacheDispatcherTest.java    From product-emm with Apache License 2.0 5 votes vote down vote up
@Test public void nonExpiredCacheHit() throws Exception {
    Cache.Entry entry = CacheTestUtils.makeRandomCacheEntry(null, false, false);
    mCache.setEntryToReturn(entry);
    mCacheQueue.add(mRequest);
    mCacheQueue.waitUntilEmpty(TIMEOUT_MILLIS);
    assertTrue(mDelivery.postResponse_called);
    assertFalse(mDelivery.postError_called);
}
 
Example 8
Source File: CacheDispatcherTest.java    From android-discourse with Apache License 2.0 5 votes vote down vote up
public void testExpiredCacheHit() throws Exception {
    Cache.Entry entry = CacheTestUtils.makeRandomCacheEntry(null, true, true);
    mCache.setEntryToReturn(entry);
    mCacheQueue.add(mRequest);
    mCacheQueue.waitUntilEmpty(TIMEOUT_MILLIS);
    assertFalse(mDelivery.wasEitherResponseCalled());
    assertTrue(mNetworkQueue.size() > 0);
    Request request = mNetworkQueue.take();
    assertSame(entry, request.getCacheEntry());
}
 
Example 9
Source File: CacheDispatcherTest.java    From SaveVolley with Apache License 2.0 5 votes vote down vote up
@Test public void softExpiredCacheHit() throws Exception {
    Cache.Entry entry = CacheTestUtils.makeRandomCacheEntry(null, false, true);
    mCache.setEntryToReturn(entry);
    mCacheQueue.add(mRequest);
    mCacheQueue.waitUntilEmpty(TIMEOUT_MILLIS);
    assertTrue(mDelivery.postResponse_called);
    assertFalse(mDelivery.postError_called);
    assertTrue(mNetworkQueue.size() > 0);
    Request request = mNetworkQueue.take();
    assertSame(entry, request.getCacheEntry());
}
 
Example 10
Source File: ResponseDeliveryTest.java    From android-discourse with Apache License 2.0 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
    super.setUp();

    // Make the delivery just run its posted responses immediately.
    mDelivery = new ImmediateResponseDelivery();
    mRequest = new MockRequest();
    mRequest.setSequence(1);
    byte[] data = new byte[16];
    Cache.Entry cacheEntry = CacheTestUtils.makeRandomCacheEntry(data);
    mSuccessResponse = Response.success(data, cacheEntry);
}
 
Example 11
Source File: ResponseDeliveryTest.java    From SaveVolley with Apache License 2.0 5 votes vote down vote up
@Before public void setUp() throws Exception {
    // Make the delivery just run its posted responses immediately.
    mDelivery = new ImmediateResponseDelivery();
    mRequest = new MockRequest();
    mRequest.setSequence(1);
    byte[] data = new byte[16];
    Cache.Entry cacheEntry = CacheTestUtils.makeRandomCacheEntry(data);
    mSuccessResponse = Response.success(data, cacheEntry);
}
 
Example 12
Source File: CacheDispatcherTest.java    From device-database with Apache License 2.0 5 votes vote down vote up
@Test public void expiredCacheHit() throws Exception {
    Cache.Entry entry = CacheTestUtils.makeRandomCacheEntry(null, true, true);
    mCache.setEntryToReturn(entry);
    mCacheQueue.add(mRequest);
    mCacheQueue.waitUntilEmpty(TIMEOUT_MILLIS);
    assertFalse(mDelivery.wasEitherResponseCalled());
    assertTrue(mNetworkQueue.size() > 0);
    Request request = mNetworkQueue.take();
    assertSame(entry, request.getCacheEntry());
}
 
Example 13
Source File: CacheDispatcherTest.java    From product-emm with Apache License 2.0 5 votes vote down vote up
@Test public void nonExpiredCacheHit() throws Exception {
    Cache.Entry entry = CacheTestUtils.makeRandomCacheEntry(null, false, false);
    mCache.setEntryToReturn(entry);
    mCacheQueue.add(mRequest);
    mCacheQueue.waitUntilEmpty(TIMEOUT_MILLIS);
    assertTrue(mDelivery.postResponse_called);
    assertFalse(mDelivery.postError_called);
}
 
Example 14
Source File: CacheDispatcherTest.java    From product-emm with Apache License 2.0 5 votes vote down vote up
@Test public void expiredCacheHit() throws Exception {
    Cache.Entry entry = CacheTestUtils.makeRandomCacheEntry(null, true, true);
    mCache.setEntryToReturn(entry);
    mCacheQueue.add(mRequest);
    mCacheQueue.waitUntilEmpty(TIMEOUT_MILLIS);
    assertFalse(mDelivery.wasEitherResponseCalled());
    assertTrue(mNetworkQueue.size() > 0);
    Request request = mNetworkQueue.take();
    assertSame(entry, request.getCacheEntry());
}
 
Example 15
Source File: ResponseDeliveryTest.java    From device-database with Apache License 2.0 5 votes vote down vote up
@Before public void setUp() throws Exception {
    // Make the delivery just run its posted responses immediately.
    mDelivery = new ImmediateResponseDelivery();
    mRequest = new MockRequest();
    mRequest.setSequence(1);
    byte[] data = new byte[16];
    Cache.Entry cacheEntry = CacheTestUtils.makeRandomCacheEntry(data);
    mSuccessResponse = Response.success(data, cacheEntry);
}
 
Example 16
Source File: CacheDispatcherTest.java    From CrossBow with Apache License 2.0 5 votes vote down vote up
@Test public void expiredCacheHit() throws Exception {
    Cache.Entry entry = CacheTestUtils.makeRandomCacheEntry(null, true, true);
    mCache.setEntryToReturn(entry);
    mCacheQueue.add(mRequest);
    mCacheQueue.waitUntilEmpty(TIMEOUT_MILLIS);
    assertFalse(mDelivery.wasEitherResponseCalled());
    assertTrue(mNetworkQueue.size() > 0);
    Request request = mNetworkQueue.take();
    assertSame(entry, request.getCacheEntry());
}
 
Example 17
Source File: CacheDispatcherTest.java    From product-emm with Apache License 2.0 5 votes vote down vote up
@Test public void softExpiredCacheHit() throws Exception {
    Cache.Entry entry = CacheTestUtils.makeRandomCacheEntry(null, false, true);
    mCache.setEntryToReturn(entry);
    mCacheQueue.add(mRequest);
    mCacheQueue.waitUntilEmpty(TIMEOUT_MILLIS);
    assertTrue(mDelivery.postResponse_called);
    assertFalse(mDelivery.postError_called);
    assertTrue(mNetworkQueue.size() > 0);
    Request request = mNetworkQueue.take();
    assertSame(entry, request.getCacheEntry());
}
 
Example 18
Source File: ResponseDeliveryTest.java    From CrossBow with Apache License 2.0 5 votes vote down vote up
@Before public void setUp() throws Exception {
    // Make the delivery just run its posted responses immediately.
    mDelivery = new ImmediateResponseDelivery();
    mRequest = new MockRequest();
    mRequest.setSequence(1);
    byte[] data = new byte[16];
    Cache.Entry cacheEntry = CacheTestUtils.makeRandomCacheEntry(data);
    mSuccessResponse = Response.success(data, cacheEntry);
}
 
Example 19
Source File: CacheDispatcherTest.java    From volley with Apache License 2.0 5 votes vote down vote up
@Test
public void expiredCacheHit() throws Exception {
    Cache.Entry entry = CacheTestUtils.makeRandomCacheEntry(null, true, true);
    when(mCache.get(anyString())).thenReturn(entry);
    mDispatcher.processRequest(mRequest);
    verifyNoResponse(mDelivery);
    verify(mNetworkQueue).put(mRequest);
    assertSame(entry, mRequest.getCacheEntry());
}
 
Example 20
Source File: CacheDispatcherTest.java    From CrossBow with Apache License 2.0 5 votes vote down vote up
@Test public void nonExpiredCacheHit() throws Exception {
    Cache.Entry entry = CacheTestUtils.makeRandomCacheEntry(null, false, false);
    mCache.setEntryToReturn(entry);
    mCacheQueue.add(mRequest);
    mCacheQueue.waitUntilEmpty(TIMEOUT_MILLIS);
    assertTrue(mDelivery.postResponse_called);
    assertFalse(mDelivery.postError_called);
}