-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support sofa-rpc provider register blacklist/whitelist (#1254)
Co-authored-by: 致节 <hzj266771@antgroup.com>
- Loading branch information
1 parent
0104a65
commit 76e7def
Showing
7 changed files
with
249 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
.../java/com/alipay/sofa/smoke/tests/rpc/provider/BlackListProviderConfigContainerTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* 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 com.alipay.sofa.smoke.tests.rpc.provider; | ||
|
||
import com.alipay.sofa.rpc.core.exception.SofaRouteException; | ||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.test.context.TestPropertySource; | ||
|
||
/** | ||
* @author huzijie | ||
* @version BlackListProviderConfigContainerTests.java, v 0.1 2023年09月27日 11:26 AM huzijie Exp $ | ||
*/ | ||
@TestPropertySource(properties = "sofa.boot.rpc.providerRegisterBlackList=com.alipay.sofa.smoke.tests.rpc.boot.bean.SampleFacade:uniqueId") | ||
public class BlackListProviderConfigContainerTests extends ProviderConfigContainerTestBase { | ||
|
||
@Test | ||
public void checkProviderExported() { | ||
Assertions.assertThat(sampleFacadeA.sayHi("Sofa")).isEqualTo("hi Sofa!"); | ||
Assertions.assertThatThrownBy(() -> sampleFacadeB.sayHi("Sofa")).isInstanceOf(SofaRouteException.class). | ||
hasMessageContaining("Cannot get the service address of service [com.alipay.sofa.smoke.tests.rpc.boot.bean.SampleFacade:1.0:uniqueId]"); | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
...c/test/java/com/alipay/sofa/smoke/tests/rpc/provider/ProviderConfigContainerTestBase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* 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 com.alipay.sofa.smoke.tests.rpc.provider; | ||
|
||
import com.alipay.sofa.rpc.boot.container.ProviderConfigContainer; | ||
import com.alipay.sofa.runtime.api.annotation.SofaReference; | ||
import com.alipay.sofa.runtime.api.annotation.SofaReferenceBinding; | ||
import com.alipay.sofa.runtime.api.annotation.SofaService; | ||
import com.alipay.sofa.runtime.api.annotation.SofaServiceBinding; | ||
import com.alipay.sofa.smoke.tests.rpc.boot.RpcSofaBootApplication; | ||
import com.alipay.sofa.smoke.tests.rpc.boot.bean.SampleFacade; | ||
import com.alipay.sofa.smoke.tests.rpc.boot.bean.SampleFacadeImpl; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Import; | ||
|
||
/** | ||
* @author huzijie | ||
* @version ProviderConfigContainerTests.java, v 0.1 2023年09月27日 11:14 AM huzijie Exp $ | ||
*/ | ||
@SpringBootTest(classes = RpcSofaBootApplication.class, properties = "sofa.boot.actuator.health.skipAll=true", webEnvironment = SpringBootTest.WebEnvironment.NONE) | ||
@Import(ProviderConfigContainerTestBase.RpcPublishConfiguration.class) | ||
public class ProviderConfigContainerTestBase { | ||
|
||
@SofaReference(jvmFirst = false, binding = @SofaReferenceBinding(bindingType = "bolt")) | ||
protected SampleFacade sampleFacadeA; | ||
|
||
@SofaReference(jvmFirst = false, binding = @SofaReferenceBinding(bindingType = "bolt"), uniqueId = "uniqueId") | ||
protected SampleFacade sampleFacadeB; | ||
|
||
@Autowired | ||
private ProviderConfigContainer providerConfigContainer; | ||
|
||
@AfterEach | ||
private void clearExported() { | ||
providerConfigContainer.unExportAllProviderConfig(); | ||
} | ||
|
||
@Configuration | ||
static class RpcPublishConfiguration { | ||
|
||
@SofaService(bindings = { @SofaServiceBinding(bindingType = "bolt") }) | ||
@Bean | ||
public SampleFacade providerA() { | ||
return new SampleFacadeImpl(); | ||
} | ||
|
||
@SofaService(bindings = { @SofaServiceBinding(bindingType = "bolt") }, uniqueId = "uniqueId") | ||
@Bean | ||
public SampleFacade providerB() { | ||
return new SampleFacadeImpl(); | ||
} | ||
} | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
.../java/com/alipay/sofa/smoke/tests/rpc/provider/WhiteListProviderConfigContainerTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* 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 com.alipay.sofa.smoke.tests.rpc.provider; | ||
|
||
import com.alipay.sofa.rpc.core.exception.SofaRouteException; | ||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.test.context.TestPropertySource; | ||
|
||
/** | ||
* @author huzijie | ||
* @version WhiteListProviderConfigContainerTests.java, v 0.1 2023年09月27日 11:27 AM huzijie Exp $ | ||
*/ | ||
@TestPropertySource(properties = "sofa.boot.rpc.providerRegisterWhiteList=com.alipay.sofa.smoke.tests.rpc.boot.bean.SampleFacade:uniqueId") | ||
public class WhiteListProviderConfigContainerTests extends ProviderConfigContainerTestBase { | ||
|
||
@Test | ||
public void checkProviderExported() { | ||
Assertions.assertThatThrownBy(() -> sampleFacadeA.sayHi("Sofa")).isInstanceOf(SofaRouteException.class). | ||
hasMessageContaining("Cannot get the service address of service [com.alipay.sofa.smoke.tests.rpc.boot.bean.SampleFacade:1.0]"); | ||
Assertions.assertThat(sampleFacadeB.sayHi("Sofa")).isEqualTo("hi Sofa!"); | ||
} | ||
} |