use of com.google.common.testing.TearDown in project commons by twitter.
the class BaseZooKeeperTest method setUp.
@Before
public final void setUp() throws Exception {
final ShutdownRegistryImpl shutdownRegistry = new ShutdownRegistryImpl();
addTearDown(new TearDown() {
@Override
public void tearDown() {
shutdownRegistry.execute();
}
});
zkTestServer = new ZooKeeperTestServer(0, shutdownRegistry, defaultSessionTimeout);
zkTestServer.startNetwork();
}
use of com.google.common.testing.TearDown in project commons by twitter.
the class ThriftFactoryTest method testCreate.
@Test
public void testCreate() throws Exception {
final AtomicReference<Socket> clientConnection = new AtomicReference<Socket>();
final CountDownLatch connected = new CountDownLatch(1);
final ServerSocket server = new ServerSocket(0);
Thread service = new Thread(new Runnable() {
@Override
public void run() {
try {
clientConnection.set(server.accept());
} catch (IOException e) {
LOG.log(Level.WARNING, "Problem accepting a connection to thrift server", e);
} finally {
connected.countDown();
}
}
});
service.setDaemon(true);
service.start();
try {
final Thrift<GoodService.Iface> thrift = ThriftFactory.create(GoodService.Iface.class).withMaxConnectionsPerEndpoint(1).build(ImmutableSet.of(new InetSocketAddress(server.getLocalPort())));
addTearDown(new TearDown() {
@Override
public void tearDown() {
thrift.close();
}
});
GoodService.Iface client = thrift.create();
assertEquals(GoodService.DONE, client.doWork());
} finally {
connected.await();
server.close();
}
Socket socket = clientConnection.get();
assertNotNull(socket);
socket.close();
}
use of com.google.common.testing.TearDown in project commons by twitter.
the class ThriftFactoryTest method testCreateEmpty.
@Test(expected = TResourceExhaustedException.class)
public void testCreateEmpty() throws Exception {
@SuppressWarnings("unchecked") DynamicHostSet<ServiceInstance> emptyHostSet = control.createMock(DynamicHostSet.class);
final Thrift<GoodService.Iface> thrift = ThriftFactory.create(GoodService.Iface.class).withMaxConnectionsPerEndpoint(1).build(emptyHostSet);
addTearDown(new TearDown() {
@Override
public void tearDown() {
thrift.close();
}
});
GoodService.Iface client = thrift.create();
// This should throw a TResourceExhaustedException
client.doWork();
}
use of com.google.common.testing.TearDown in project commons by twitter.
the class DeadlineCallerTest method makeDeadline.
private DeadlineCaller makeDeadline(final boolean shouldTimeOut) {
final CountDownLatch cancelled = new CountDownLatch(1);
if (shouldTimeOut) {
addTearDown(new TearDown() {
@Override
public void tearDown() throws Exception {
// This will block forever if cancellation does not occur and interrupt the ~indefinite
// sleep.
cancelled.await();
}
});
}
Caller sleepyCaller = new CallerDecorator(caller, false) {
@Override
public Object call(Method method, Object[] args, @Nullable AsyncMethodCallback callback, @Nullable Amount<Long, Time> connectTimeoutOverride) throws Throwable {
if (shouldTimeOut) {
try {
Thread.sleep(Long.MAX_VALUE);
fail("Expected late work to be cancelled and interrupted");
} catch (InterruptedException e) {
cancelled.countDown();
}
}
return caller.call(method, args, callback, connectTimeoutOverride);
}
};
return new DeadlineCaller(sleepyCaller, false, executorService, DEADLINE);
}
use of com.google.common.testing.TearDown in project commons by twitter.
the class ExceptionHandlingExecutorServiceTest method setUp.
@Before
public void setUp() throws Exception {
signallingHandler = createMock(Thread.UncaughtExceptionHandler.class);
executorService = MoreExecutors.exceptionHandlingExecutor(Executors.newCachedThreadPool(new ThreadFactoryBuilder().setNameFormat("ExceptionHandlingExecutorServiceTest-%d").build()), signallingHandler);
final ExecutorServiceShutdown executorServiceShutdown = new ExecutorServiceShutdown(executorService, Amount.of(3L, Time.SECONDS));
addTearDown(new TearDown() {
@Override
public void tearDown() throws Exception {
executorServiceShutdown.execute();
}
});
}
Aggregations