From 5f7751c0d0e405105a0a46a952fd6e4a66169a2b Mon Sep 17 00:00:00 2001 From: haoxz11 Date: Tue, 22 Nov 2022 16:26:31 +0800 Subject: [PATCH 1/2] Fix the warning problem when invokerUrls is checked (#10937) --- .../registry/integration/RegistryDirectory.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java index 1c66500c61f..4efa28799b7 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java @@ -231,14 +231,14 @@ private void refreshInvoker(List invokerUrls) { } // use local reference to avoid NPE as this.cachedInvokerUrls will be set null by destroyAllInvokers(). Set localCachedInvokerUrls = this.cachedInvokerUrls; - if (invokerUrls.isEmpty() && localCachedInvokerUrls != null) { - - // 1-4 Empty address. - logger.warn(REGISTRY_EMPTY_ADDRESS, "configuration ", "", - "Service" + serviceKey + " received empty address list with no EMPTY protocol set, trigger empty protection."); - - invokerUrls.addAll(localCachedInvokerUrls); + if (invokerUrls.isEmpty()) { + if(CollectionUtils.isNotEmpty(localCachedInvokerUrls)){ + // 1-4 Empty address. + logger.warn(REGISTRY_EMPTY_ADDRESS, "configuration ", "", + "Service" + serviceKey + " received empty address list with no EMPTY protocol set, trigger empty protection."); + invokerUrls.addAll(localCachedInvokerUrls); + } } else { localCachedInvokerUrls = new HashSet<>(); localCachedInvokerUrls.addAll(invokerUrls);//Cached invoker urls, convenient for comparison From f074aec261cc8b794d06a3a5a0fe5842bbbeebf2 Mon Sep 17 00:00:00 2001 From: Albumen Kevin Date: Tue, 22 Nov 2022 17:16:46 +0800 Subject: [PATCH 2/2] Fix FileTest seperator in Win (#10990) --- .../org/apache/dubbo/dependency/FileTest.java | 64 ++++++++++--------- 1 file changed, 33 insertions(+), 31 deletions(-) diff --git a/dubbo-test/dubbo-test-modules/src/test/java/org/apache/dubbo/dependency/FileTest.java b/dubbo-test/dubbo-test-modules/src/test/java/org/apache/dubbo/dependency/FileTest.java index e7f7ba606b1..85775ae2c51 100644 --- a/dubbo-test/dubbo-test-modules/src/test/java/org/apache/dubbo/dependency/FileTest.java +++ b/dubbo-test/dubbo-test-modules/src/test/java/org/apache/dubbo/dependency/FileTest.java @@ -80,7 +80,7 @@ void checkDubboBom() throws DocumentException { .sorted() .collect(Collectors.toList()); - String dubboBomPath = "dubbo-distribution/dubbo-bom/pom.xml"; + String dubboBomPath = "dubbo-distribution" + File.separator + "dubbo-bom" + File.separator + "pom.xml"; Document dubboBom = reader.read(new File(getBaseFile(), dubboBomPath)); List artifactIdsInDubboBom = dubboBom.getRootElement() .element("dependencyManagement") @@ -120,7 +120,7 @@ void checkDubboDependenciesAll() throws DocumentException { .sorted() .collect(Collectors.toList()); - String dubboDependenciesAllPath = "dubbo-test/dubbo-dependencies-all/pom.xml"; + String dubboDependenciesAllPath = "dubbo-test" + File.separator + "dubbo-dependencies-all" + File.separator + "pom.xml"; Document dubboDependenciesAll = reader.read(new File(getBaseFile(), dubboDependenciesAllPath)); List artifactIdsInDubboDependenciesAll = dubboDependenciesAll.getRootElement() .element("dependencies") @@ -177,7 +177,7 @@ void checkDubboAllDependencies() throws DocumentException { .sorted() .collect(Collectors.toList()); - String dubboAllPath = "dubbo-distribution/dubbo-all/pom.xml"; + String dubboAllPath = "dubbo-distribution" + File.separator + "dubbo-all" + File.separator + "pom.xml"; Document dubboAll = reader.read(new File(getBaseFile(), dubboAllPath)); List artifactIdsInDubboAll = dubboAll.getRootElement() .element("dependencies") @@ -191,12 +191,12 @@ void checkDubboAllDependencies() throws DocumentException { expectedArtifactIds.removeIf(artifactId -> ignoredModules.stream().anyMatch(pattern -> pattern.matcher(artifactId).matches())); expectedArtifactIds.removeIf(artifactId -> ignoredModulesInDubboAll.stream().anyMatch(pattern -> pattern.matcher(artifactId).matches())); - Assertions.assertTrue(expectedArtifactIds.isEmpty(), "Newly created modules must be added to dubbo-all(dubbo-distribution/dubbo-all/pom.xml). Found modules: " + expectedArtifactIds); + Assertions.assertTrue(expectedArtifactIds.isEmpty(), "Newly created modules must be added to dubbo-all(dubbo-distribution" + File.separator + "dubbo-all" + File.separator + "pom.xml). Found modules: " + expectedArtifactIds); List unexpectedArtifactIds = new LinkedList<>(artifactIdsInDubboAll); unexpectedArtifactIds.removeIf(artifactId -> !artifactIds.contains(artifactId)); unexpectedArtifactIds.removeAll(deployedArtifactIds); - Assertions.assertTrue(unexpectedArtifactIds.isEmpty(), "Undeploy dependencies should not be added to dubbo-all(dubbo-distribution/dubbo-all/pom.xml). Found modules: " + unexpectedArtifactIds); + Assertions.assertTrue(unexpectedArtifactIds.isEmpty(), "Undeploy dependencies should not be added to dubbo-all(dubbo-distribution" + File.separator + "dubbo-all" + File.separator + "pom.xml). Found modules: " + unexpectedArtifactIds); unexpectedArtifactIds = new LinkedList<>(); for (String artifactId : artifactIdsInDubboAll) { @@ -210,7 +210,7 @@ void checkDubboAllDependencies() throws DocumentException { unexpectedArtifactIds.add(artifactId); } } - Assertions.assertTrue(unexpectedArtifactIds.isEmpty(), "Unexpected dependencies should not be added to dubbo-all(dubbo-distribution/dubbo-all/pom.xml). Found modules: " + unexpectedArtifactIds); + Assertions.assertTrue(unexpectedArtifactIds.isEmpty(), "Unexpected dependencies should not be added to dubbo-all(dubbo-distribution" + File.separator + "dubbo-all" + File.separator + "pom.xml). Found modules: " + unexpectedArtifactIds); } @Test @@ -254,7 +254,7 @@ void checkDubboAllShade() throws DocumentException { .sorted() .collect(Collectors.toList()); - String dubboAllPath = "dubbo-distribution/dubbo-all/pom.xml"; + String dubboAllPath = "dubbo-distribution" + File.separator + "dubbo-all" + File.separator + "pom.xml"; Document dubboAll = reader.read(new File(getBaseFile(), dubboAllPath)); List artifactIdsInDubboAll = dubboAll.getRootElement() .element("build") @@ -281,12 +281,12 @@ void checkDubboAllShade() throws DocumentException { expectedArtifactIds.removeIf(artifactId -> ignoredModules.stream().anyMatch(pattern -> pattern.matcher(artifactId).matches())); expectedArtifactIds.removeIf(artifactId -> ignoredModulesInDubboAll.stream().anyMatch(pattern -> pattern.matcher(artifactId).matches())); - Assertions.assertTrue(expectedArtifactIds.isEmpty(), "Newly created modules must be added to dubbo-all (dubbo-distribution/dubbo-all/pom.xml in shade plugin). Found modules: " + expectedArtifactIds); + Assertions.assertTrue(expectedArtifactIds.isEmpty(), "Newly created modules must be added to dubbo-all (dubbo-distribution" + File.separator + "dubbo-all" + File.separator + "pom.xml in shade plugin). Found modules: " + expectedArtifactIds); List unexpectedArtifactIds = new LinkedList<>(artifactIdsInDubboAll); unexpectedArtifactIds.removeIf(artifactId -> !artifactIds.contains(artifactId)); unexpectedArtifactIds.removeAll(deployedArtifactIds); - Assertions.assertTrue(unexpectedArtifactIds.isEmpty(), "Undeploy dependencies should not be added to dubbo-all (dubbo-distribution/dubbo-all/pom.xml in shade plugin). Found modules: " + unexpectedArtifactIds); + Assertions.assertTrue(unexpectedArtifactIds.isEmpty(), "Undeploy dependencies should not be added to dubbo-all (dubbo-distribution" + File.separator + "dubbo-all" + File.separator + "pom.xml in shade plugin). Found modules: " + unexpectedArtifactIds); unexpectedArtifactIds = new LinkedList<>(); for (String artifactId : artifactIdsInDubboAll) { @@ -300,7 +300,7 @@ void checkDubboAllShade() throws DocumentException { unexpectedArtifactIds.add(artifactId); } } - Assertions.assertTrue(unexpectedArtifactIds.isEmpty(), "Unexpected dependencies should not be added to dubbo-all (dubbo-distribution/dubbo-all/pom.xml in shade plugin). Found modules: " + unexpectedArtifactIds); + Assertions.assertTrue(unexpectedArtifactIds.isEmpty(), "Unexpected dependencies should not be added to dubbo-all (dubbo-distribution" + File.separator + "dubbo-all" + File.separator + "pom.xml in shade plugin). Found modules: " + unexpectedArtifactIds); } @Test @@ -309,7 +309,7 @@ void checkDubboAllTransform() throws DocumentException { List spis = new LinkedList<>(); readSPI(baseFile, spis); - String dubboAllPath = "dubbo-distribution/dubbo-all/pom.xml"; + String dubboAllPath = "dubbo-distribution" + File.separator + "dubbo-all" + File.separator + "pom.xml"; SAXReader reader = new SAXReader(); Document dubboAll = reader.read(new File(baseFile, dubboAllPath)); @@ -335,11 +335,11 @@ void checkDubboAllTransform() throws DocumentException { List expectedSpis = new LinkedList<>(spis); expectedSpis.removeAll(transformsInDubboAll); - Assertions.assertTrue(expectedSpis.isEmpty(), "Newly created SPI interface must be added to dubbo-all(dubbo-distribution/dubbo-all/pom.xml in shade plugin) to being transformed. Found spis: " + expectedSpis); + Assertions.assertTrue(expectedSpis.isEmpty(), "Newly created SPI interface must be added to dubbo-all(dubbo-distribution" + File.separator + "dubbo-all" + File.separator + "pom.xml in shade plugin) to being transformed. Found spis: " + expectedSpis); List unexpectedSpis = new LinkedList<>(transformsInDubboAll); unexpectedSpis.removeAll(spis); - Assertions.assertTrue(unexpectedSpis.isEmpty(), "Class without `@SPI` declaration should not be added to dubbo-all(dubbo-distribution/dubbo-all/pom.xml in shade plugin) to being transformed. Found spis: " + unexpectedSpis); + Assertions.assertTrue(unexpectedSpis.isEmpty(), "Class without `@SPI` declaration should not be added to dubbo-all(dubbo-distribution" + File.separator + "dubbo-all" + File.separator + "pom.xml in shade plugin) to being transformed. Found spis: " + unexpectedSpis); } @Test @@ -356,8 +356,8 @@ void checkSpiFiles() { List unexpectedSpis = new LinkedList<>(); readSPIUnexpectedResource(baseFile, unexpectedSpis); - unexpectedSpis.removeIf(file -> file.getAbsolutePath().contains("dubbo-common/src/main/resources/META-INF/services/org.apache.dubbo.common.extension.LoadingStrategy")); - Assertions.assertTrue(unexpectedSpis.isEmpty(), "Dubbo native provided spi profiles must filed in `META-INF/dubbo/internal`. Please move to proper folder . Found spis: " + unexpectedSpis); + unexpectedSpis.removeIf(file -> file.getAbsolutePath().contains("dubbo-common" + File.separator + "src" + File.separator + "main" + File.separator + "resources" + File.separator + "META-INF" + File.separator + "services" + File.separator + "org.apache.dubbo.common.extension.LoadingStrategy")); + Assertions.assertTrue(unexpectedSpis.isEmpty(), "Dubbo native provided spi profiles must filed in `META-INF" + File.separator + "dubbo" + File.separator + "internal`. Please move to proper folder . Found spis: " + unexpectedSpis); } private static File getBaseFile() { @@ -404,7 +404,7 @@ public void readSPI(File path, List spis) { if (path.getAbsolutePath().contains("target")) { return; } - if (path.getAbsolutePath().contains("src/main/java")) { + if (path.getAbsolutePath().contains("src" + File.separator + "main" + File.separator + "java")) { String content; try { content = FileUtils.readFileToString(path, StandardCharsets.UTF_8); @@ -413,9 +413,10 @@ public void readSPI(File path, List spis) { } if (content != null && content.contains("@SPI")) { String absolutePath = path.getAbsolutePath(); - absolutePath = absolutePath.substring(absolutePath.lastIndexOf("src/main/java/") + "src/main/java/".length()); + absolutePath = absolutePath.substring(absolutePath.lastIndexOf("src" + File.separator + "main" + File.separator + "java" + File.separator) + + ("src" + File.separator + "main" + File.separator + "java" + File.separator).length()); absolutePath = absolutePath.substring(0, absolutePath.lastIndexOf(".java")); - absolutePath = absolutePath.replaceAll("/", "."); + absolutePath = absolutePath.replaceAll(File.separator, "."); spis.add(absolutePath); } } @@ -434,10 +435,11 @@ public void readSPIResource(File path, Map spis) { if (path.getAbsolutePath().contains("target")) { return; } - if (path.getAbsolutePath().contains("src/main/resources/META-INF/dubbo/internal/")) { + if (path.getAbsolutePath().contains("src" + File.separator + "main" + File.separator + "resources" + File.separator + "META-INF" + File.separator + "dubbo" + File.separator + "internal" + File.separator)) { String absolutePath = path.getAbsolutePath(); - absolutePath = absolutePath.substring(absolutePath.lastIndexOf("src/main/resources/META-INF/dubbo/internal/") + "src/main/resources/META-INF/dubbo/internal/".length()); - absolutePath = absolutePath.replaceAll("/", "."); + absolutePath = absolutePath.substring(absolutePath.lastIndexOf("src" + File.separator + "main" + File.separator + "resources" + File.separator + "META-INF" + File.separator + "dubbo" + File.separator + "internal" + File.separator) + + ("src" + File.separator + "main" + File.separator + "resources" + File.separator + "META-INF" + File.separator + "dubbo" + File.separator + "internal" + File.separator).length()); + absolutePath = absolutePath.replaceAll( File.separator, "."); spis.put(path, absolutePath); } } @@ -455,35 +457,35 @@ public void readSPIUnexpectedResource(File path, List spis) { if (path.getAbsolutePath().contains("target")) { return; } - if (path.getAbsolutePath().contains("src/main/resources/META-INF/dubbo/org.apache.dubbo")) { + if (path.getAbsolutePath().contains("src" + File.separator + "main" + File.separator + "resources" + File.separator + "META-INF" + File.separator + "dubbo" + File.separator + "org.apache.dubbo")) { spis.add(path); } - if (path.getAbsolutePath().contains("src/main/resources/META-INF/dubbo/com.alibaba.dubbo")) { + if (path.getAbsolutePath().contains("src" + File.separator + "main" + File.separator + "resources" + File.separator + "META-INF" + File.separator + "dubbo" + File.separator + "com.alibaba.dubbo")) { spis.add(path); } - if (path.getAbsolutePath().contains("src/main/resources/META-INF/services/org.apache.dubbo")) { + if (path.getAbsolutePath().contains("src" + File.separator + "main" + File.separator + "resources" + File.separator + "META-INF" + File.separator + "services" + File.separator + "org.apache.dubbo")) { spis.add(path); } - if (path.getAbsolutePath().contains("src/main/resources/META-INF/services/com.alibaba.dubbo")) { + if (path.getAbsolutePath().contains("src" + File.separator + "main" + File.separator + "resources" + File.separator + "META-INF" + File.separator + "services" + File.separator + "com.alibaba.dubbo")) { spis.add(path); } - if (path.getAbsolutePath().contains("src/main/resources/META-INF.dubbo/org.apache.dubbo")) { + if (path.getAbsolutePath().contains("src" + File.separator + "main" + File.separator + "resources" + File.separator + "META-INF.dubbo" + File.separator + "org.apache.dubbo")) { spis.add(path); } - if (path.getAbsolutePath().contains("src/main/resources/META-INF.dubbo/com.alibaba.dubbo")) { + if (path.getAbsolutePath().contains("src" + File.separator + "main" + File.separator + "resources" + File.separator + "META-INF.dubbo" + File.separator + "com.alibaba.dubbo")) { spis.add(path); } - if (path.getAbsolutePath().contains("src/main/resources/META-INF.services/org.apache.dubbo")) { + if (path.getAbsolutePath().contains("src" + File.separator + "main" + File.separator + "resources" + File.separator + "META-INF.services" + File.separator + "org.apache.dubbo")) { spis.add(path); } - if (path.getAbsolutePath().contains("src/main/resources/META-INF.services/com.alibaba.dubbo")) { + if (path.getAbsolutePath().contains("src" + File.separator + "main" + File.separator + "resources" + File.separator + "META-INF.services" + File.separator + "com.alibaba.dubbo")) { spis.add(path); } - if (path.getAbsolutePath().contains("src/main/resources/META-INF.dubbo.internal/org.apache.dubbo")) { + if (path.getAbsolutePath().contains("src" + File.separator + "main" + File.separator + "resources" + File.separator + "META-INF.dubbo.internal" + File.separator + "org.apache.dubbo")) { spis.add(path); } - if (path.getAbsolutePath().contains("src/main/resources/META-INF.dubbo.internal/com.alibaba.dubbo")) { + if (path.getAbsolutePath().contains("src" + File.separator + "main" + File.separator + "resources" + File.separator + "META-INF.dubbo.internal" + File.separator + "com.alibaba.dubbo")) { spis.add(path); } }