2012-02-28 21:11:51 +00:00
|
|
|
/*
|
|
|
|
* blsm_client.cpp
|
|
|
|
*
|
|
|
|
* Copyright 2009-2012 Yahoo! Inc.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*
|
|
|
|
*/
|
2011-08-23 00:10:43 +00:00
|
|
|
#include "MapKeeper.h"
|
2011-05-11 22:27:48 +00:00
|
|
|
#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));
|
|
|
|
|
2011-08-23 00:10:43 +00:00
|
|
|
mapkeeper::MapKeeperClient client(protocol);
|
2011-05-11 22:27:48 +00:00
|
|
|
transport->open();
|
|
|
|
socket->setNoDelay(true);
|
2011-08-23 00:10:43 +00:00
|
|
|
mapkeeper::BinaryResponse getResponse;
|
|
|
|
mapkeeper::RecordListResponse scanResponse;
|
2011-05-12 20:41:18 +00:00
|
|
|
std::string db = "db";
|
|
|
|
std::string db1 = "db1";
|
2011-08-23 00:10:43 +00:00
|
|
|
cout << client.addMap(db) << endl;;
|
2011-05-12 20:41:18 +00:00
|
|
|
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;
|
2011-08-23 00:10:43 +00:00
|
|
|
cout << client.addMap(db) << endl;;
|
2011-05-13 06:53:39 +00:00
|
|
|
|
2011-08-23 00:10:43 +00:00
|
|
|
cout << client.addMap(db1) << endl;;
|
2011-05-13 06:53:39 +00:00
|
|
|
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-08-23 00:10:43 +00:00
|
|
|
client.scan(scanResponse, db, mapkeeper::ScanOrder::Ascending, "", true, "", true, 100, 100);
|
|
|
|
std::vector<mapkeeper::Record>::iterator itr;
|
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;
|
|
|
|
|
|
|
|
|
2011-08-23 00:10:43 +00:00
|
|
|
client.scan(scanResponse, db, mapkeeper::ScanOrder::Ascending, "kkkkkkkkkkkkk1", false, "kkkkkkkkkkkkk3", false, 100, 100);
|
2011-05-12 20:41:18 +00:00
|
|
|
for (itr = scanResponse.records.begin(); itr != scanResponse.records.end(); itr++) {
|
|
|
|
cout << itr->key << " " << itr->value << endl;
|
|
|
|
}
|
|
|
|
std::cout << std::endl;
|
|
|
|
|
2011-08-23 00:10:43 +00:00
|
|
|
client.scan(scanResponse, db, mapkeeper::ScanOrder::Ascending, "kkkkkkkkkkkkk1", true, "kkkkkkkkkkkkk3", true, 100, 100);
|
2011-05-12 20:41:18 +00:00
|
|
|
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-08-23 00:10:43 +00:00
|
|
|
client.scan(scanResponse, db, mapkeeper::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;
|
|
|
|
|
2011-08-23 00:10:43 +00:00
|
|
|
client.scan(scanResponse, db, mapkeeper::ScanOrder::Ascending, "k", true, "kkkkkkkkkkkkk4", true, 100, 100);
|
2011-05-12 20:41:18 +00:00
|
|
|
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;
|
|
|
|
}
|