|
|
@ -18,7 +18,9 @@
|
|
|
|
package com.tencent.cloud.rpc.enhancement.plugin;
|
|
|
|
package com.tencent.cloud.rpc.enhancement.plugin;
|
|
|
|
|
|
|
|
|
|
|
|
import java.net.URI;
|
|
|
|
import java.net.URI;
|
|
|
|
|
|
|
|
import java.net.URISyntaxException;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
|
|
|
|
|
|
|
import com.tencent.cloud.common.metadata.MetadataContext;
|
|
|
|
import com.tencent.cloud.common.metadata.MetadataContext;
|
|
|
|
import com.tencent.cloud.common.util.ApplicationContextAwareUtils;
|
|
|
|
import com.tencent.cloud.common.util.ApplicationContextAwareUtils;
|
|
|
@ -117,7 +119,7 @@ public class EnhancedPluginContextTest {
|
|
|
|
EnhancedPluginContext enhancedPluginContext = new EnhancedPluginContext();
|
|
|
|
EnhancedPluginContext enhancedPluginContext = new EnhancedPluginContext();
|
|
|
|
enhancedPluginContext.setRequest(requestContext);
|
|
|
|
enhancedPluginContext.setRequest(requestContext);
|
|
|
|
enhancedPluginContext.setResponse(responseContext);
|
|
|
|
enhancedPluginContext.setResponse(responseContext);
|
|
|
|
enhancedPluginContext.setTargetServiceInstance(new DefaultServiceInstance());
|
|
|
|
enhancedPluginContext.setTargetServiceInstance(new DefaultServiceInstance(), null);
|
|
|
|
enhancedPluginContext.setThrowable(mock(Exception.class));
|
|
|
|
enhancedPluginContext.setThrowable(mock(Exception.class));
|
|
|
|
enhancedPluginContext.setDelay(0);
|
|
|
|
enhancedPluginContext.setDelay(0);
|
|
|
|
assertThat(enhancedPluginContext.getRequest()).isNotNull();
|
|
|
|
assertThat(enhancedPluginContext.getRequest()).isNotNull();
|
|
|
@ -148,7 +150,26 @@ public class EnhancedPluginContextTest {
|
|
|
|
|
|
|
|
|
|
|
|
doReturn(configuration).when(sdkContext).getConfig();
|
|
|
|
doReturn(configuration).when(sdkContext).getConfig();
|
|
|
|
|
|
|
|
|
|
|
|
enhancedPluginRunner = new DefaultEnhancedPluginRunner(Arrays.asList(enhancedPlugin2), null, sdkContext);
|
|
|
|
enhancedPluginRunner = new DefaultEnhancedPluginRunner(Collections.singletonList(enhancedPlugin2), null, sdkContext);
|
|
|
|
enhancedPluginRunner.run(EnhancedPluginType.Client.POST, enhancedPluginContext);
|
|
|
|
enhancedPluginRunner.run(EnhancedPluginType.Client.POST, enhancedPluginContext);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
public void testSetTargetServiceInstance() throws URISyntaxException {
|
|
|
|
|
|
|
|
EnhancedPluginContext enhancedPluginContext = new EnhancedPluginContext();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// targetServiceInstance != null
|
|
|
|
|
|
|
|
DefaultServiceInstance testDefaultServiceInstance = new DefaultServiceInstance();
|
|
|
|
|
|
|
|
testDefaultServiceInstance.setPort(1);
|
|
|
|
|
|
|
|
enhancedPluginContext.setTargetServiceInstance(testDefaultServiceInstance, null);
|
|
|
|
|
|
|
|
assertThat(enhancedPluginContext.getTargetServiceInstance().getPort()).isEqualTo(1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// targetServiceInstance == null && url != null
|
|
|
|
|
|
|
|
enhancedPluginContext.setTargetServiceInstance(null, new URI("https://www.qq.com"));
|
|
|
|
|
|
|
|
assertThat(enhancedPluginContext.getTargetServiceInstance().getPort()).isEqualTo(443);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// targetServiceInstance == null && url == null
|
|
|
|
|
|
|
|
enhancedPluginContext.setTargetServiceInstance(null, null);
|
|
|
|
|
|
|
|
assertThat(enhancedPluginContext.getTargetServiceInstance().getPort()).isEqualTo(0);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|