2011-05-11 22:27:48 +00:00
|
|
|
#include <dht_persistent_store/PersistentStore.h>
|
|
|
|
#include <transport/TSocket.h>
|
|
|
|
#include <transport/TBufferTransports.h>
|
|
|
|
#include <protocol/TBinaryProtocol.h>
|
|
|
|
#include <iostream>
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
using namespace apache::thrift;
|
|
|
|
using namespace apache::thrift::protocol;
|
|
|
|
using namespace apache::thrift::transport;
|
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
|
|
|
boost::shared_ptr<TSocket> socket(new TSocket("localhost", 9090));
|
|
|
|
boost::shared_ptr<TTransport> transport(new TFramedTransport(socket));
|
|
|
|
boost::shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));
|
|
|
|
|
|
|
|
sherpa::PersistentStoreClient client(protocol);
|
|
|
|
transport->open();
|
|
|
|
socket->setNoDelay(true);
|
|
|
|
sherpa::BinaryResponse getResponse;
|
|
|
|
sherpa::RecordListResponse scanResponse;
|
2011-05-12 20:41:18 +00:00
|
|
|
std::string db = "db";
|
|
|
|
std::string db1 = "db1";
|
|
|
|
cout << client.addDatabase(db) << endl;;
|
|
|
|
cout << client.insert(db, "kkkkkkkkkkkkk1", "v1") << endl;
|
|
|
|
cout << client.insert(db, "kkkkkkkkkkkkk2", "v2") << endl;
|
|
|
|
cout << client.insert(db, "kkkkkkkkkkkkk3", "v3") << endl;
|
|
|
|
client.get(getResponse, db, "kkkkkkkkkkkkk1");
|
|
|
|
cout << getResponse.responseCode << endl;
|
|
|
|
cout << getResponse.value << endl;
|
|
|
|
client.get(getResponse, db, "kkkkkkkkkkkkk2");
|
|
|
|
cout << getResponse.responseCode << endl;
|
|
|
|
cout << getResponse.value << endl;
|
|
|
|
client.get(getResponse, db, "kkkkkkkkkkkkk3");
|
|
|
|
cout << getResponse.responseCode << endl;
|
|
|
|
cout << getResponse.value << endl;
|
2011-05-11 22:27:48 +00:00
|
|
|
|
2011-05-12 20:41:18 +00:00
|
|
|
cout << client.update(db, "k0", "v11") << endl;
|
|
|
|
cout << client.update(db, "kkkkkkkkkkkkk1", "v11") << endl;
|
|
|
|
cout << client.update(db, "kkkkkkkkkkkkk2", "v12") << endl;
|
|
|
|
cout << client.update(db, "kkkkkkkkkkkkk3", "v13") << endl;
|
|
|
|
client.get(getResponse, db, "kkkkkkkkkkkkk1");
|
2011-05-12 00:30:02 +00:00
|
|
|
cout << getResponse.responseCode << endl;
|
|
|
|
cout << getResponse.value << endl;
|
2011-05-12 20:41:18 +00:00
|
|
|
client.get(getResponse, db, "kkkkkkkkkkkkk2");
|
2011-05-11 22:27:48 +00:00
|
|
|
cout << getResponse.responseCode << endl;
|
|
|
|
cout << getResponse.value << endl;
|
2011-05-12 20:41:18 +00:00
|
|
|
client.get(getResponse, db, "kkkkkkkkkkkkk3");
|
2011-05-12 00:30:02 +00:00
|
|
|
cout << getResponse.responseCode << endl;
|
|
|
|
cout << getResponse.value << endl;
|
|
|
|
|
2011-05-12 20:41:18 +00:00
|
|
|
/*
|
|
|
|
client.get(getResponse, "fdsafdasfdasfdsaf", "kkkkkkkkkkkkk3");
|
2011-05-12 00:30:02 +00:00
|
|
|
cout << getResponse.responseCode << endl;
|
|
|
|
|
2011-05-12 20:41:18 +00:00
|
|
|
client.get(getResponse, db, "k4");
|
2011-05-12 00:30:02 +00:00
|
|
|
cout << getResponse.responseCode << endl;
|
2011-05-12 20:41:18 +00:00
|
|
|
*/
|
2011-05-12 00:30:02 +00:00
|
|
|
|
2011-05-13 06:53:39 +00:00
|
|
|
cout << "adding db one more time" << endl;
|
|
|
|
cout << client.addDatabase(db) << endl;;
|
|
|
|
|
|
|
|
cout << client.addDatabase(db1) << endl;;
|
|
|
|
cout << client.insert(db1, "new key", "new value") << endl;
|
|
|
|
client.get(getResponse, db1, "new key");
|
|
|
|
cout << getResponse.responseCode << endl;
|
|
|
|
cout << getResponse.value << endl;
|
|
|
|
|
|
|
|
client.get(getResponse, db, "new key");
|
|
|
|
cout << getResponse.responseCode << endl;
|
|
|
|
cout << getResponse.value << endl;
|
|
|
|
|
|
|
|
cout << client.remove(db1, "new key") << endl;
|
|
|
|
client.get(getResponse, db1, "new key");
|
|
|
|
cout << getResponse.responseCode << endl;
|
|
|
|
cout << client.remove(db1, "new key") << endl;
|
2011-05-11 22:27:48 +00:00
|
|
|
|
2011-05-12 20:41:18 +00:00
|
|
|
client.scan(scanResponse, db, sherpa::ScanOrder::Ascending, "", true, "", true, 100, 100);
|
2011-05-11 22:27:48 +00:00
|
|
|
std::vector<sherpa::Record>::iterator itr;
|
|
|
|
for (itr = scanResponse.records.begin(); itr != scanResponse.records.end(); itr++) {
|
|
|
|
cout << itr->key << " " << itr->value << endl;
|
|
|
|
}
|
2011-05-12 20:41:18 +00:00
|
|
|
std::cout << std::endl;
|
|
|
|
|
|
|
|
|
|
|
|
client.scan(scanResponse, db, sherpa::ScanOrder::Ascending, "kkkkkkkkkkkkk1", false, "kkkkkkkkkkkkk3", false, 100, 100);
|
|
|
|
for (itr = scanResponse.records.begin(); itr != scanResponse.records.end(); itr++) {
|
|
|
|
cout << itr->key << " " << itr->value << endl;
|
|
|
|
}
|
|
|
|
std::cout << std::endl;
|
|
|
|
|
|
|
|
client.scan(scanResponse, db, sherpa::ScanOrder::Ascending, "kkkkkkkkkkkkk1", true, "kkkkkkkkkkkkk3", true, 100, 100);
|
|
|
|
for (itr = scanResponse.records.begin(); itr != scanResponse.records.end(); itr++) {
|
|
|
|
cout << itr->key << " " << itr->value << endl;
|
|
|
|
}
|
|
|
|
std::cout << std::endl;
|
2011-05-11 22:27:48 +00:00
|
|
|
|
2011-05-12 20:41:18 +00:00
|
|
|
client.scan(scanResponse, db, sherpa::ScanOrder::Ascending, "kkkkkkkkkkkkk2", true, "kkkkkkkkkkkkk2", true, 100, 100);
|
2011-05-11 22:27:48 +00:00
|
|
|
for (itr = scanResponse.records.begin(); itr != scanResponse.records.end(); itr++) {
|
|
|
|
cout << itr->key << " " << itr->value << endl;
|
|
|
|
}
|
2011-05-12 20:41:18 +00:00
|
|
|
std::cout << std::endl;
|
|
|
|
|
|
|
|
client.scan(scanResponse, db, sherpa::ScanOrder::Ascending, "k", true, "kkkkkkkkkkkkk4", true, 100, 100);
|
|
|
|
for (itr = scanResponse.records.begin(); itr != scanResponse.records.end(); itr++) {
|
|
|
|
cout << itr->key << " " << itr->value << endl;
|
|
|
|
}
|
2011-05-11 22:27:48 +00:00
|
|
|
return 0;
|
|
|
|
}
|