Search in sources :

Example 71 with Capture

use of org.easymock.Capture in project tesb-rt-se by Talend.

the class RegisterEndpointProviderTest method unregister.

@Ignore
@Test
public void unregister() throws Exception {
    Endpoint endpoint = create(SERVICE_QNAME_1, ENDPOINT_1, BindingType.JAXRS, TransportType.HTTP);
    Capture<Long> lastTimeStoppedCapture = new Capture<Long>();
    endpointExists(ENDPOINT_PATH_11);
    getData(ENDPOINT_PATH_11, OLD_DATA);
    data2Ep(SERVICE_QNAME_1, OLD_DATA);
    deleteEndpointStatus(ENDPOINT_PATH_11);
    ep2Data(endpoint, LAST_TIME_STARTED, lastTimeStoppedCapture, NEW_DATA);
    setData(ENDPOINT_PATH_11, NEW_DATA);
    replayAll();
    ServiceLocatorImpl slc = createServiceLocatorSuccess();
    slc.setEndpointTransformer(trans);
    long beforeUnregister = System.currentTimeMillis();
    slc.unregister(endpoint);
    long afterUnregister = System.currentTimeMillis();
    verifyAll();
    long lastTimeStopped = lastTimeStoppedCapture.getValue();
    assertTrue(beforeUnregister <= lastTimeStopped && lastTimeStopped <= afterUnregister);
}
Also used : Endpoint(org.talend.esb.servicelocator.client.Endpoint) SLEndpoint(org.talend.esb.servicelocator.client.SLEndpoint) EasyMock.anyLong(org.easymock.EasyMock.anyLong) Capture(org.easymock.Capture) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 72 with Capture

use of org.easymock.Capture in project tesb-rt-se by Talend.

the class ServiceLocatorImplTest method updateTimetolive.

@Test
public void updateTimetolive() throws Exception {
    final int ttl = 95;
    Capture<Date> dateCap = new Capture<Date>();
    expect(backend.connect()).andReturn(rootNode);
    expect(rootNode.getServiceNode(SERVICE_QNAME_1)).andReturn(serviceNode);
    expect(serviceNode.getEndPoint(ENDPOINT_1)).andReturn(endpointNode);
    expect(endpointNode.exists()).andReturn(true);
    endpointNode.setLive(true);
    endpointNode.setExpiryTime(capture(dateCap), eq(true));
    replayAll();
    ServiceLocatorImpl slc = new ServiceLocatorImpl();
    slc.setBackend(backend);
    Date startD = new Date();
    slc.updateTimetolive(SERVICE_QNAME_1, ENDPOINT_1, ttl);
    verifyAll();
    assertNotNull(dateCap.getValue());
    assertTrue(dateCap.getValue().after(startD));
    assertTrue(dateCap.getValue().before(new Date(startD.getTime() + (ttl + 5) * 1000)));
}
Also used : Date(java.util.Date) Capture(org.easymock.Capture) Test(org.junit.Test)

Example 73 with Capture

use of org.easymock.Capture in project tesb-rt-se by Talend.

the class SingleBusLocatorRegistrarTest method addServerLifeCycleManager.

private Capture<ServerLifeCycleListener> addServerLifeCycleManager(Bus bus) {
    Capture<ServerLifeCycleListener> slclCapture = new Capture<ServerLifeCycleListener>();
    ServerLifeCycleManager slcm = createMock(ServerLifeCycleManager.class);
    slcm.registerListener(capture(slclCapture));
    expect(bus.getExtension(ServerLifeCycleManager.class)).andStubReturn(slcm);
    return slclCapture;
}
Also used : ServerLifeCycleManager(org.apache.cxf.endpoint.ServerLifeCycleManager) ServerLifeCycleListener(org.apache.cxf.endpoint.ServerLifeCycleListener) Capture(org.easymock.Capture)

Example 74 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 75 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)

Aggregations

Capture (org.easymock.Capture)79 Test (org.junit.Test)42 INetworkManagementEventObserver (android.net.INetworkManagementEventObserver)12 File (java.io.File)10 Intent (android.content.Intent)8 IConnectivityManager (android.net.IConnectivityManager)8 INetworkManagementService (android.os.INetworkManagementService)8 TrustedTime (android.util.TrustedTime)8 IAnswer (org.easymock.IAnswer)7 CacheRefreshedEvent (com.netflix.discovery.CacheRefreshedEvent)6 EurekaEventListener (com.netflix.discovery.EurekaEventListener)6 Map (java.util.Map)6 UrlRewriteEnvironment (org.apache.knox.gateway.filter.rewrite.api.UrlRewriteEnvironment)6 UrlRewriteContext (org.apache.knox.gateway.filter.rewrite.spi.UrlRewriteContext)6 OutputStream (java.io.OutputStream)5 HashMap (java.util.HashMap)5 Template (org.apache.knox.gateway.util.urltemplate.Template)5 EurekaClient (com.netflix.discovery.EurekaClient)4 ServerListUpdater (com.netflix.loadbalancer.ServerListUpdater)4 URI (java.net.URI)4