Search in sources :

Example 6 with TearDown

use of com.google.common.testing.TearDown in project commons by twitter.

the class FileUtilsTest method setUp.

@Before
public void setUp() {
    final File tmpDir = FileUtils.createTempDir();
    addTearDown(new TearDown() {

        @Override
        public void tearDown() throws Exception {
            org.apache.commons.io.FileUtils.deleteDirectory(tmpDir);
        }
    });
    assertEmptyDir(tmpDir);
    temporary = new Temporary(tmpDir);
}
Also used : TearDown(com.google.common.testing.TearDown) Temporary(com.twitter.common.io.FileUtils.Temporary) File(java.io.File) IOException(java.io.IOException) Before(org.junit.Before)

Example 7 with TearDown

use of com.google.common.testing.TearDown in project commons by twitter.

the class SingletonServiceTest method mySetUp.

@Before
@SuppressWarnings("unchecked")
public void mySetUp() throws IOException {
    control = createControl();
    addTearDown(new TearDown() {

        @Override
        public void tearDown() {
            control.verify();
        }
    });
    listener = control.createMock(SingletonService.LeadershipListener.class);
    serverSet = control.createMock(ServerSet.class);
    candidate = control.createMock(Candidate.class);
    endpointStatus = control.createMock(ServerSet.EndpointStatus.class);
    abdicate = control.createMock(ExceptionalCommand.class);
    service = new SingletonService(serverSet, candidate);
}
Also used : EndpointStatus(com.twitter.common.zookeeper.ServerSet.EndpointStatus) TearDown(com.google.common.testing.TearDown) ExceptionalCommand(com.twitter.common.base.ExceptionalCommand) LeadershipListener(com.twitter.common.zookeeper.SingletonService.LeadershipListener) Before(org.junit.Before)

Example 8 with TearDown

use of com.google.common.testing.TearDown in project guava by google.

the class UninterruptibleFutureTest method setUp.

@Override
protected void setUp() {
    final ExecutorService executor = Executors.newSingleThreadExecutor();
    tearDownStack.addTearDown(new TearDown() {

        @Override
        public void tearDown() {
            executor.shutdownNow();
        }
    });
    sleeper = new SleepingRunnable(1000);
    delayedFuture = executor.submit(sleeper, true);
    tearDownStack.addTearDown(new TearDown() {

        @Override
        public void tearDown() {
            Thread.interrupted();
        }
    });
}
Also used : TearDown(com.google.common.testing.TearDown) ExecutorService(java.util.concurrent.ExecutorService)

Example 9 with TearDown

use of com.google.common.testing.TearDown in project guava by google.

the class InterruptionUtil method repeatedlyInterruptTestThread.

static void repeatedlyInterruptTestThread(long interruptPeriodMillis, TearDownAccepter tearDownAccepter) {
    final Interruptenator interruptingTask = new Interruptenator(Thread.currentThread(), interruptPeriodMillis);
    final Thread interruptingThread = new Thread(interruptingTask);
    interruptingThread.start();
    tearDownAccepter.addTearDown(new TearDown() {

        @Override
        public void tearDown() throws Exception {
            interruptingTask.stopInterrupting();
            interruptingThread.interrupt();
            joinUninterruptibly(interruptingThread, 2500, MILLISECONDS);
            Thread.interrupted();
            if (interruptingThread.isAlive()) {
                // This will be hidden by test-output redirection:
                logger.severe("InterruptenatorTask did not exit; future tests may be affected");
                /*
           * This won't do any good under JUnit 3, but I'll leave it around in
           * case we ever switch to JUnit 4:
           */
                fail();
            }
        }
    });
}
Also used : TearDown(com.google.common.testing.TearDown)

Example 10 with TearDown

use of com.google.common.testing.TearDown in project guava by hceylan.

the class InterruptionUtil method repeatedlyInterruptTestThread.

static void repeatedlyInterruptTestThread(long interruptPeriodMillis, TearDownAccepter tearDownAccepter) {
    final Interruptenator interruptingTask = new Interruptenator(Thread.currentThread(), interruptPeriodMillis);
    final Thread interruptingThread = new Thread(interruptingTask);
    interruptingThread.start();
    tearDownAccepter.addTearDown(new TearDown() {

        @Override
        public void tearDown() throws Exception {
            interruptingTask.stopInterrupting();
            interruptingThread.interrupt();
            joinUninterruptibly(interruptingThread, 2500, MILLISECONDS);
            Thread.interrupted();
            if (interruptingThread.isAlive()) {
                // This will be hidden by test-output redirection:
                logger.severe("InterruptenatorTask did not exit; future tests may be affected");
                /*
           * This won't do any good under JUnit 3, but I'll leave it around in
           * case we ever switch to JUnit 4:
           */
                fail();
            }
        }
    });
}
Also used : TearDown(com.google.common.testing.TearDown)

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