heesung-sn commented on code in PR #389:
URL: https://github.com/apache/pulsar-client-cpp/pull/389#discussion_r1462673893


##########
tests/extensibleLM/docker-compose.yml:
##########
@@ -0,0 +1,154 @@
+version: '3'
+networks:
+  pulsar:
+    driver: bridge
+services:
+  # Start ZooKeeper
+  zookeeper:

Review Comment:
   @BewareMyPower do you happen to know why this zk server cannot start? It is 
a bit tricky to debug as not outputting the logs.



##########
lib/ClientImpl.h:
##########
@@ -97,6 +97,10 @@ class ClientImpl : public 
std::enable_shared_from_this<ClientImpl> {
 
     Future<Result, ClientConnectionPtr> getConnection(const std::string& 
topic, size_t key);
 
+    Future<Result, ClientConnectionPtr> connect(const std::string& 
logicalAddress, size_t key);
+
+    const std::string& getPhysicalAddress(const std::string& logicalAddress);

Review Comment:
   Ok. I will update this.



##########
tests/extensibleLM/ExtensibleLoadManagerTest.cc:
##########
@@ -0,0 +1,210 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+// Run `docker-compose up -d` to set up the test environment for this test.
+#include <gtest/gtest.h>
+
+#include <thread>
+
+#include "include/pulsar/Client.h"
+#include "lib/Semaphore.h"
+#include "tests/HttpHelper.h"
+#include "tests/PulsarFriend.h"
+
+using namespace pulsar;
+
+bool checkTime() {
+    const static auto start = std::chrono::high_resolution_clock::now();
+    auto end = std::chrono::high_resolution_clock::now();
+    auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end 
- start).count();
+    return duration < 180 * 1000;
+}
+
+TEST(ExtensibleLoadManagerTest, testConsumeSuccess) {
+    const static std::string adminUrl = "http://localhost:8080/";;
+    const static std::string topicName =
+        "persistent://public/unload-test/topic-1" + std::to_string(time(NULL));
+    while (checkTime()) {
+        std::string url = adminUrl + 
"admin/v2/namespaces/public/unload-test?bundles=1";
+        int res = makePutRequest(url, "");
+        if (res != 204 && res != 409) {
+            continue;
+        }
+        break;
+    }
+
+    Client client{"pulsar://localhost:6650"};
+    Producer producer;
+    ProducerConfiguration producerConfiguration;
+    Result producerResult = client.createProducer(topicName, 
producerConfiguration, producer);
+    ASSERT_EQ(producerResult, ResultOk);
+    Consumer consumer;
+    Result consumerResult = client.subscribe(topicName, "sub", consumer);
+    ASSERT_EQ(consumerResult, ResultOk);
+
+    Semaphore firstUnloadSemaphore(0);
+    Semaphore secondUnloadSemaphore(0);
+    Semaphore halfPubWaitSemaphore(0);
+    const int msgCount = 10;
+    int produced = 0;
+    auto produce = [&producer, &produced, &firstUnloadSemaphore, 
&secondUnloadSemaphore,
+                    &halfPubWaitSemaphore]() {
+        int i = 0;
+        while (i < msgCount && checkTime()) {
+            if (i == 3) {
+                firstUnloadSemaphore.acquire();
+            }
+
+            if (i == 5) {
+                halfPubWaitSemaphore.release();
+            }
+
+            if (i == 8) {
+                secondUnloadSemaphore.acquire();
+            }
+
+            std::string content = std::to_string(i);
+            const auto msg = MessageBuilder().setContent(content).build();
+            while (checkTime()) {
+                Result sendResult = producer.send(msg);
+                if (sendResult != ResultOk) {
+                    continue;
+                }
+                break;
+            }
+            std::cout << "produced index:" << i << std::endl;
+            produced++;
+            i++;
+        }
+        std::cout << "producer finished" << std::endl;
+    };
+
+    int consumed = 0;
+    auto consume = [&consumer, &consumed]() {
+        Message receivedMsg;
+        int i = 0;
+        while (i < msgCount && checkTime()) {
+            while (checkTime()) {
+                Result receiveResult =
+                    consumer.receive(receivedMsg, 1000);  // Assumed that we 
wait 1000 ms for each message
+                if (receiveResult != ResultOk) {
+                    continue;
+                }
+                std::cout << "received index:" << i << std::endl;
+                break;
+            }
+            int id = std::stoi(receivedMsg.getDataAsString());
+            if (id < i) {
+                continue;
+            }
+            while (checkTime()) {
+                Result ackResult = consumer.acknowledge(receivedMsg);
+                if (ackResult != ResultOk) {
+                    continue;
+                }
+                std::cout << "acked index:" << i << std::endl;
+                break;
+            }
+            consumed++;
+            i++;
+        }
+        std::cout << "consumer finished" << std::endl;
+    };
+
+    std::thread produceThread(produce);
+    std::thread consumeThread(consume);
+
+    auto unload = [&client, &consumer, &producer] {
+        auto clientImplPtr = PulsarFriend::getClientImplPtr(client);
+        auto &consumerImpl = PulsarFriend::getConsumerImpl(consumer);
+        auto &producerImpl = PulsarFriend::getProducerImpl(producer);
+        uint64_t lookupCountBeforeUnload;
+        std::string destinationBroker;
+        while (checkTime()) {
+            // make sure producers and consumers are ready
+            while (checkTime() && !consumerImpl.isConnected() && 
!producerImpl.isConnected()) {
+                sleep(1);
+            }

Review Comment:
   Sure. Thanks for the suggestion.



##########
lib/ClientImpl.h:
##########
@@ -124,6 +128,8 @@ class ClientImpl : public 
std::enable_shared_from_this<ClientImpl> {
     std::shared_ptr<std::atomic<uint64_t>> getRequestIdGenerator() const { 
return requestIdGenerator_; }
 
     ConnectionPool& getConnectionPool() noexcept { return pool_; }
+    bool useProxy() { return useProxy_; }

Review Comment:
   Ok will remove this.



##########
lib/ClientImpl.cc:
##########
@@ -531,6 +533,10 @@ Future<Result, ClientConnectionPtr> 
ClientImpl::getConnection(const std::string&
                 promise.setFailed(result);
                 return;
             }
+            if (useProxy_ != data.proxyThroughServiceUrl) {
+                useProxy_ = data.proxyThroughServiceUrl;
+            }

Review Comment:
   Ok will update this.



##########
tests/extensibleLM/ExtensibleLoadManagerTest.cc:
##########
@@ -0,0 +1,210 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+// Run `docker-compose up -d` to set up the test environment for this test.
+#include <gtest/gtest.h>
+
+#include <thread>
+
+#include "include/pulsar/Client.h"
+#include "lib/Semaphore.h"
+#include "tests/HttpHelper.h"
+#include "tests/PulsarFriend.h"
+
+using namespace pulsar;
+
+bool checkTime() {
+    const static auto start = std::chrono::high_resolution_clock::now();
+    auto end = std::chrono::high_resolution_clock::now();
+    auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end 
- start).count();
+    return duration < 180 * 1000;
+}
+
+TEST(ExtensibleLoadManagerTest, testConsumeSuccess) {
+    const static std::string adminUrl = "http://localhost:8080/";;
+    const static std::string topicName =
+        "persistent://public/unload-test/topic-1" + std::to_string(time(NULL));
+    while (checkTime()) {
+        std::string url = adminUrl + 
"admin/v2/namespaces/public/unload-test?bundles=1";
+        int res = makePutRequest(url, "");
+        if (res != 204 && res != 409) {
+            continue;
+        }
+        break;
+    }
+
+    Client client{"pulsar://localhost:6650"};
+    Producer producer;
+    ProducerConfiguration producerConfiguration;
+    Result producerResult = client.createProducer(topicName, 
producerConfiguration, producer);
+    ASSERT_EQ(producerResult, ResultOk);
+    Consumer consumer;
+    Result consumerResult = client.subscribe(topicName, "sub", consumer);
+    ASSERT_EQ(consumerResult, ResultOk);
+
+    Semaphore firstUnloadSemaphore(0);
+    Semaphore secondUnloadSemaphore(0);
+    Semaphore halfPubWaitSemaphore(0);
+    const int msgCount = 10;
+    int produced = 0;
+    auto produce = [&producer, &produced, &firstUnloadSemaphore, 
&secondUnloadSemaphore,
+                    &halfPubWaitSemaphore]() {
+        int i = 0;
+        while (i < msgCount && checkTime()) {
+            if (i == 3) {
+                firstUnloadSemaphore.acquire();
+            }
+
+            if (i == 5) {
+                halfPubWaitSemaphore.release();
+            }
+
+            if (i == 8) {
+                secondUnloadSemaphore.acquire();
+            }
+
+            std::string content = std::to_string(i);
+            const auto msg = MessageBuilder().setContent(content).build();
+            while (checkTime()) {
+                Result sendResult = producer.send(msg);
+                if (sendResult != ResultOk) {
+                    continue;
+                }
+                break;
+            }
+            std::cout << "produced index:" << i << std::endl;

Review Comment:
   Ok. Will update this.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to