use of org.easymock.Capture in project commons by twitter.
the class ThriftTest method testAsyncRetriesFailure.
@Test
public void testAsyncRetriesFailure() throws Exception {
// 1st call
Capture<AsyncMethodCallback<Integer>> callbackCapture1 = new Capture<AsyncMethodCallback<Integer>>();
expectAsyncServiceCall(true).calculateMass(eq("jake"), capture(callbackCapture1));
requestTracker.requestResult((InetSocketAddress) anyObject(), eq(RequestTracker.RequestResult.FAILED), anyLong());
// 1st retry
Capture<AsyncMethodCallback<Integer>> callbackCapture2 = new Capture<AsyncMethodCallback<Integer>>();
expectAsyncServiceRetry(true).calculateMass(eq("jake"), capture(callbackCapture2));
requestTracker.requestResult((InetSocketAddress) anyObject(), eq(RequestTracker.RequestResult.FAILED), anyLong());
// 2nd retry
Capture<AsyncMethodCallback<Integer>> callbackCapture3 = new Capture<AsyncMethodCallback<Integer>>();
expectAsyncServiceRetry(true).calculateMass(eq("jake"), capture(callbackCapture3));
requestTracker.requestResult((InetSocketAddress) anyObject(), eq(RequestTracker.RequestResult.FAILED), anyLong());
// Verifies that our callback was called.
TTransportException returnedException = new TTransportException();
callback.onError(returnedException);
Thrift<TestServiceAsync> thrift = createAsyncThrift(expectUnusedExecutorService());
control.replay();
thrift.builder().withRetries(2).withConnectTimeout(ASYNC_CONNECT_TIMEOUT).create().calculateMass("jake", callback);
callbackCapture1.getValue().onError(new TTransportException());
callbackCapture2.getValue().onError(new IOException());
callbackCapture3.getValue().onError(returnedException);
assertRequestsTotal(thrift, 1);
assertErrorsTotal(thrift, 1);
assertReconnectsTotal(thrift, 1);
assertTimeoutsTotal(thrift, 0);
control.verify();
}
use of org.easymock.Capture in project commons by twitter.
the class ConnectionPoolTest method testCreating.
@Test
public void testCreating() throws Exception {
Amount<Long, Time> timeout = Amount.of(1L, Time.SECONDS);
Executor executor = new ThreadPoolExecutor(1, 1, 0, TimeUnit.MILLISECONDS, new SynchronousQueue<Runnable>());
expect(connectionFactory.mightCreate()).andReturn(true);
Capture<Amount<Long, Time>> timeout1 = new Capture<Amount<Long, Time>>();
@SuppressWarnings("unchecked") Connection<String, Integer> connection1 = control.createMock(Connection.class);
expect(connectionFactory.create(capture(timeout1))).andReturn(connection1);
Capture<Amount<Long, Time>> timeout2 = new Capture<Amount<Long, Time>>();
@SuppressWarnings("unchecked") Connection<String, Integer> connection2 = control.createMock(Connection.class);
expect(connectionFactory.create(capture(timeout2))).andReturn(connection2);
control.replay();
ConnectionPool<Connection<String, Integer>> connectionPool = createConnectionPool(executor);
assertSame(connection1, connectionPool.get(timeout));
assertTrue(timeout1.hasCaptured());
Long timeout1Millis = timeout1.getValue().as(Time.MILLISECONDS);
assertTrue(timeout1Millis > 0 && timeout1Millis <= timeout.as(Time.MILLISECONDS));
assertSame(connection2, connectionPool.get(timeout));
assertTrue(timeout2.hasCaptured());
Long timeout2Millis = timeout1.getValue().as(Time.MILLISECONDS);
assertTrue(timeout2Millis > 0 && timeout2Millis <= timeout.as(Time.MILLISECONDS));
control.verify();
}
use of org.easymock.Capture in project intellij-community by JetBrains.
the class PyPullUpPresenterTest method testConflicts.
/**
* Ensures that presenter displays conflicts if destination class already has that members
*/
public void testConflicts() throws Exception {
final PyPullUpPresenterImpl sut = configureByClass("ChildWithConflicts");
configureParent();
final Collection<PyMemberInfo<PyElement>> infos = getMemberInfos(sut);
final Capture<MultiMap<PyClass, PyMemberInfo<?>>> conflictCapture = new Capture<>();
EasyMock.expect(myView.showConflictsDialog(EasyMock.capture(conflictCapture), EasyMock.<Collection<PyMemberInfo<?>>>anyObject())).andReturn(false).anyTimes();
EasyMock.expect(myView.getSelectedMemberInfos()).andReturn(infos).anyTimes();
final PyClass parent = getClassByName("ParentWithConflicts");
EasyMock.expect(myView.getSelectedParent()).andReturn(parent).anyTimes();
myMocksControl.replay();
sut.okClicked();
final MultiMap<PyClass, PyMemberInfo<?>> conflictMap = conflictCapture.getValue();
Assert.assertTrue("No conflicts found, while it should", conflictMap.containsKey(parent));
final Collection<String> conflictedMemberNames = Collections2.transform(conflictMap.get(parent), NameTransformer.INSTANCE);
Assert.assertThat("Failed to find right conflicts", conflictedMemberNames, Matchers.containsInAnyOrder("extends Bar", "CLASS_FIELD", "self.instance_field", "my_func(self)", "__init__(self)"));
}
use of org.easymock.Capture in project gerrit by GerritCodeReview.
the class AllRequestFilterFilterProxyTest method dynamicUnloading.
@Test
public void dynamicUnloading() throws Exception {
EasyMockSupport ems = new EasyMockSupport();
FilterConfig config = ems.createMock(FilterConfig.class);
HttpServletRequest req1 = new FakeHttpServletRequest();
HttpServletRequest req2 = new FakeHttpServletRequest();
HttpServletRequest req3 = new FakeHttpServletRequest();
HttpServletResponse res1 = new FakeHttpServletResponse();
HttpServletResponse res2 = new FakeHttpServletResponse();
HttpServletResponse res3 = new FakeHttpServletResponse();
Plugin plugin = ems.createMock(Plugin.class);
IMocksControl mockControl = ems.createStrictControl();
FilterChain chain = mockControl.createMock("chain", FilterChain.class);
Capture<FilterChain> capturedChainA1 = new Capture<>();
Capture<FilterChain> capturedChainB1 = new Capture<>();
Capture<FilterChain> capturedChainB2 = new Capture<>();
AllRequestFilter filterA = mockControl.createMock("filterA", AllRequestFilter.class);
AllRequestFilter filterB = mockControl.createMock("filterB", AllRequestFilter.class);
filterA.init(config);
filterB.init(config);
filterA.doFilter(eq(req1), eq(res1), capture(capturedChainA1));
filterB.doFilter(eq(req1), eq(res1), capture(capturedChainB1));
chain.doFilter(req1, res1);
// Cleaning up of filterA after it got unloaded
filterA.destroy();
filterB.doFilter(eq(req2), eq(res2), capture(capturedChainB2));
chain.doFilter(req2, res2);
// Cleaning up of filterA after it got unloaded
filterB.destroy();
chain.doFilter(req3, res3);
ems.replayAll();
AllRequestFilter.FilterProxy filterProxy = getFilterProxy();
ReloadableRegistrationHandle<AllRequestFilter> handleFilterA = addFilter(filterA);
ReloadableRegistrationHandle<AllRequestFilter> handleFilterB = addFilter(filterB);
filterProxy.init(config);
// Request #1 with filterA and filterB
filterProxy.doFilter(req1, res1, chain);
capturedChainA1.getValue().doFilter(req1, res1);
capturedChainB1.getValue().doFilter(req1, res1);
// Unloading filterA
handleFilterA.remove();
filterProxy.onStopPlugin(plugin);
// Request #1 only with filterB
filterProxy.doFilter(req2, res2, chain);
capturedChainA1.getValue().doFilter(req2, res2);
// Unloading filterB
handleFilterB.remove();
filterProxy.onStopPlugin(plugin);
// Request #1 with no additional filters
filterProxy.doFilter(req3, res3, chain);
filterProxy.destroy();
ems.verifyAll();
}
use of org.easymock.Capture in project gerrit by GerritCodeReview.
the class AllRequestFilterFilterProxyTest method singleFilterBubbling.
@Test
public void singleFilterBubbling() throws Exception {
EasyMockSupport ems = new EasyMockSupport();
FilterConfig config = ems.createMock(FilterConfig.class);
HttpServletRequest req = new FakeHttpServletRequest();
HttpServletResponse res = new FakeHttpServletResponse();
IMocksControl mockControl = ems.createStrictControl();
FilterChain chain = mockControl.createMock(FilterChain.class);
Capture<FilterChain> capturedChain = new Capture<>();
AllRequestFilter filter = mockControl.createMock(AllRequestFilter.class);
filter.init(config);
filter.doFilter(eq(req), eq(res), capture(capturedChain));
chain.doFilter(req, res);
filter.destroy();
ems.replayAll();
AllRequestFilter.FilterProxy filterProxy = getFilterProxy();
addFilter(filter);
filterProxy.init(config);
filterProxy.doFilter(req, res, chain);
capturedChain.getValue().doFilter(req, res);
filterProxy.destroy();
ems.verifyAll();
}
Aggregations