mardi 26 mai 2015

JUnit tests involving unloading classes in the JVM

I'm involved in a project where the application we are developing can be customized and additional features added to it through plugin-jars. When the application launches, it checks the plugins folder for any jars and attempts to load all the classes defined in that jar.

Data generated by the application is stored on disk after serializing through Kryo. Ideally, data generated by one user with one installation of the application should be accessible to another user with another installing of the application. Also ideally, the two users should be able to maintain independent configurations of their installation with independent sets of plugins.

The complication is if any of the data generated by User 1 depends on a particular class defined in one of the plugins that are present on User 1's installation of the application. If User 2 then tries to access that data and the class is not available in their installation, we need to fail gracefully without completely rendering the data inaccessible to User 2.

Our team has been able to design data structures that should, in principle, be able to fail gracefully and not render the data completely inaccessible. However, we'd like to implement some JUnit tests to verify their behavior. To this end, we were hoping there could be some way save generated data to disk, then unload the class definition, and finally attempt to reload the data from disk and verify certain assertions, all in a single JUnit test run.

Is there an elegant way to do this?

As an example, say the application we are developing is a CircusManagement application which generates and saves data about the properties and maintenance of various Troupes. The capabilities of a particular Venue depend on which plugin-jars are included in the installation of the application at that venue. At venue1 the venue manager updates troupe data and saves the data to disk. The troupe is now at venue2 and the venue manager is attempting to load the data from the last venue. However, venue2 doesn't have any OnSiteVetClinic and so can't load any of the data associated with that, but should be able to load all the other data. We need a JUnit test that will simulate the generation of data on disk from venue1 that includes the OnSiteVetClinic data type, and then the loading of that from venue2 that doesn't have that data type.

Aucun commentaire:

Enregistrer un commentaire