ModeShape/modeshape — pull request #574 by rhauch (2012-10-16 22:13:32+00:00)
Title: MODE-1674 Corrected several issues with backup/restore, the JSON reader/writer, and tests

Changed the backup and restore tests to use file-based persisted repositories rather than in-memory repositories. When the repositories are restarted during the restore process, restarting an in-memory repository (and cache) loses all data that was successfully restored.

One issue with the backup and restore process was that, even upon restore, the RepositoryCache's sourceKey and repositoryKey were generated from the configuration's name and cache name. So if the restored repository had a different name than the backup or the repository's cache was named something different, the restored repository would never find the top-level nodes in the workspaces, and the restored repository would appear to contain no content (even though the cache actually did contain all the restored entries). This was corrected by using a new "repository:info" document with metadata about the repository, including the source name and key, the cache name, the repository name and key, the date the repository was created, and the version of ModeShape that was used to create the repository. Because this "repository:info" document is stored in the cache (with a well-known key), the document is included in the backups and the document can be found upon restore. Note that 3.0.0.Final (and later) will create this "repository:info" document if not found, so any pre-3.0.0.Final repository would have to be at least started using 3.0.0.Final (or later) before a backup can be created.

Also discovered and fixed several other issues in the way backups were being read. One of these had to do with escaped characters in JSON field values (which were not being processed correctly), and that documents written to JSON were not properly escaping quotes and control characters that appeared *within* string values. Finally, the JSON reader code (that was added for restore) that read a file containing multiple JSON documents was not correctly handling the end of the stream.

After all these changes, a full build completes successfully.