private static void setMockLocation(ClusterConnection hc, byte[] row, RegionLocations result) throws IOException { Mockito.when(hc.locateRegion(Mockito.eq(DUMMY_TABLE), Mockito.eq(row), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.anyInt())).thenReturn(result); Mockito.when(hc.locateRegion(Mockito.eq(DUMMY_TABLE), Mockito.eq(row), Mockito.anyBoolean(), Mockito.anyBoolean())).thenReturn(result); }
private static void setMockLocation(ClusterConnection hc, byte[] row, RegionLocations result) throws IOException { Mockito.when(hc.locateRegion(Mockito.eq(DUMMY_TABLE), Mockito.eq(row), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.anyInt())).thenReturn(result); Mockito.when(hc.locateRegion(Mockito.eq(DUMMY_TABLE), Mockito.eq(row), Mockito.anyBoolean(), Mockito.anyBoolean())).thenReturn(result); }
@Test public void testSuccess() throws Exception { @SuppressWarnings("unchecked") Future<Object> future = mock(Future.class); Object value = new Object(); when(future.get()).thenReturn(value); Subscriber<Object> subscriber = TestHelper.mockSubscriber(); TestSubscriber<Object> ts = new TestSubscriber<Object>(subscriber); Flowable.fromFuture(future).subscribe(ts); ts.dispose(); verify(subscriber, times(1)).onNext(value); verify(subscriber, times(1)).onComplete(); verify(subscriber, never()).onError(any(Throwable.class)); verify(future, never()).cancel(anyBoolean()); }
@Test public void testFailure() throws Exception { @SuppressWarnings("unchecked") Future<Object> future = mock(Future.class); RuntimeException e = new RuntimeException(); when(future.get()).thenThrow(e); Subscriber<Object> subscriber = TestHelper.mockSubscriber(); TestSubscriber<Object> ts = new TestSubscriber<Object>(subscriber); Flowable.fromFuture(future).subscribe(ts); ts.dispose(); verify(subscriber, never()).onNext(null); verify(subscriber, never()).onComplete(); verify(subscriber, times(1)).onError(e); verify(future, never()).cancel(anyBoolean()); }
private void forcesToRecalculate_Sxssf( String property, boolean expectedFlag ) throws Exception { step.setVariable( ExcelWriterStep.STREAMER_FORCE_RECALC_PROP_NAME, property ); data.wb = spy( new SXSSFWorkbook() ); step.recalculateAllWorkbookFormulas(); if ( expectedFlag ) { verify( data.wb ).setForceFormulaRecalculation( true ); } else { verify( data.wb, never() ).setForceFormulaRecalculation( anyBoolean() ); } }
private ClusterConnection createHConnection() throws IOException { ClusterConnection hc = createHConnectionCommon(); setMockLocation(hc, DUMMY_BYTES_1, new RegionLocations(loc1)); setMockLocation(hc, DUMMY_BYTES_2, new RegionLocations(loc2)); setMockLocation(hc, DUMMY_BYTES_3, new RegionLocations(loc3)); Mockito.when(hc.locateRegions(Mockito.eq(DUMMY_TABLE), Mockito.anyBoolean(), Mockito.anyBoolean())).thenReturn(Arrays.asList(loc1, loc2, loc3)); setMockLocation(hc, FAILS, new RegionLocations(loc2)); return hc; }
@Test public void requestManager_intoImageView_withSameByteArrayAndMemoryCacheEnabled_loadsFromMemory() throws IOException { final byte[] canonicalBytes = getCanonicalBytes(); concurrency.loadOnMainThread( Glide.with(context) .load(canonicalBytes) .apply(skipMemoryCacheOf(false)), imageView); Glide.with(context).clear(imageView); concurrency.loadOnMainThread( Glide.with(context) .load(canonicalBytes) .listener(requestListener) .apply(skipMemoryCacheOf(false)), imageView); verify(requestListener).onResourceReady( anyDrawable(), any(), anyDrawableTarget(), eq(DataSource.MEMORY_CACHE), anyBoolean()); }
@Test public void testQueryCloseOnError() throws Exception { ObjectStore spy = Mockito.spy(objectStore); spy.getAllDatabases(DEFAULT_CATALOG_NAME); spy.getAllFunctions(DEFAULT_CATALOG_NAME); spy.getAllTables(DEFAULT_CATALOG_NAME, DB1); spy.getPartitionCount(); Mockito.verify(spy, Mockito.times(3)) .rollbackAndCleanup(Mockito.anyBoolean(), Mockito.<Query>anyObject()); }
@Test public void load_whenLoadSucceeds_butEncoderFails_doesNotCallOnLoadFailed() { WaitForErrorStrategy strategy = new WaitForErrorStrategy(); Glide.init(context, new GlideBuilder() .setAnimationExecutor(GlideExecutor.newAnimationExecutor(/*threadCount=*/ 1, strategy)) .setSourceExecutor(GlideExecutor.newSourceExecutor(strategy)) .setDiskCacheExecutor(GlideExecutor.newDiskCacheExecutor(strategy))); Glide.get(context).getRegistry().prepend(Bitmap.class, new FailEncoder()); concurrency.get( Glide.with(context) .load(ResourceIds.raw.canonical) .listener(requestListener) .submit()); verify(requestListener) .onResourceReady( anyDrawable(), any(), anyDrawableTarget(), any(DataSource.class), anyBoolean()); verify(requestListener, never()) .onLoadFailed(any(GlideException.class), any(), anyDrawableTarget(), anyBoolean()); }
@Test public void requestBuilder_intoImageView_withSameByteArrayAndMemoryCacheEnabled_loadsFromMemory() throws IOException { final byte[] canonicalBytes = getCanonicalBytes(); concurrency.loadOnMainThread( Glide.with(context) .asDrawable() .load(canonicalBytes) .apply(skipMemoryCacheOf(false)), imageView); Glide.with(context).clear(imageView); concurrency.loadOnMainThread( Glide.with(context) .asDrawable() .load(canonicalBytes) .listener(requestListener) .apply(skipMemoryCacheOf(false)), imageView); verify(requestListener).onResourceReady( anyDrawable(), any(), anyDrawableTarget(), eq(DataSource.MEMORY_CACHE), anyBoolean()); }
@Test public void load_whenEncoderFails_callsUncaughtThrowableStrategy() { WaitForErrorStrategy strategy = new WaitForErrorStrategy(); Glide.init(context, new GlideBuilder() .setAnimationExecutor(GlideExecutor.newAnimationExecutor(/*threadCount=*/ 1, strategy)) .setSourceExecutor(GlideExecutor.newSourceExecutor(strategy)) .setDiskCacheExecutor(GlideExecutor.newDiskCacheExecutor(strategy))); Glide.get(context).getRegistry().prepend(Bitmap.class, new FailEncoder()); concurrency.get( Glide.with(context) .load(ResourceIds.raw.canonical) .listener(requestListener) .submit()); // Writing to the disk cache and therefore the exception caused by our FailEncoder may happen // after the request completes, so we should wait for the expected error explicitly. ConcurrencyHelper.waitOnLatch(strategy.latch); assertThat(strategy.error).isEqualTo(FailEncoder.TO_THROW); verify(requestListener, never()) .onLoadFailed(any(GlideException.class), any(), anyDrawableTarget(), anyBoolean()); }
@Test public void loadFromRequestManager_withSameByteArray_returnsFromLocal() throws IOException { byte[] data = getCanonicalBytes(); Target<Drawable> target = concurrency.wait( GlideApp.with(context) .load(data) .submit()); GlideApp.with(context).clear(target); concurrency.wait( GlideApp.with(context) .load(data) .listener(requestListener) .submit()); verify(requestListener).onResourceReady( anyDrawable(), any(), anyDrawableTarget(), eq(DataSource.LOCAL), anyBoolean()); }
@Test public void loadFromRequestBuilder_withSameByteArray_returnsFromLocal() throws IOException { byte[] data = getCanonicalBytes(); Target<Drawable> target = concurrency.wait( GlideApp.with(context) .asDrawable() .load(data) .submit()); GlideApp.with(context).clear(target); concurrency.wait( GlideApp.with(context) .asDrawable() .load(data) .listener(requestListener) .submit()); verify(requestListener).onResourceReady( anyDrawable(), any(), anyDrawableTarget(), eq(DataSource.LOCAL), anyBoolean()); }
@Test public void loadFromRequestManager_withSameByteArray_memoryCacheEnabled_returnsFromCache() throws IOException { byte[] data = getCanonicalBytes(); Target<Drawable> target = concurrency.wait( GlideApp.with(context) .load(data) .skipMemoryCache(false) .submit()); GlideApp.with(context).clear(target); concurrency.wait( GlideApp.with(context) .load(data) .skipMemoryCache(false) .listener(requestListener) .submit()); verify(requestListener).onResourceReady( anyDrawable(), any(), anyDrawableTarget(), eq(DataSource.MEMORY_CACHE), anyBoolean()); }
@Test public void submit_withDisabledMemoryCache_andResourceInActiveResources_loadsFromMemory() { Glide.init( context, new GlideBuilder().setMemoryCache(new MemoryCacheAdapter())); FutureTarget<Drawable> first = GlideApp.with(context) .load(raw.canonical) .submit(); concurrency.get(first); concurrency.get( GlideApp.with(context) .load(ResourceIds.raw.canonical) .listener(requestListener) .submit()); verify(requestListener) .onResourceReady( anyDrawable(), any(), anyDrawableTarget(), eq(DataSource.MEMORY_CACHE), anyBoolean()); }
@Test public void loadFromRequestManager_withSameByteArrayAndMissingFromMemory_returnsFromLocal() throws IOException { byte[] data = getCanonicalBytes(); Target<Drawable> target = concurrency.wait( GlideApp.with(context) .load(data) .submit()); GlideApp.with(context).clear(target); concurrency.runOnMainThread(new Runnable() { @Override public void run() { GlideApp.get(context).clearMemory(); } }); concurrency.wait( GlideApp.with(context) .load(data) .listener(requestListener) .submit()); verify(requestListener).onResourceReady( anyDrawable(), any(), anyDrawableTarget(), eq(DataSource.LOCAL), anyBoolean()); }
@Test public void loadFromRequestBuilder_withSameByteArray_memoryCacheEnabled_returnsFromCache() throws IOException { byte[] data = getCanonicalBytes(); Target<Drawable> target = concurrency.wait( GlideApp.with(context) .asDrawable() .load(data) .skipMemoryCache(false) .submit()); GlideApp.with(context).clear(target); concurrency.wait( GlideApp.with(context) .asDrawable() .load(data) .skipMemoryCache(false) .listener(requestListener) .submit()); verify(requestListener).onResourceReady( anyDrawable(), any(), anyDrawableTarget(), eq(DataSource.MEMORY_CACHE), anyBoolean()); }
@Test public void loadFromBuilder_withDataDiskCacheStrategy_returnsFromSource() throws IOException { byte[] data = getCanonicalBytes(); concurrency.wait( GlideApp.with(context) .asDrawable() .diskCacheStrategy(DiskCacheStrategy.DATA) .load(data) .submit()); concurrency.wait( GlideApp.with(context) .asDrawable() .diskCacheStrategy(DiskCacheStrategy.DATA) .skipMemoryCache(true) .load(data) .listener(requestListener) .submit()); verify(requestListener).onResourceReady( anyDrawable(), any(), anyDrawableTarget(), eq(DataSource.DATA_DISK_CACHE), anyBoolean()); }
@Test public void loadFromRequestBuilder_withSameByteArrayAndMissingFromMemory_returnsFromLocal() throws IOException { byte[] data = getCanonicalBytes(); Target<Drawable> target = concurrency.wait( GlideApp.with(context) .asDrawable() .load(data) .submit()); GlideApp.with(context).clear(target); concurrency.runOnMainThread(new Runnable() { @Override public void run() { GlideApp.get(context).clearMemory(); } }); concurrency.wait( GlideApp.with(context) .asDrawable() .load(data) .listener(requestListener) .submit()); verify(requestListener).onResourceReady( anyDrawable(), any(), anyDrawableTarget(), eq(DataSource.LOCAL), anyBoolean()); }
@Test public void loadFromBuilder_withSkipMemoryCacheSetBeforeLoad_doesNotOverrideSkipMemoryCache() throws IOException { byte[] data = getCanonicalBytes(); concurrency.wait( GlideApp.with(context) .asDrawable() .skipMemoryCache(false) .load(data) .submit()); concurrency.runOnMainThread(new Runnable() { @Override public void run() { GlideApp.get(context).clearMemory(); } }); concurrency.wait( GlideApp.with(context) .asDrawable() .skipMemoryCache(false) .listener(requestListener) .load(data) .submit()); verify(requestListener).onResourceReady( anyDrawable(), any(), anyDrawableTarget(), eq(DataSource.MEMORY_CACHE), anyBoolean()); }