FailfastHaStrategy extends AbstractHaStrategy<T> { @Override public Response call(Request request, LoadBalance<T> loadBalance) { Referer<T> refer = loadBalance.select(request); return refer.call(request); }  @Override Response call(Request request, LoadBalance<T> loadBalance);  }
@Test @SuppressWarnings("unchecked") public void testCall() { final LoadBalance<IWorld> loadBalance = mockery.mock(LoadBalance.class); final Referer<IWorld> referer = mockery.mock(Referer.class); final Request request = mockery.mock(Request.class); final Response response = mockery.mock(Response.class); mockery.checking(new Expectations() { { one(loadBalance).select(request); will(returnValue(referer)); one(referer).call(request); will(returnValue(response)); } }); assertEquals(response, failfastHaStrategy.call(request, loadBalance)); }
@Test(expected = MotanServiceException.class) @SuppressWarnings("unchecked") public void testCallError() { final LoadBalance<IWorld> loadBalance = mockery.mock(LoadBalance.class); final Referer<IWorld> referer = mockery.mock(Referer.class); final Request request = mockery.mock(Request.class); mockery.checking(new Expectations() { { one(loadBalance).select(request); will(returnValue(referer)); one(referer).call(request); will(returnValue(null)); } }); assertEquals(null, failfastHaStrategy.call(request, loadBalance)); }