Skip to content

Commit

Permalink
Add a Reset command to the SimpleDB simulator, useful in tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
qris committed Jan 4, 2016
1 parent 6f596f8 commit 6eda839
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
25 changes: 21 additions & 4 deletions lib/httpserver/S3Simulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,12 @@ SimpleDBSimulator::SimpleDBSimulator()
: mDomainsFile("testfiles/domains.qdbm"),
mItemsFile("testfiles/items.qdbm")
{
// Open the database file
int mode = DP_OWRITER | DP_OCREAT;
Open(DP_OWRITER | DP_OCREAT);
}

// Open the database file
void SimpleDBSimulator::Open(int mode)
{
mpDomains = dpopen(mDomainsFile.c_str(), mode, 0);
if(!mpDomains)
{
Expand All @@ -62,8 +65,12 @@ SimpleDBSimulator::SimpleDBSimulator()
}
}


SimpleDBSimulator::~SimpleDBSimulator()
{
Close();
}

void SimpleDBSimulator::Close()
{
if(mpDomains && !dpclose(mpDomains))
{
Expand Down Expand Up @@ -513,7 +520,7 @@ void S3Simulator::HandleSimpleDBGet(HTTPRequest &rRequest, HTTPResponse &rRespon
rResponse.SetResponseCode(HTTPResponse::Code_OK);

std::string domain;
if(action != "ListDomains")
if(action != "ListDomains" && action != "Reset")
{
domain = rRequest.GetParameterString("DomainName");
}
Expand Down Expand Up @@ -736,6 +743,11 @@ void S3Simulator::HandleSimpleDBGet(HTTPRequest &rRequest, HTTPResponse &rRespon
attribute);
}
}
else if(action == "Reset")
{
simpledb.Reset();
response_tree.add("ResetResponse", "");
}
else
{
rResponse.SetResponseCode(HTTPResponse::Code_NotFound);
Expand Down Expand Up @@ -821,6 +833,11 @@ std::vector<std::string> SimpleDBSimulator::ListDomains()
return domains;
}

void SimpleDBSimulator::Reset()
{
Close();
Open(DP_OWRITER | DP_OCREAT | DP_OTRUNC);
}

void SimpleDBSimulator::CreateDomain(const std::string& domain_name)
{
Expand Down
3 changes: 3 additions & 0 deletions lib/httpserver/S3Simulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,11 @@ class SimpleDBSimulator
const std::string& domain_name,
const std::string& item_name,
bool throw_if_not_found = true);
void Reset();

protected:
void Open(int mode);
void Close();
boost::property_tree::ptree GetDomainProps(const std::string& domain_name);
void PutDomainProps(const std::string& domain_name,
const boost::property_tree::ptree domain_props);
Expand Down
9 changes: 9 additions & 0 deletions test/httpserver/testhttpserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,15 @@ int test(int argc, const char *argv[])
expected_attrs.insert(attr_t("Color", "Green"));
expected_attrs.insert(attr_t("Size", "Large"));
TEST_THAT(simpledb_get_attributes(access_key, secret_key, expected_attrs));

// Reset for the next test
request.SetParameter("Action", "Reset");
TEST_THAT(add_simpledb_signature(request, secret_key));
TEST_THAT(send_and_receive_xml(request, response_tree,
"ResetResponse"));
domains = simpledb_list_domains(access_key, secret_key);
expected_domains.clear();
TEST_THAT(compare_lists(expected_domains, domains));
}

// Kill it
Expand Down

0 comments on commit 6eda839

Please sign in to comment.