Added BlockStore::numBlocks()

This commit is contained in:
Sebastian Messmer 2015-02-23 21:07:07 +01:00
parent aeec8b1490
commit f491d3d183
8 changed files with 18 additions and 0 deletions

View File

@ -43,5 +43,9 @@ void InMemoryBlockStore::remove(unique_ptr<Block> block) {
assert(1==numRemoved); assert(1==numRemoved);
} }
uint64_t InMemoryBlockStore::numBlocks() const {
return _blocks.size();
}
} }
} }

View File

@ -19,6 +19,7 @@ public:
std::unique_ptr<Block> create(const Key &key, size_t size) override; std::unique_ptr<Block> create(const Key &key, size_t size) override;
std::unique_ptr<Block> load(const Key &key) override; std::unique_ptr<Block> load(const Key &key) override;
void remove(std::unique_ptr<Block> block) override; void remove(std::unique_ptr<Block> block) override;
uint64_t numBlocks() const override;
private: private:
std::map<std::string, InMemoryBlock> _blocks; std::map<std::string, InMemoryBlock> _blocks;

View File

@ -34,5 +34,9 @@ void OnDiskBlockStore::remove(unique_ptr<Block> block) {
OnDiskBlock::RemoveFromDisk(_rootdir, key); OnDiskBlock::RemoveFromDisk(_rootdir, key);
} }
uint64_t OnDiskBlockStore::numBlocks() const {
return std::distance(bf::directory_iterator(_rootdir), bf::directory_iterator());
}
} }
} }

View File

@ -19,6 +19,7 @@ public:
std::unique_ptr<Block> create(const Key &key, size_t size) override; std::unique_ptr<Block> create(const Key &key, size_t size) override;
std::unique_ptr<Block> load(const Key &key) override; std::unique_ptr<Block> load(const Key &key) override;
void remove(std::unique_ptr<Block> block) override; void remove(std::unique_ptr<Block> block) override;
uint64_t numBlocks() const override;
private: private:
const boost::filesystem::path _rootdir; const boost::filesystem::path _rootdir;

View File

@ -55,5 +55,9 @@ void FakeBlockStore::updateData(const Key &key, const Data &data) {
std::memcpy(stored_data.data(), data.data(), data.size()); std::memcpy(stored_data.data(), data.data(), data.size());
} }
uint64_t FakeBlockStore::numBlocks() const {
return _blocks.size();
}
} }
} }

View File

@ -34,6 +34,7 @@ public:
std::unique_ptr<Block> create(const Key &key, size_t size) override; std::unique_ptr<Block> create(const Key &key, size_t size) override;
std::unique_ptr<Block> load(const Key &key) override; std::unique_ptr<Block> load(const Key &key) override;
void remove(std::unique_ptr<Block> block) override; void remove(std::unique_ptr<Block> block) override;
uint64_t numBlocks() const override;
void updateData(const Key &key, const Data &data); void updateData(const Key &key, const Data &data);

View File

@ -20,6 +20,8 @@ public:
// Return nullptr if block with this key doesn't exists // Return nullptr if block with this key doesn't exists
virtual std::unique_ptr<Block> load(const Key &key) = 0; virtual std::unique_ptr<Block> load(const Key &key) = 0;
virtual void remove(std::unique_ptr<Block> block) = 0; virtual void remove(std::unique_ptr<Block> block) = 0;
virtual uint64_t numBlocks() const = 0;
//TODO Test numBlocks
}; };
} }

View File

@ -25,6 +25,7 @@ public:
} }
MOCK_METHOD1(do_load, Block*(const Key &)); MOCK_METHOD1(do_load, Block*(const Key &));
void remove(unique_ptr<Block> block) {} void remove(unique_ptr<Block> block) {}
MOCK_CONST_METHOD0(numBlocks, uint64_t());
}; };
class BlockMock: public Block { class BlockMock: public Block {