diff --git a/pulsar-client-cpp/tests/BasicEndToEndTest.cc b/pulsar-client-cpp/tests/BasicEndToEndTest.cc index 61be84b92dd98d7a45a467bec155de963f512216..7241b5b58ca5b71c08e8a5072103701aa978cdc0 100644 --- a/pulsar-client-cpp/tests/BasicEndToEndTest.cc +++ b/pulsar-client-cpp/tests/BasicEndToEndTest.cc @@ -354,13 +354,12 @@ TEST(BasicEndToEndTest, testPartitionedProducerConsumer) std::string topicName = "persistent://prop/unit/ns/partition-test"; // call admin api to make it partitioned - std::string url = lookupUrl + "/admin/persistent/prop/unit/ns/partition-test/partitions"; - int res = makePutRequest(lookupUrl, "3"); + std::string url = adminUrl + "admin/persistent/prop/unit/ns/partition-test/partitions"; + int res = makePutRequest(url, "3"); - if (res != 204 && res != 409) { - LOG_DEBUG("Unable to create partitioned topic."); - return; - } + LOG_INFO("res = "<(epochTime) ; // call admin api to make it partitioned - std::string url = lookupUrl + "/admin/persistent/prop/unit/ns/test-partitioned-batch-messages-" + std::string url = adminUrl + "admin/persistent/property/cluster/namespace/test-partitioned-batch-messages-" + boost::lexical_cast(epochTime) + "/partitions"; - int res = makePutRequest(lookupUrl, "7"); + int res = makePutRequest(url, "7"); - if (res != 204 && res != 409) { - LOG_DEBUG("Unable to create partitioned topic."); - return; - } + LOG_INFO("res = "< - int makePutRequest(const std::string& url, const std::string& body) { - CURL* curl = curl_easy_init(); - curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); - curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PUT"); - curl_easy_setopt(curl, CURLOPT_POSTFIELDS, body.c_str()); - - int res = curl_easy_perform(curl); - if (res != CURLE_OK) { - return -1; - } - - int httpResult = 0; - curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &httpResult); - - curl_easy_cleanup(curl); - return httpResult; - } +int makePutRequest(const std::string& url, const std::string& body) { + CURL* curl = curl_easy_init(); + + struct curl_slist *list = NULL; + + list = curl_slist_append(list, "Content-Type: application/json"); + + curl_easy_setopt(curl, CURLOPT_HTTPHEADER, list); + curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); + curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PUT"); + curl_easy_setopt(curl, CURLOPT_POSTFIELDS, body.c_str()); + curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); + int res = curl_easy_perform(curl); + curl_slist_free_all(list); /* free the list again */ + + if (res != CURLE_OK) { + return -1; + } + + int httpResult = 0; + curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &httpResult); + curl_easy_cleanup(curl); + return httpResult; +}