artefactual / archivematica-storage-service

Archivematica storage service
http://www.archivematica.org
GNU Affero General Public License v3.0
34 stars 43 forks source link

Problem: filesystem and database are not treated as injectable dependencies #249

Open jrwdunham opened 7 years ago

jrwdunham commented 7 years ago

The storage service contains pervasive calls to filesystem APIs (os, sys, shutil) and database APIs (Django models, Elasticsearch). If classes like package.py::Package explicitly declared dependencies on objects (say fs or db) and the APIs they required, then those dependencies could more easily be swapped out in different environments, e.g., during testing or when digital objects are accessed not from a Unix filesystem but from an S3 store.

One immediate benefit of such a refactoring would be that unit and functional tests could be made to run much more quickly. If instead of creating test databases and test directory structures we swapped in mock dependencies, the runtime of these tests could probably be significantly decreased.

The metsrw PR 27 illustrates a strategy for dependency injection that might be applicable here.

Relatedly, this strategy could allow us to clean up the space-related code and make spaces pluggable dependencies, which could allow users to avoid installing unneeded third party dependencies for space types that they never use.

Refactoring SS to include dependency injection could proceed via the StranglerApplication approach/pattern.

jrwdunham commented 7 years ago

Changing the source as per this issue might not even be necessary. It may simply be necessary to improve how we write tests. See https://github.com/artefactual/archivematica/pull/772