You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pegasus.apache.org by "GehaFearless (via GitHub)" <gi...@apache.org> on 2023/04/10 14:58:02 UTC

[GitHub] [incubator-pegasus] GehaFearless commented on a diff in pull request #1430: feat(FQDN): Implement of struct rpc_host_port

GehaFearless commented on code in PR #1430:
URL: https://github.com/apache/incubator-pegasus/pull/1430#discussion_r1161758838


##########
src/runtime/test/host_port_test.cpp:
##########
@@ -0,0 +1,71 @@
+/*
+ * 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.
+ */
+
+#include <gtest/gtest.h>
+#include <gtest/gtest-message.h>
+#include <gtest/gtest-test-part.h>
+#include <string>
+
+#include "runtime/rpc/rpc_address.h"
+#include "runtime/rpc/rpc_host_port.h"
+
+namespace dsn {
+
+TEST(host_port_test, host_port_to_string)
+{
+    {
+        host_port hp = host_port("localhost", 8080);
+        ASSERT_EQ(std::string("localhost:8080"), hp.to_string());
+    }
+
+    {
+        host_port hp;
+        ASSERT_EQ(std::string("invalid address"), hp.to_string());
+    }
+}
+
+TEST(host_port_test, host_port_build)
+{
+    host_port hp = host_port("localhost", 8080);
+    ASSERT_EQ(HOST_TYPE_IPV4, hp.type());
+    ASSERT_EQ(8080, hp.port());
+    ASSERT_EQ("localhost", hp.host());
+}
+
+TEST(host_port_test, operators)
+{
+    host_port hp("localhost", 8080);
+    ASSERT_EQ(hp, hp);

Review Comment:
   in host_port_build



##########
src/runtime/rpc/rpc_host_port.h:
##########
@@ -0,0 +1,124 @@
+/*
+ * 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.
+ */
+
+#pragma once
+
+// IWYU pragma: no_include <experimental/string_view>
+#include <stdint.h>
+#include <cstddef>
+#include <iosfwd>
+#include <string>
+
+#include "runtime/rpc/rpc_address.h"
+#include "utils/fmt_logging.h"
+
+namespace dsn {
+
+class host_port
+{
+public:
+    static const host_port s_invalid_host_port;
+    explicit host_port() = default;
+    explicit host_port(std::string host, uint16_t port);
+    explicit host_port(rpc_address addr);
+
+    host_port(const host_port &other) { *this = other; }
+    host_port &operator=(const host_port &other);
+
+    void reset();
+    ~host_port() { reset(); }
+
+    dsn_host_type_t type() const { return _type; }
+    const std::string &host() const { return _host; }
+    uint16_t port() const { return _port; }
+
+    bool is_invalid() const { return _type == HOST_TYPE_INVALID; }
+
+    std::string to_string() const;
+
+    friend std::ostream &operator<<(std::ostream &os, const host_port &hp)
+    {
+        return os << hp.to_string();
+    }
+
+private:
+    std::string _host;
+    uint16_t _port = 0;
+    dsn_host_type_t _type = HOST_TYPE_INVALID;
+};
+
+inline bool operator<(const host_port &hp1, const host_port &hp2)

Review Comment:
   Then we're going to use map



##########
src/runtime/test/host_port_test.cpp:
##########
@@ -0,0 +1,71 @@
+/*
+ * 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.
+ */
+
+#include <gtest/gtest.h>
+#include <gtest/gtest-message.h>
+#include <gtest/gtest-test-part.h>
+#include <string>
+
+#include "runtime/rpc/rpc_address.h"
+#include "runtime/rpc/rpc_host_port.h"
+
+namespace dsn {
+
+TEST(host_port_test, host_port_to_string)
+{
+    {
+        host_port hp = host_port("localhost", 8080);
+        ASSERT_EQ(std::string("localhost:8080"), hp.to_string());
+    }
+
+    {
+        host_port hp;
+        ASSERT_EQ(std::string("invalid address"), hp.to_string());
+    }
+}
+
+TEST(host_port_test, host_port_build)
+{
+    host_port hp = host_port("localhost", 8080);
+    ASSERT_EQ(HOST_TYPE_IPV4, hp.type());
+    ASSERT_EQ(8080, hp.port());
+    ASSERT_EQ("localhost", hp.host());
+}
+
+TEST(host_port_test, operators)
+{
+    host_port hp("localhost", 8080);
+    ASSERT_EQ(hp, hp);
+
+    {
+        host_port new_hp(hp);
+        ASSERT_EQ(hp, new_hp);
+    }
+
+    {
+        host_port new_hp("localhost", 8081);
+        ASSERT_NE(hp, new_hp);
+    }
+
+    host_port hp2;
+    ASSERT_NE(hp, hp2);
+    ASSERT_FALSE(hp.is_invalid());
+    ASSERT_TRUE(hp2.is_invalid());

Review Comment:
   I can delete it now, and add when it needed.



-- 
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: dev-unsubscribe@pegasus.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pegasus.apache.org
For additional commands, e-mail: dev-help@pegasus.apache.org