use of org.mockito.internal.stubbing.answers.ThrowsException in project hadoop by apache.
the class TestFailoverController method testFailoverFromNonExistantServiceWithFencer.
@Test
public void testFailoverFromNonExistantServiceWithFencer() throws Exception {
DummyHAService svc1 = spy(new DummyHAService(null, svc1Addr));
// Getting a proxy to a dead server will throw IOException on call,
// not on creation of the proxy.
HAServiceProtocol errorThrowingProxy = Mockito.mock(HAServiceProtocol.class, Mockito.withSettings().defaultAnswer(new ThrowsException(new IOException("Could not connect to host"))).extraInterfaces(Closeable.class));
Mockito.doNothing().when((Closeable) errorThrowingProxy).close();
Mockito.doReturn(errorThrowingProxy).when(svc1).getProxy(Mockito.<Configuration>any(), Mockito.anyInt());
DummyHAService svc2 = new DummyHAService(HAServiceState.STANDBY, svc2Addr);
svc1.fencer = svc2.fencer = setupFencer(AlwaysSucceedFencer.class.getName());
try {
doFailover(svc1, svc2, false, false);
} catch (FailoverFailedException ffe) {
fail("Non-existant active prevented failover");
}
// Verify that the proxy created to try to make it go to standby
// gracefully used the right rpc timeout
Mockito.verify(svc1).getProxy(Mockito.<Configuration>any(), Mockito.eq(CommonConfigurationKeys.HA_FC_GRACEFUL_FENCE_TIMEOUT_DEFAULT));
// Don't check svc1 because we can't reach it, but that's OK, it's been fenced.
assertEquals(HAServiceState.ACTIVE, svc2.state);
}
use of org.mockito.internal.stubbing.answers.ThrowsException in project mockito by mockito.
the class InvocationContainerImplStubbingTest method should_finish_stubbing_when_wrong_throwable_is_set.
@Test
public void should_finish_stubbing_when_wrong_throwable_is_set() throws Exception {
state.stubbingStarted();
try {
invocationContainerImpl.addAnswer(new ThrowsException(new Exception()));
fail();
} catch (MockitoException e) {
state.validateState();
}
}
use of org.mockito.internal.stubbing.answers.ThrowsException in project mockito by mockito.
the class MocksSerializationTest method should_allow_throws_exception_to_be_serializable.
@Test
public void should_allow_throws_exception_to_be_serializable() throws Exception {
// given
Bar mock = mock(Bar.class, new ThrowsException(new RuntimeException()));
// when-serialize then-deserialize
serializeAndBack(mock);
}
use of org.mockito.internal.stubbing.answers.ThrowsException in project neo4j by neo4j.
the class ExecutionResultSerializerTest method shouldAbbreviateWellKnownIOErrors.
@Test
public void shouldAbbreviateWellKnownIOErrors() throws Exception {
// given
OutputStream output = mock(OutputStream.class, new ThrowsException(new IOException("Broken pipe")));
AssertableLogProvider logProvider = new AssertableLogProvider();
ExecutionResultSerializer serializer = getSerializerWith(output, null, logProvider);
// when
serializer.finish();
// then
logProvider.assertExactly(AssertableLogProvider.inLog(ExecutionResultSerializer.class).error("Unable to reply to request, because the client has closed the connection (Broken pipe)."));
}
use of org.mockito.internal.stubbing.answers.ThrowsException in project neo4j by neo4j.
the class ExecutionResultSerializerTest method shouldLogIOErrors.
@Test
public void shouldLogIOErrors() throws Exception {
// given
IOException failure = new IOException();
OutputStream output = mock(OutputStream.class, new ThrowsException(failure));
AssertableLogProvider logProvider = new AssertableLogProvider();
ExecutionResultSerializer serializer = getSerializerWith(output, null, logProvider);
// when
serializer.finish();
// then
logProvider.assertExactly(AssertableLogProvider.inLog(ExecutionResultSerializer.class).error(is("Failed to generate JSON output."), sameInstance(failure)));
}
Aggregations