More unit tests for storage drivers and a bug fix for memory storage

This PR contains several unit tests. It also contains a bug fix for memory storage. The bug could be reproduced with the newly added unit tests in this PR.
For the in memory storage, yes, we could. For other storage driver, I'm not sure if we should pose this restriction. (Probably, we could provide a function in the storage package to sort stats?)