Fix tests
Lock index while loading a new index to avoid high memory usage

The server had to retain the old index until the new one is loaded.
This should fix that problem by locking the index for both read and
write access and replacing the index.
The old index might still be referenced by an old concurrent read
operation which may prevent it from being free'd.
Fixes #58.