Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/Commands.cc
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ SharedBuffer Commands::newConnect(const AuthenticationPtr& authentication, const
BaseCommand cmd;
cmd.set_type(BaseCommand::CONNECT);
CommandConnect* connect = cmd.mutable_connect();
connect->set_client_version(PULSAR_VERSION_STR);
connect->set_client_version(std::string("Pulsar-CPP-v") + PULSAR_VERSION_STR);
connect->set_auth_method_name(authentication->getAuthMethodName());
connect->set_protocol_version(ProtocolVersion_MAX);

Expand Down Expand Up @@ -294,7 +294,7 @@ SharedBuffer Commands::newAuthResponse(const AuthenticationPtr& authentication,
BaseCommand cmd;
cmd.set_type(BaseCommand::AUTH_RESPONSE);
CommandAuthResponse* authResponse = cmd.mutable_authresponse();
authResponse->set_client_version(PULSAR_VERSION_STR);
authResponse->set_client_version(std::string("Pulsar-CPP-v") + PULSAR_VERSION_STR);

AuthData* authData = authResponse->mutable_response();
authData->set_auth_method_name(authentication->getAuthMethodName());
Expand Down
33 changes: 33 additions & 0 deletions tests/ClientTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
#include <gtest/gtest.h>
#include <pulsar/Client.h>
#include <pulsar/Version.h>

#include <chrono>
#include <future>
Expand All @@ -34,6 +35,7 @@ DECLARE_LOG_OBJECT()
using namespace pulsar;

static std::string lookupUrl = "pulsar://localhost:6650";
static std::string adminUrl = "http://localhost:8080/";

TEST(ClientTest, testChecksumComputation) {
std::string data = "test";
Expand Down Expand Up @@ -308,3 +310,34 @@ TEST(ClientTest, testCloseClient) {
client.close();
}
}

TEST(ClientTest, testClientVersion) {
const std::string topic = "testClientVersion" + std::to_string(time(nullptr));
const std::string expectedVersion = std::string("Pulsar-CPP-v") + PULSAR_VERSION_STR;

Client client(lookupUrl);

std::string responseData;

Producer producer;
Result result = client.createProducer(topic, producer);
ASSERT_EQ(ResultOk, result);
int res =
makeGetRequest(adminUrl + "admin/v2/persistent/public/default/" + topic + "/stats", responseData);
ASSERT_TRUE(res == 200) << "res: " << res;

ASSERT_TRUE(responseData.find(expectedVersion) != std::string::npos);
producer.close();

responseData.clear();
Consumer consumer;
result = client.subscribe(topic, "consumer-1", consumer);
ASSERT_EQ(ResultOk, result);
res = makeGetRequest(adminUrl + "admin/v2/persistent/public/default/" + topic + "/stats", responseData);
ASSERT_TRUE(res == 200) << "res: " << res;

ASSERT_TRUE(responseData.find(expectedVersion) != std::string::npos);
consumer.close();

client.close();
}
25 changes: 21 additions & 4 deletions tests/HttpHelper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@

#include <curl/curl.h>

static int makeRequest(const std::string& method, const std::string& url, const std::string& body) {
static size_t curlWriteCallback(void* contents, size_t size, size_t nmemb, void* responseDataPtr) {
((std::string*)responseDataPtr)->append((char*)contents, size * nmemb);
return size * nmemb;
}

static int makeRequest(const std::string& method, const std::string& url, const std::string& body,
const std::string& responseData) {
CURL* curl = curl_easy_init();

struct curl_slist* list = NULL;
Expand All @@ -33,6 +39,11 @@ static int makeRequest(const std::string& method, const std::string& url, const
if (!body.empty()) {
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, body.c_str());
}

// Write callback
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curlWriteCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &responseData);

int res = curl_easy_perform(curl);
curl_slist_free_all(list); /* free the list again */

Expand All @@ -46,10 +57,16 @@ static int makeRequest(const std::string& method, const std::string& url, const
return (int)httpResult;
}

int makePutRequest(const std::string& url, const std::string& body) { return makeRequest("PUT", url, body); }
int makePutRequest(const std::string& url, const std::string& body) {
return makeRequest("PUT", url, body, "");
}

int makePostRequest(const std::string& url, const std::string& body) {
return makeRequest("POST", url, body);
return makeRequest("POST", url, body, "");
}

int makeDeleteRequest(const std::string& url) { return makeRequest("DELETE", url, ""); }
int makeDeleteRequest(const std::string& url) { return makeRequest("DELETE", url, "", ""); }

int makeGetRequest(const std::string& url, const std::string& responseData) {
return makeRequest("GET", url, "", responseData);
}
1 change: 1 addition & 0 deletions tests/HttpHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@
int makePutRequest(const std::string& url, const std::string& body);
int makePostRequest(const std::string& url, const std::string& body);
int makeDeleteRequest(const std::string& url);
int makeGetRequest(const std::string& url, const std::string& responseData);

#endif /* end of include guard: HTTP_HELPER */