Skip to content

Instantly share code, notes, and snippets.

@philsquared
Created July 13, 2013 10:18
Show Gist options
  • Save philsquared/5990252 to your computer and use it in GitHub Desktop.
Save philsquared/5990252 to your computer and use it in GitHub Desktop.
struct MaxUsage { int memory, disk; };
TEST_CASE( "KeyValueBuffer disk memory usage" )
{
using namespace Catch::Generators;
MaxUsage params[] = {
{ 1, 2 },
{ 1, 1024 },
{ 8, 1024 },
{ 1024, 2048 },
{ 1024, 1024 },
{ 16, 16 * 1024 },
{ 32, 32 },
{ 1000, 10000 },
{ 10000, 1000000 } };
MaxUsage* maxUsage = GENERATE( between( params, &params[sizeof(params)/sizeof(MaxUsage)-1] ) );
std::unique_ptr<KeyValueBuffer> key_value_buffer_;
SECTION( "BEH_Store" ) {
uint64_t disk_usage(maxUsage->disk), memory_usage(maxUsage->memory),
total_usage(disk_usage + memory_usage);
while (total_usage != 0) {
NonEmptyString value(std::string(RandomAlphaNumericString(
static_cast<uint32_t>(maxUsage->memory))));
Identity key(crypto::Hash<crypto::SHA512>(value));
REQUIRE_NOTHROW(key_value_buffer_->Store(key, value));
NonEmptyString recovered;
REQUIRE_NOTHROW(recovered = key_value_buffer_->Get(key));
REQUIRE(value == recovered);
if (disk_usage != 0) {
disk_usage -= maxUsage->memory;
total_usage -= maxUsage->memory;
} else {
total_usage -= maxUsage->memory;
}
}
}
SECTION( "BEH_Delete" ) { /*...*/ }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment