Compiling and tests pass w/ source state

Finish adding support for per-datasource state and update the tests to
let them all compile and pass as they used to. The next step is to
refactor all this to initialise and finalise the state when the system
starts and stops.