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);
}
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)));
}
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;
}
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();
}
Aggregations