public BDDStubber willCallRealMethod() { return new BDDStubberImpl(mockitoStubber.doCallRealMethod()); } }
@Override public Stubber doCallRealMethod() { return stubber().doCallRealMethod(); }
public BDDStubber willCallRealMethod() { return new BDDStubberImpl(mockitoStubber.doCallRealMethod()); } }
return MOCKITO_CORE.stubber().doCallRealMethod();
IMetaStoreClient spyDb = Mockito.spy(db); Mockito.doThrow(HiveException.class).doCallRealMethod().doCallRealMethod().when(spyDb) .add_partitions(Mockito.anyObject(), Mockito.anyBoolean(), Mockito.anyBoolean());
@Override public StaticCapableStubber doCallRealMethod() { instanceStubber = instanceStubber.doCallRealMethod(); return this; } }
Mockito.doThrow(MetastoreException.class).doCallRealMethod().doCallRealMethod().when(spyDb) .dropPartitions(Mockito.eq(table.getCatName()), Mockito.eq(table.getDbName()), Mockito.eq(table.getTableName()),
@Override public Stubber doCallRealMethod() {return stubber.doCallRealMethod();}
@Test default void listenerShouldNotReceiveWhenFailsGreaterThanMaxRetries() throws Exception { EventCollector eventCollector = eventCollector(); doThrow(new RuntimeException()) .doThrow(new RuntimeException()) .doThrow(new RuntimeException()) .doThrow(new RuntimeException()) .doCallRealMethod() .when(eventCollector).event(EVENT); eventBus().register(eventCollector, GROUP_A); eventBus().dispatch(EVENT, NO_KEYS).block(); TimeUnit.SECONDS.sleep(1); assertThat(eventCollector.getEvents()) .isEmpty(); }
@Test default void listenerShouldReceiveWhenFailsLessThanMaxRetries() { EventCollector eventCollector = eventCollector(); doThrow(new RuntimeException()) .doThrow(new RuntimeException()) .doCallRealMethod() .when(eventCollector).event(EVENT); eventBus().register(eventCollector, GROUP_A); eventBus().dispatch(EVENT, NO_KEYS).block(); WAIT_CONDITION .until(() -> assertThat(eventCollector.getEvents()).hasSize(1)); }
@Test default void listenerShouldReceiveWhenFailsEqualsMaxRetries() { EventCollector eventCollector = eventCollector(); doThrow(new RuntimeException()) .doThrow(new RuntimeException()) .doThrow(new RuntimeException()) .doCallRealMethod() .when(eventCollector).event(EVENT); eventBus().register(eventCollector, GROUP_A); eventBus().dispatch(EVENT, NO_KEYS).block(); WAIT_CONDITION .until(() -> assertThat(eventCollector.getEvents()).hasSize(1)); }
@Test void retryShouldWorkWhenDeliverWithRetry() { MailboxListenerCountingSuccessfulExecution listener = newListener(); doThrow(new RuntimeException()) .doThrow(new RuntimeException()) .doThrow(new RuntimeException()) .doCallRealMethod() .when(listener).event(EVENT); inVmEventDelivery.deliver(listener, EVENT, DeliveryOption.of( BackoffRetryer.of(RetryBackoffConfiguration.DEFAULT, listener), PermanentFailureHandler.NO_HANDLER)) .allListenerFuture() .block(); assertThat(listener.numberOfEventCalls()) .isEqualTo(1); }
@Test default void deadLetterShouldNotStoreWhenFailsLessThanMaxRetries() { EventCollector eventCollector = eventCollector(); doThrow(new RuntimeException()) .doThrow(new RuntimeException()) .doCallRealMethod() .when(eventCollector).event(EVENT); eventBus().register(eventCollector, new EventBusTestFixture.GroupA()); eventBus().dispatch(EVENT, NO_KEYS).block(); WAIT_CONDITION .until(() -> assertThat(eventCollector.getEvents()).hasSize(1)); assertThat(deadLetter().groupsWithFailedEvents().toIterable()) .isEmpty(); }
@Test default void deadLetterShouldStoreWhenFailsGreaterThanMaxRetries() throws Exception { EventCollector eventCollector = eventCollector(); doThrow(new RuntimeException()) .doThrow(new RuntimeException()) .doThrow(new RuntimeException()) .doThrow(new RuntimeException()) .doCallRealMethod() .when(eventCollector).event(EVENT); eventBus().register(eventCollector, GROUP_A); eventBus().dispatch(EVENT, NO_KEYS).block(); WAIT_CONDITION.until(() -> assertThat(deadLetter().failedEventIds(GROUP_A).toIterable()) .containsOnly(EVENT.getEventId())); assertThat(eventCollector.getEvents()) .isEmpty(); } }
@Test public void testIpcOnAddFailure() throws Throwable { BaseHandler.CONFIG_FILE = "/config/handler_config.json"; handler.skipWriteStats = true; List<DummyEvent> events = new ArrayList<DummyEvent>(2); events.add(new DummyEvent("foo", 0)); events.add(new DummyEvent("bar", 0)); TestContext context = new TestContext(); context.setInvokedFunctionArn("arn:aws:lambda:us-east-1:123:function:test:tag"); handler.init(context); TransportBuffer tbSpy1 = spy(new ArrayTransportBuffer()); TransportBuffer tbSpy2 = spy(new ArrayTransportBuffer()); doCallRealMethod().doCallRealMethod().when(tbSpy1).add(any()); doThrow(new IllegalStateException("expected")).when(tbSpy2).add(any()); IpcSenderService spyIpc = spy(handler.getIpcService()); TransportFactory tfSpy = spy(spyIpc.getTransportFactory()); when(tfSpy.newTransportBuffer()).thenReturn(tbSpy1, tbSpy2); spyIpc.setTransportFactory(tfSpy); handler.setIpcService(spyIpc); handler.handler(events, context); assertEquals(1, spyIpc.getSuccessCountStat().getValue()); }
@Test default void deadLettersIsNotAppliedForKeyRegistrations() throws Exception { EventCollector eventCollector = eventCollector(); doThrow(new RuntimeException()) .doThrow(new RuntimeException()) .doThrow(new RuntimeException()) .doThrow(new RuntimeException()) .doCallRealMethod() .when(eventCollector).event(EVENT); eventBus().register(eventCollector, KEY_1); eventBus().dispatch(EVENT, ImmutableSet.of(KEY_1)).block(); TimeUnit.SECONDS.sleep(1); SoftAssertions.assertSoftly(softly -> { softly.assertThat(eventCollector.getEvents()).isEmpty(); softly.assertThat(deadLetter().groupsWithFailedEvents().toIterable()) .isEmpty(); }); }
}).doCallRealMethod().when(buffer).close();
@Test void failureHandlerShouldWorkWhenRetryFails() { MailboxListenerCountingSuccessfulExecution listener = newListener(); doThrow(new RuntimeException()) .doThrow(new RuntimeException()) .doThrow(new RuntimeException()) .doThrow(new RuntimeException()) .doCallRealMethod() .when(listener).event(EVENT); MemoryEventDeadLetters deadLetter = new MemoryEventDeadLetters(); inVmEventDelivery.deliver(listener, EVENT, DeliveryOption.of( BackoffRetryer.of(RetryBackoffConfiguration.DEFAULT, listener), PermanentFailureHandler.StoreToDeadLetters.of(GROUP_A, deadLetter))) .allListenerFuture() .block(); SoftAssertions.assertSoftly(softy -> { softy.assertThat(listener.numberOfEventCalls()) .isEqualTo(0); assertThat(deadLetter.groupsWithFailedEvents().toStream()) .containsOnly(GROUP_A); }); } }
@Test void failureHandlerShouldNotWorkWhenRetrySuccess() { MailboxListenerCountingSuccessfulExecution listener = newListener(); doThrow(new RuntimeException()) .doThrow(new RuntimeException()) .doCallRealMethod() .when(listener).event(EVENT); MemoryEventDeadLetters deadLetter = new MemoryEventDeadLetters(); inVmEventDelivery.deliver(listener, EVENT, DeliveryOption.of( BackoffRetryer.of(RetryBackoffConfiguration.DEFAULT, listener), PermanentFailureHandler.StoreToDeadLetters.of(GROUP_A, deadLetter))) .allListenerFuture() .block(); SoftAssertions.assertSoftly(softy -> { softy.assertThat(listener.numberOfEventCalls()) .isEqualTo(1); softy.assertThat(deadLetter.groupsWithFailedEvents().toStream()) .isEmpty(); }); }