Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ jobs:
java-version: '8'
distribution: 'temurin'
cache: maven
- name: Build with Maven
run: ./mvnw clean install -Pci-install -B -U -e && bash ./tools/check_format.sh
- name: Test with Maven
run: ./mvnw package -Pci-test
- name: Build and test with Maven
run: ./mvnw -T 1C clean verify -Pci-test -B -e && bash ./tools/check_format.sh
- name: Codecov
uses: codecov/codecov-action@v1

Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public void init() {
consumerConfig = new ConsumerConfig<FaultHelloService>()
.setInterfaceId(FaultHelloService.class.getName())
.setTimeout(500)
.setReconnectPeriod(2000)
.setDirectUrl("127.0.0.1:12299")
Comment on lines 91 to 95
.setRegister(false)
.setProtocol(RpcConstants.PROTOCOL_TYPE_BOLT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.alipay.sofa.rpc.client.aft;

import com.alipay.sofa.rpc.client.ProviderInfo;
import com.alipay.sofa.rpc.transport.ClientTransport;
import org.junit.Assert;
import org.junit.Test;

Expand Down Expand Up @@ -44,18 +45,16 @@ public void testAll() throws InterruptedException {
FaultToleranceConfigManager.putAppConfig(APP_NAME1, config);

/**test degrade normal*/
for (int i = 0; i < 1; i++) {
try {
helloService.sayHello("liangen");
} catch (Exception e) {
LOGGER.info("超时");
}
}
Thread.sleep(100);
final ProviderInfo providerInfo = getProviderInfoByHost(consumerConfig, "127.0.0.1");
final InvocationStatDimension statDimension = new InvocationStatDimension(providerInfo, consumerConfig);
InvocationStat invocationStat = InvocationStatFactory.ALL_STATS.get(statDimension);
Assert.assertNotNull(invocationStat);
final int maxConnectionRetryAttempts = 50;
final int maxRetryAttempts = 10;
final int retryDelayMillis = 100;
Comment on lines 48 to +52
Assert.assertTrue("Consumer transport should be available before invoking the service",
waitForAvailableTransport(providerInfo, maxConnectionRetryAttempts, retryDelayMillis));
InvocationStat invocationStat = waitForInvocationStat(statDimension, maxRetryAttempts, retryDelayMillis);
Assert.assertNotNull("InvocationStat should be available after " + maxRetryAttempts + " retry attempts",
invocationStat);

// 最多等10000ms 到了下一个周期
Assert.assertNull(delayGet(new Callable<InvocationStat>() {
Expand All @@ -65,4 +64,38 @@ public InvocationStat call() throws Exception {
}
}, null, 100, 100));
}
}

private InvocationStat waitForInvocationStat(InvocationStatDimension statDimension, int maxAttempts,
int retryDelayMillis) throws InterruptedException {
for (int i = 0; i < maxAttempts; i++) {
try {
helloService.sayHello("liangen");
} catch (Exception e) {
LOGGER.info("超时");
}
InvocationStat invocationStat = InvocationStatFactory.ALL_STATS.get(statDimension);
if (invocationStat != null) {
return invocationStat;
}
if (i < maxAttempts - 1) {
Thread.sleep(retryDelayMillis);
}
}
return null;
}

private boolean waitForAvailableTransport(ProviderInfo providerInfo, int maxAttempts, int retryDelayMillis)
throws InterruptedException {
for (int i = 0; i < maxAttempts; i++) {
ClientTransport clientTransport = consumerConfig.getConsumerBootstrap().getCluster().getConnectionHolder()
.getAvailableClientTransport(providerInfo);
if (clientTransport != null && clientTransport.isAvailable()) {
return true;
}
if (i < maxAttempts - 1) {
Thread.sleep(retryDelayMillis);
}
}
return false;
}
}
6 changes: 5 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,11 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.8.1</version>
<version>2.22.2</version>
<configuration>
<forkCount>1</forkCount>
<reuseForks>true</reuseForks>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public class ConsulRegistryAclTest {

private static final String CONSUL_SERVICE_NAME = "test-service";

private static final int STARTUP_TIMEOUT = 60;

private ConsulProcess consul;

private RegistryConfig registryConfig;
Expand All @@ -66,6 +68,7 @@ public class ConsulRegistryAclTest {
public void setup() {
consul = ConsulStarterBuilder.consulStarter()
.withConsulVersion("1.4.0")
.withWaitTimeout(STARTUP_TIMEOUT)
.withToken(token)
.withCustomConfig("{\n" +
" \"acl\": {\n" +
Expand All @@ -92,9 +95,14 @@ public void setup() {

@After
public void tearDown() {
registry.destroy();
consul.close();
if (registry != null) {
registry.destroy();
}
if (consul != null) {
consul.close();
}
registry = null;
consul = null;
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public class ConsulRegistryTest {

private static final String CONSUL_SERVICE_NAME = "test-service";

private static final int STARTUP_TIMEOUT = 60;

private ConsulProcess consul;

private RegistryConfig registryConfig;
Expand All @@ -64,6 +66,7 @@ public class ConsulRegistryTest {
public void setup() {
consul = ConsulStarterBuilder.consulStarter()
.withConsulVersion("1.4.0")
.withWaitTimeout(STARTUP_TIMEOUT)
.build()
.start();

Expand All @@ -78,9 +81,14 @@ public void setup() {

@After
public void tearDown() {
registry.destroy();
consul.close();
if (registry != null) {
registry.destroy();
}
if (consul != null) {
consul.close();
}
registry = null;
consul = null;
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion registry/registry-sofa/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
<jdk>1.8</jdk>
</activation>
<properties>
<exculdeTests>**/NotExistTest.java</exculdeTests>
<exculdeTests>**/SofaRegistryTest.java</exculdeTests>
</properties>
</profile>
</profiles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,13 @@ public void testDefaultMetadataSize() {
Assert.assertTrue(e.getCause().getCause().getMessage().contains("Header size exceeded max allowed size (65536)"));
}

consumerConfig.unRefer();
consumerConfig = new ConsumerConfig<>();
consumerConfig.setInterfaceId(SampleService.class.getName())
.setProtocol(RpcConstants.PROTOCOL_TYPE_TRIPLE)
.setDirectUrl("tri://127.0.0.1:" + port);
Comment on lines +435 to +439
sampleService = consumerConfig.refer();

try {
RpcInvokeContext.getContext().addCustomHeader("grpc_custom_header", buildMsg(25));
sampleService.messageSize(msg, 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ public void test() throws InterruptedException {
String result2 = helloService2.sayHello("impl2", 2);
Assert.isTrue(result2.contains("impl2"), "anotherHelloService2 run fail, result is " + result2);

Thread.currentThread().setContextClassLoader(clientClassloader);
consumerConfig1.unRefer();
consumerConfig2.unRefer();

Thread.currentThread().setContextClassLoader(cl1);
providerConfig1.unExport();
Thread.currentThread().setContextClassLoader(cl2);
Expand Down Expand Up @@ -167,6 +171,9 @@ public void test() throws InterruptedException {
String result3 = helloService3.sayHello("impl3", 2);
Assert.isTrue(result3.contains("impl3"), "anotherHelloService3 run fail, result is " + result3);

Thread.currentThread().setContextClassLoader(clientClassloader2);
consumerConfig3.unRefer();

Thread.currentThread().setContextClassLoader(cl3);
providerConfig3.unExport();

Expand Down
Loading