@Test public void shouldHandleCacheClosedException() throws BucketNotFoundException { Mockito.when(manager.getRepository(any(), any(), any())) .thenThrow(CacheClosedException.class); AsyncEvent event = Mockito.mock(AsyncEvent.class); boolean result = listener.processEvents(Arrays.asList(event)); assertFalse(result); verify(listener, times(1)) .logDebugMessage(contains("cache has been closed"), any(CacheClosedException.class)); }
@Test public void shouldHandleBucketNotFoundException() throws BucketNotFoundException { Mockito.when(manager.getRepository(any(), any(), any())) .thenThrow(BucketNotFoundException.class); AsyncEvent event = Mockito.mock(AsyncEvent.class); boolean result = listener.processEvents(Arrays.asList(event)); assertFalse(result); verify(listener, times(1)) .logDebugMessage(startsWith("Bucket not found"), any(BucketNotFoundException.class)); }
@Test public void shouldHandleAlreadyClosedException() throws BucketNotFoundException { Mockito.when(manager.getRepository(any(), any(), any())) .thenThrow(AlreadyClosedException.class); AsyncEvent event = Mockito.mock(AsyncEvent.class); boolean result = listener.processEvents(Arrays.asList(event)); assertFalse(result); verify(listener, times(1)) .logDebugMessage(contains("the lucene index is already closed"), any(AlreadyClosedException.class)); }
@Test public void shouldThrowAndCaptureIOException() throws BucketNotFoundException { doAnswer((m) -> { throw new IOException(); }).when(manager).getRepository(any(), any(), any()); AtomicReference<Throwable> lastException = new AtomicReference<>(); LuceneEventListener.setExceptionObserver(lastException::set); AsyncEvent event = Mockito.mock(AsyncEvent.class); try { listener.processEvents(Arrays.asList(event)); fail("should have thrown an exception"); } catch (InternalGemFireError expected) { assertEquals(expected, lastException.get()); } } }
Mockito.when(manager.getRepository(eq(region1), any(), eq(callback1))).thenReturn(repo1); Mockito.when(manager.getRepository(eq(region2), any(), eq(null))).thenReturn(repo2); List<AsyncEvent> events = new ArrayList<AsyncEvent>();
Object callbackArgument = event.getCallbackArgument(); IndexRepository repository = repositoryManager.getRepository(region, key, callbackArgument);