Fixed duplicate messages when topic store overrun.
- Added unit tests

#1973