Пример #1
0
  @Test
  public void testFlatMapMaxConcurrent() {
    final int m = 4;
    final AtomicInteger subscriptionCount = new AtomicInteger();
    Observable<Integer> source =
        Observable.range(1, 10)
            .flatMap(
                new Func1<Integer, Observable<Integer>>() {
                  @Override
                  public Observable<Integer> call(Integer t1) {
                    return compose(Observable.range(t1 * 10, 2), subscriptionCount, m)
                        .subscribeOn(Schedulers.computation());
                  }
                },
                m);

    TestSubscriber<Integer> ts = new TestSubscriber<Integer>();

    source.subscribe(ts);

    ts.awaitTerminalEvent();
    ts.assertNoErrors();
    Set<Integer> expected =
        new HashSet<Integer>(
            Arrays.asList(
                10, 11, 20, 21, 30, 31, 40, 41, 50, 51, 60, 61, 70, 71, 80, 81, 90, 91, 100, 101));
    Assert.assertEquals(expected.size(), ts.getOnNextEvents().size());
    Assert.assertTrue(expected.containsAll(ts.getOnNextEvents()));
  }
 @Test
 public void testBitmapMemoryCacheGetSuccessful() {
   setupBitmapCacheGetSuccess();
   when(mProducerContext.getLowestPermittedRequestLevel())
       .thenReturn(ImageRequest.RequestLevel.BITMAP_MEMORY_CACHE);
   mBitmapMemoryCacheGetProducer.produceResults(mConsumer, mProducerContext);
   verify(mConsumer).onNewResult(mFinalImageReference, true);
   verify(mProducerListener).onProducerStart(mRequestId, PRODUCER_NAME);
   Map<String, String> extraMap =
       ImmutableMap.of(BitmapMemoryCacheProducer.EXTRA_CACHED_VALUE_FOUND, "true");
   verify(mProducerListener).onProducerFinishWithSuccess(mRequestId, PRODUCER_NAME, extraMap);
   Assert.assertTrue(!mFinalImageReference.isValid());
 }
 @Test
 public void testEncodedMemoryCacheGetNotFoundNextProducerSuccess() {
   setupEncodedMemoryCacheGetNotFound();
   setupNextProducerStreamingSuccess();
   mEncodedMemoryCacheProducer.produceResults(mConsumer, mProducerContext);
   verify(mMemoryCache, never()).cache(mCacheKey, mIntermediateImageReference);
   ArgumentCaptor<CloseableReference> argumentCaptor =
       ArgumentCaptor.forClass(CloseableReference.class);
   verify(mMemoryCache).cache(eq(mCacheKey), argumentCaptor.capture());
   CloseableReference<PooledByteBuffer> capturedRef =
       (CloseableReference<PooledByteBuffer>) argumentCaptor.getValue();
   Assert.assertSame(
       mFinalImageReference.getUnderlyingReferenceTestOnly(),
       capturedRef.getUnderlyingReferenceTestOnly());
   verify(mConsumer).onNewResult(mIntermediateEncodedImage, false);
   verify(mConsumer).onNewResult(mFinalEncodedImage, true);
   Assert.assertTrue(EncodedImage.isValid(mFinalEncodedImageClone));
   verify(mProducerListener).onProducerStart(mRequestId, PRODUCER_NAME);
   Map<String, String> extraMap = ImmutableMap.of(EncodedMemoryCacheProducer.VALUE_FOUND, "false");
   verify(mProducerListener).onProducerFinishWithSuccess(mRequestId, PRODUCER_NAME, extraMap);
 }