Search in sources :

Example 1 with TearDown

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();
}
Also used : TearDown(com.google.common.testing.TearDown) Override(java.lang.Override)

Example 2 with TearDown

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();
        }
    });
}
Also used : TearDown(com.google.common.testing.TearDown) IllegalArgumentException(java.lang.IllegalArgumentException) Exception(java.lang.Exception) NullPointerException(java.lang.NullPointerException) ExecutionException(java.util.concurrent.ExecutionException) Before(org.junit.Before)

Example 3 with TearDown

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]);
}
Also used : TearDown(com.google.common.testing.TearDown) AsyncIface(com.twitter.common.thrift.ThriftFactoryTest.GoodService.AsyncIface) InetSocketAddress(java.net.InetSocketAddress) AsyncIface(com.twitter.common.thrift.ThriftFactoryTest.GoodService.AsyncIface) CountDownLatch(java.util.concurrent.CountDownLatch) AsyncMethodCallback(org.apache.thrift.async.AsyncMethodCallback) Test(org.junit.Test)

Example 4 with TearDown

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();
        }
    });
}
Also used : TearDown(com.google.common.testing.TearDown) Before(org.junit.Before)

Example 5 with TearDown

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() + "/";
}
Also used : Context(org.mortbay.jetty.servlet.Context) TearDown(com.google.common.testing.TearDown) Server(org.mortbay.jetty.Server) ServletHolder(org.mortbay.jetty.servlet.ServletHolder) SocketConnector(org.mortbay.jetty.bio.SocketConnector) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Aggregations

TearDown (com.google.common.testing.TearDown)16 Before (org.junit.Before)6 AsyncIface (com.twitter.common.thrift.ThriftFactoryTest.GoodService.AsyncIface)3 IOException (java.io.IOException)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 Test (org.junit.Test)3 InetSocketAddress (java.net.InetSocketAddress)2 ExecutionException (java.util.concurrent.ExecutionException)2 AsyncMethodCallback (org.apache.thrift.async.AsyncMethodCallback)2 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 ShutdownRegistryImpl (com.twitter.common.application.ShutdownRegistry.ShutdownRegistryImpl)1 ExceptionalCommand (com.twitter.common.base.ExceptionalCommand)1 Temporary (com.twitter.common.io.FileUtils.Temporary)1 Amount (com.twitter.common.quantity.Amount)1 TTimeoutException (com.twitter.common.thrift.TTimeoutException)1 JoinException (com.twitter.common.zookeeper.Group.JoinException)1 Partition (com.twitter.common.zookeeper.Partitioner.Partition)1 EndpointStatus (com.twitter.common.zookeeper.ServerSet.EndpointStatus)1 LeadershipListener (com.twitter.common.zookeeper.SingletonService.LeadershipListener)1 ServiceInstance (com.twitter.thrift.ServiceInstance)1