use of com.google.common.testing.TearDown in project commons by twitter.
the class ServerSetImplTest method createThriftClient.
private Service.Iface createThriftClient(DynamicHostSet<ServiceInstance> serverSet) throws ThriftFactoryException {
final Thrift<Service.Iface> thrift = ThriftFactory.create(Service.Iface.class).build(serverSet);
addTearDown(new TearDown() {
@Override
public void tearDown() {
thrift.close();
}
});
return thrift.create();
}
use of com.google.common.testing.TearDown in project commons by twitter.
the class ExceptionHandlingScheduledExecutorServiceTest method setUp.
@Before
public void setUp() throws Exception {
signallingHandler = createMock(Thread.UncaughtExceptionHandler.class);
executorService = MoreExecutors.exceptionHandlingExecutor(Executors.newSingleThreadScheduledExecutor(), signallingHandler);
final ExecutorServiceShutdown executorServiceShutdown = new ExecutorServiceShutdown(executorService, Amount.of(3L, Time.SECONDS));
addTearDown(new TearDown() {
@Override
public void tearDown() throws Exception {
executorServiceShutdown.execute();
}
});
}
use of com.google.common.testing.TearDown in project commons by twitter.
the class ThriftFactoryTest method testCreateAsync.
@Test
public void testCreateAsync() throws IOException, InterruptedException, ThriftFactory.ThriftFactoryException {
final String[] responseHolder = new String[] { null };
final CountDownLatch done = new CountDownLatch(1);
AsyncMethodCallback<String> callback = new AsyncMethodCallback<String>() {
@Override
public void onComplete(String response) {
responseHolder[0] = response;
done.countDown();
}
@Override
public void onError(Throwable throwable) {
responseHolder[0] = throwable.toString();
done.countDown();
}
};
final Thrift<AsyncIface> thrift = ThriftFactory.create(GoodService.AsyncIface.class).withMaxConnectionsPerEndpoint(1).useFramedTransport(true).buildAsync(ImmutableSet.of(new InetSocketAddress(1234)));
addTearDown(new TearDown() {
@Override
public void tearDown() {
thrift.close();
}
});
GoodService.AsyncIface client = thrift.builder().blocking().create();
client.doWork(callback);
assertTrue("wasn't called back in time, callback got " + responseHolder[0], done.await(5000, TimeUnit.MILLISECONDS));
assertEquals(GoodService.DONE, responseHolder[0]);
}
use of com.google.common.testing.TearDown in project commons by twitter.
the class EasyMockTest method setupEasyMock.
/**
* Creates an EasyMock {@link #control} for tests to use that will be automatically
* {@link IMocksControl#verify() verified} on tear down.
*/
@Before
public final void setupEasyMock() {
control = createControl();
addTearDown(new TearDown() {
@Override
public void tearDown() {
control.verify();
}
});
}
use of com.google.common.testing.TearDown in project commons by twitter.
the class UrlResolverUtilTest method startServer.
private String startServer() throws Exception {
final Server server = new Server();
final SocketConnector connector = new SocketConnector();
connector.setHost("127.0.0.1");
connector.setPort(0);
server.addConnector(connector);
Context context = new Context(server, "/", Context.NO_SECURITY);
context.addServlet(new ServletHolder(servlet), "/*");
server.start();
addTearDown(new TearDown() {
@Override
public void tearDown() throws Exception {
server.stop();
}
});
return "http://" + connector.getHost() + ":" + connector.getLocalPort() + "/";
}
Aggregations