You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by al...@apache.org on 2021/09/15 09:31:13 UTC
[dubbo] branch 3.0 updated: Add unit test for
Base[Service/Application]MetadataIdentifier (#8767)
This is an automated email from the ASF dual-hosted git repository.
albumenj pushed a commit to branch 3.0
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/3.0 by this push:
new 6ddb26a Add unit test for Base[Service/Application]MetadataIdentifier (#8767)
6ddb26a is described below
commit 6ddb26a341e87ab4155e4ede6094029dcb2a2269
Author: 灼华 <43...@users.noreply.github.com>
AuthorDate: Wed Sep 15 17:30:50 2021 +0800
Add unit test for Base[Service/Application]MetadataIdentifier (#8767)
* Add unit test for Base[Service/Application]MetadataIdentifier
* Unused import
---
.../BaseApplicationMetadataIdentifier.java | 28 ++++---------
.../identifier/BaseServiceMetadataIdentifier.java | 48 +++++-----------------
.../BaseApplicationMetadataIdentifierTest.java | 44 ++++++++++++++++++++
.../BaseServiceMetadataIdentifierTest.java | 48 ++++++++++++++++++++++
.../registry/client/ServiceDiscoveryRegistry.java | 2 +-
5 files changed, 111 insertions(+), 59 deletions(-)
diff --git a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/identifier/BaseApplicationMetadataIdentifier.java b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/identifier/BaseApplicationMetadataIdentifier.java
index f70678b..591a1a7 100644
--- a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/identifier/BaseApplicationMetadataIdentifier.java
+++ b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/identifier/BaseApplicationMetadataIdentifier.java
@@ -16,40 +16,25 @@
*/
package org.apache.dubbo.metadata.report.identifier;
-import static org.apache.dubbo.common.constants.CommonConstants.PATH_SEPARATOR;
-import static org.apache.dubbo.common.utils.PathUtils.buildPath;
import static org.apache.dubbo.metadata.MetadataConstants.DEFAULT_PATH_TAG;
-import static org.apache.dubbo.metadata.MetadataConstants.KEY_SEPARATOR;
/**
- * The Base class of MetadataIdentifier for service scope
+ * The Base class of MetadataIdentifier for application scope
* <p>
* 2019-08-09
*/
public class BaseApplicationMetadataIdentifier {
- String application;
+ protected String application;
- String getUniqueKey(KeyTypeEnum keyType, String... params) {
+ protected String getUniqueKey(KeyTypeEnum keyType, String... params) {
if (keyType == KeyTypeEnum.PATH) {
return getFilePathKey(params);
}
return getIdentifierKey(params);
}
- String getIdentifierKey(String... params) {
- return application + joinParams(KEY_SEPARATOR, params);
- }
-
- private String joinParams(String joinChar, String... params) {
- if (params == null || params.length == 0) {
- return "";
- }
- StringBuilder sb = new StringBuilder();
- for (String param : params) {
- sb.append(joinChar);
- sb.append(param);
- }
- return sb.toString();
+ protected String getIdentifierKey(String... params) {
+ return KeyTypeEnum.UNIQUE_KEY.build(application,params);
}
private String getFilePathKey(String... params) {
@@ -57,7 +42,8 @@ public class BaseApplicationMetadataIdentifier {
}
private String getFilePathKey(String pathTag, String... params) {
- return buildPath(pathTag, application, joinParams(PATH_SEPARATOR, params));
+ String prefix = KeyTypeEnum.PATH.build(pathTag, application);
+ return KeyTypeEnum.PATH.build(prefix, params);
}
}
diff --git a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/identifier/BaseServiceMetadataIdentifier.java b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/identifier/BaseServiceMetadataIdentifier.java
index 37b53ae..8b75515 100644
--- a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/identifier/BaseServiceMetadataIdentifier.java
+++ b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/identifier/BaseServiceMetadataIdentifier.java
@@ -17,12 +17,9 @@
package org.apache.dubbo.metadata.report.identifier;
import org.apache.dubbo.common.URL;
-import org.apache.dubbo.common.utils.StringUtils;
import static org.apache.dubbo.common.constants.CommonConstants.ANY_VALUE;
-import static org.apache.dubbo.common.constants.CommonConstants.PATH_SEPARATOR;
import static org.apache.dubbo.metadata.MetadataConstants.DEFAULT_PATH_TAG;
-import static org.apache.dubbo.metadata.MetadataConstants.KEY_SEPARATOR;
/**
* The Base class of MetadataIdentifier for service scope
@@ -30,40 +27,21 @@ import static org.apache.dubbo.metadata.MetadataConstants.KEY_SEPARATOR;
* 2019-08-09
*/
public class BaseServiceMetadataIdentifier {
- String serviceInterface;
- String version;
- String group;
- String side;
+ protected String serviceInterface;
+ protected String version;
+ protected String group;
+ protected String side;
- String getUniqueKey(KeyTypeEnum keyType, String... params) {
+ protected String getUniqueKey(KeyTypeEnum keyType, String... params) {
if (keyType == KeyTypeEnum.PATH) {
return getFilePathKey(params);
}
return getIdentifierKey(params);
}
- String getIdentifierKey(String... params) {
-
- return serviceInterface
- + KEY_SEPARATOR + (version == null ? "" : version)
- + KEY_SEPARATOR + (group == null ? "" : group)
- + KEY_SEPARATOR + (side == null ? "" : side)
- + joinParams(KEY_SEPARATOR, params);
- }
-
- private String joinParams(String joinChar, String... params) {
- if (params == null || params.length == 0) {
- return "";
- }
- StringBuilder sb = new StringBuilder();
- for (String param : params) {
- if (param == null) {
- continue;
- }
- sb.append(joinChar);
- sb.append(param);
- }
- return sb.toString();
+ protected String getIdentifierKey(String... params) {
+ String prefix = KeyTypeEnum.UNIQUE_KEY.build(serviceInterface, version, group, side);
+ return KeyTypeEnum.UNIQUE_KEY.build(prefix, params);
}
private String getFilePathKey(String... params) {
@@ -71,15 +49,11 @@ public class BaseServiceMetadataIdentifier {
}
private String getFilePathKey(String pathTag, String... params) {
- return pathTag
- + (StringUtils.isEmpty(toServicePath()) ? "" : (PATH_SEPARATOR + toServicePath()))
- + (version == null ? "" : (PATH_SEPARATOR + version))
- + (group == null ? "" : (PATH_SEPARATOR + group))
- + (side == null ? "" : (PATH_SEPARATOR + side))
- + joinParams(PATH_SEPARATOR, params);
+ String prefix = KeyTypeEnum.PATH.build(pathTag, toServicePath(), version, group, side);
+ return KeyTypeEnum.PATH.build(prefix, params);
}
- public String toServicePath() {
+ private String toServicePath() {
if (ANY_VALUE.equals(serviceInterface)) {
return "";
}
diff --git a/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/report/identifier/BaseApplicationMetadataIdentifierTest.java b/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/report/identifier/BaseApplicationMetadataIdentifierTest.java
new file mode 100644
index 0000000..90950b5
--- /dev/null
+++ b/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/report/identifier/BaseApplicationMetadataIdentifierTest.java
@@ -0,0 +1,44 @@
+/*
+ * 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.
+ */
+package org.apache.dubbo.metadata.report.identifier;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+class BaseApplicationMetadataIdentifierTest {
+ private BaseApplicationMetadataIdentifier baseApplicationMetadataIdentifier;
+
+ {
+ baseApplicationMetadataIdentifier = new BaseApplicationMetadataIdentifier();
+ baseApplicationMetadataIdentifier.application = "app";
+ }
+
+ @Test
+ void getUniqueKey() {
+ String uniqueKey = baseApplicationMetadataIdentifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY, "reversion");
+ Assertions.assertEquals(uniqueKey, "app:reversion");
+
+ String uniqueKey2 = baseApplicationMetadataIdentifier.getUniqueKey(KeyTypeEnum.PATH, "reversion");
+ Assertions.assertEquals(uniqueKey2, "metadata/app/reversion");
+ }
+
+ @Test
+ void getIdentifierKey() {
+ String identifierKey = baseApplicationMetadataIdentifier.getIdentifierKey( "reversion");
+ Assertions.assertEquals(identifierKey, "app:reversion");
+ }
+}
diff --git a/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/report/identifier/BaseServiceMetadataIdentifierTest.java b/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/report/identifier/BaseServiceMetadataIdentifierTest.java
new file mode 100644
index 0000000..3b6ce91
--- /dev/null
+++ b/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/report/identifier/BaseServiceMetadataIdentifierTest.java
@@ -0,0 +1,48 @@
+/*
+ * 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.
+ */
+package org.apache.dubbo.metadata.report.identifier;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+class BaseServiceMetadataIdentifierTest {
+
+ private BaseServiceMetadataIdentifier baseServiceMetadataIdentifier;
+
+ {
+ baseServiceMetadataIdentifier = new BaseServiceMetadataIdentifier();
+ baseServiceMetadataIdentifier.version = "1.0.0";
+ baseServiceMetadataIdentifier.group = "test";
+ baseServiceMetadataIdentifier.side = "provider";
+ baseServiceMetadataIdentifier.serviceInterface = "BaseServiceMetadataIdentifierTest";
+ }
+
+ @Test
+ void getUniqueKey() {
+ String uniqueKey = baseServiceMetadataIdentifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY, "appName");
+ Assertions.assertEquals(uniqueKey, "BaseServiceMetadataIdentifierTest:1.0.0:test:provider:appName");
+
+ String uniqueKey2 = baseServiceMetadataIdentifier.getUniqueKey(KeyTypeEnum.PATH, "appName");
+ Assertions.assertEquals(uniqueKey2, "metadata/BaseServiceMetadataIdentifierTest/1.0.0/test/provider/appName");
+ }
+
+ @Test
+ void getIdentifierKey() {
+ String identifierKey = baseServiceMetadataIdentifier.getIdentifierKey( "appName");
+ Assertions.assertEquals(identifierKey, "BaseServiceMetadataIdentifierTest:1.0.0:test:provider:appName");
+ }
+}
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceDiscoveryRegistry.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceDiscoveryRegistry.java
index 54f5262..9b8c93b 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceDiscoveryRegistry.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceDiscoveryRegistry.java
@@ -187,7 +187,7 @@ public class ServiceDiscoveryRegistry implements Registry {
}
} else {
if (logger.isWarnEnabled()) {
- logger.info(format("The URL[%s] has been deregistered.", url.toString()));
+ logger.warn(format("The URL[%s] has been deregistered.", url.toString()));
}
}
}