Skip to content

Commit

Permalink
fix: set default 0 when get method timeout config (#1422)
Browse files Browse the repository at this point in the history
* fix: default 0 when get method timeout config

* format

---------

Co-authored-by: Lo1nt <[email protected]>
  • Loading branch information
Lo1nt and Lo1nt authored Jul 29, 2024
1 parent d163820 commit ff2471e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public MethodConfig setParameters(Map<String, String> parameters) {
* @return the timeout
*/
public Integer getTimeout() {
return timeout;
return timeout == null ? 0 : timeout;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.alipay.sofa.rpc.config.AbstractInterfaceConfig;
import com.alipay.sofa.rpc.config.ApplicationConfig;
import com.alipay.sofa.rpc.config.MethodConfig;
import com.alipay.sofa.rpc.config.ProviderConfig;
import com.alipay.sofa.rpc.config.RegistryConfig;
import com.alipay.sofa.rpc.core.exception.SofaRpcRuntimeException;
import com.alipay.sofa.rpc.listener.ConfigListener;
Expand Down Expand Up @@ -50,6 +51,21 @@
* @version : AbstractInterfaceConfigTest.java, v 0.1 2022年01月25日 4:46 下午 zhaowang
*/
public class AbstractInterfaceConfigTest {
@Test
public void testMethodTimeout() {
MethodConfig config = new MethodConfig();
config.setTimeout(null);

ProviderConfig p = new ProviderConfig();
p.setMethods(new HashMap<>());
p.getMethods().put("test", config);

try {
Assert.assertFalse(p.hasTimeout());
} catch (Exception e) {
Assert.fail("exception should not appears: " + e.getMessage());
}
}

@Test
public void testDefaultValue() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,17 @@ public void convertProviderToUrls() throws Exception {
Assert.assertEquals(serverConfig3.getPort(), providerInfo3.getPort());
Assert.assertEquals(providerConfig.getAppName(), providerInfo3.getAttr(ProviderInfoAttrs.ATTR_APP_NAME));
Assert.assertEquals(providerConfig.getTimeout(), providerInfo3.getDynamicAttr(ProviderInfoAttrs.ATTR_TIMEOUT));

ProviderConfig<?> providerConfig2 = new ProviderConfig<>();
providerConfig2.setMethods(new HashMap<>());
providerConfig2.getMethods().put("test", new MethodConfig().setTimeout(null));
Assert.assertNotNull(providerConfig2.getTimeout());
String s4 = SofaRegistryHelper.convertProviderToUrls(providerConfig2, serverConfig);
Assert.assertNotNull(s3);
ProviderInfo providerInfo4 = SofaRegistryHelper.parseProviderInfo(s4);
Assert.assertEquals(0, providerInfo4.getDynamicAttr(".test.timeout"));
Assert.assertFalse(providerConfig2.hasTimeout());

}

@Test
Expand Down

0 comments on commit ff2471e

Please sign in to comment.