How about, instead of running before and after the class, you run it
before and after "everything", by using a GuiceBerryEnvMain? Something
like:
@Provides
static GuiceBerryEnvMain buildGuiceBerryEnvMain (final
SearchIndexInterface indexInterface) {
@Override
public void run() {
indexInterface.clearIndex();
Thread shutdownThread = new Thread() {
@Override
public void run() {
indexInterface.shutdownIndexer();
}
};
Runtime.getRuntime().addShutdownHook(shutdownThread);
}
}
> --
> You received this message because you are subscribed to the Google Groups "guiceberry-users" group.
> To post to this group, send email to guiceber...@googlegroups.com.
> To unsubscribe from this group, send email to guiceberry-use...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/guiceberry-users?hl=en.
>
There are hacky ways to accomplish something like what you are talking
about, but before we rathole into this hacky discussion, let me
suggest what I would try to do.
If I understand the problem as you stated, you have a
SearchIndexInterface that is:
a. too expensive/slow to setup/teardown for every test
b. needs exclusive access to files/server sockets/etc
If you can't solve "a" (i.e. make it cheap so you setup and teardown
on every test), I'd suggest that you make the files/sockets/etc that
it acquires not be hard-coded.
E.g. if it binds to a socket port, make it pick a random (unused)
port, rather than hardcode a number (guiceberry would be the one
picking the random port, since it would need to know which port it is
to connect to it, which should be simple/trivial to do).
Likewise, say it needs to write to a data file "data/index.dbx". If
you adapt your production code to accept a root directory (again, that
guiceberry can pick), you could have each GBE create one with a
certain (random) root (ending up with, say
/tmp/testdatafor-<random>/data/index.dbx).
Another upshot of doing this would be that you could run multiple of
the same test suite at the same time in the same computer.
Let me know what you think,
Z
> Not using the providers is not an option, so I need some way to call
> stop methods and then destroy these classes.
>
> Many thanks,
>