Search in sources :

Example 36 with Capture

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();
}
Also used : AsyncMethodCallback(org.apache.thrift.async.AsyncMethodCallback) TTransportException(org.apache.thrift.transport.TTransportException) IOException(java.io.IOException) Capture(org.easymock.Capture) Test(org.junit.Test)

Example 37 with Capture

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();
}
Also used : Amount(com.twitter.common.quantity.Amount) Time(com.twitter.common.quantity.Time) Capture(org.easymock.Capture) Executor(java.util.concurrent.Executor) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) Test(org.junit.Test)

Example 38 with Capture

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)"));
}
Also used : PyClass(com.jetbrains.python.psi.PyClass) MultiMap(com.intellij.util.containers.MultiMap) PyMemberInfo(com.jetbrains.python.refactoring.classes.membersManager.PyMemberInfo) Collection(java.util.Collection) Capture(org.easymock.Capture)

Example 39 with Capture

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();
}
Also used : EasyMockSupport(org.easymock.EasyMockSupport) FakeHttpServletRequest(com.google.gerrit.util.http.testutil.FakeHttpServletRequest) FilterChain(javax.servlet.FilterChain) FakeHttpServletResponse(com.google.gerrit.util.http.testutil.FakeHttpServletResponse) HttpServletResponse(javax.servlet.http.HttpServletResponse) Capture(org.easymock.Capture) HttpServletRequest(javax.servlet.http.HttpServletRequest) FakeHttpServletRequest(com.google.gerrit.util.http.testutil.FakeHttpServletRequest) IMocksControl(org.easymock.IMocksControl) FakeHttpServletResponse(com.google.gerrit.util.http.testutil.FakeHttpServletResponse) FilterConfig(javax.servlet.FilterConfig) Plugin(com.google.gerrit.server.plugins.Plugin) Test(org.junit.Test)

Example 40 with Capture

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();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) FakeHttpServletRequest(com.google.gerrit.util.http.testutil.FakeHttpServletRequest) IMocksControl(org.easymock.IMocksControl) EasyMockSupport(org.easymock.EasyMockSupport) FakeHttpServletRequest(com.google.gerrit.util.http.testutil.FakeHttpServletRequest) FakeHttpServletResponse(com.google.gerrit.util.http.testutil.FakeHttpServletResponse) FilterChain(javax.servlet.FilterChain) FakeHttpServletResponse(com.google.gerrit.util.http.testutil.FakeHttpServletResponse) HttpServletResponse(javax.servlet.http.HttpServletResponse) FilterConfig(javax.servlet.FilterConfig) Capture(org.easymock.Capture) Test(org.junit.Test)

Aggregations

Capture (org.easymock.Capture)43 Test (org.junit.Test)19 INetworkManagementEventObserver (android.net.INetworkManagementEventObserver)12 Intent (android.content.Intent)8 IConnectivityManager (android.net.IConnectivityManager)8 INetworkManagementService (android.os.INetworkManagementService)8 TrustedTime (android.util.TrustedTime)8 CacheRefreshedEvent (com.netflix.discovery.CacheRefreshedEvent)6 EurekaEventListener (com.netflix.discovery.EurekaEventListener)6 ByteString (com.linkedin.data.ByteString)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 Callback (com.linkedin.common.callback.Callback)4 EurekaClient (com.netflix.discovery.EurekaClient)4 ServerListUpdater (com.netflix.loadbalancer.ServerListUpdater)4 AlarmManager (android.app.AlarmManager)3 IActivityManager (android.app.IActivityManager)3 IAlarmManager (android.app.IAlarmManager)3 INotificationManager (android.app.INotificationManager)3 IProcessObserver (android.app.IProcessObserver)3 PendingIntent (android.app.PendingIntent)3