use of org.apache.servicecomb.core.Invocation in project incubator-servicecomb-java-chassis by apache.
the class TestConfiguration method testConfiguration.
@Test
public void testConfiguration() {
assertNotNull(Configuration.INSTANCE);
assertEquals("returnnull", Configuration.FALLBACKPOLICY_POLICY_RETURN);
assertEquals("throwexception", Configuration.FALLBACKPOLICY_POLICY_THROW);
Configuration c = Configuration.INSTANCE;
Invocation invocation = Mockito.mock(Invocation.class);
String test2 = invocation.getMicroserviceName();
Mockito.when(invocation.getOperationMeta()).thenReturn(Mockito.mock(OperationMeta.class));
Mockito.when(invocation.getOperationMeta().getMicroserviceName()).thenReturn("testqualify");
int res = c.getIsolationTimeoutInMilliseconds("groupname", test2, "testqualify");
assertEquals(30000, res);
boolean b1 = c.getIsolationTimeoutEnabled("groupname", test2, "testqualify");
assertFalse(b1);
int res1 = c.getIsolationMaxConcurrentRequests("groupname", test2, "testqualify");
assertEquals(1000, res1);
boolean b2 = c.isCircuitBreakerEnabled("groupname", test2, "testqualify");
assertTrue(b2);
String str = c.getFallbackPolicyPolicy("groupname", test2, "testqualify");
// no need to give default value now
assertEquals(null, str);
assertFalse(c.isCircuitBreakerForceOpen("groupname", test2, "testqualify"));
assertFalse(c.isCircuitBreakerForceClosed("groupname", test2, "testqualify"));
assertEquals(15000, c.getCircuitBreakerSleepWindowInMilliseconds("groupname", test2, "testqualify"));
assertEquals(20, c.getCircuitBreakerRequestVolumeThreshold("groupname", test2, "testqualify"));
assertEquals(50, c.getCircuitBreakerErrorThresholdPercentage("groupname", test2, "testqualify"));
assertTrue(c.isFallbackEnabled("groupname", test2, "testqualify"));
}
use of org.apache.servicecomb.core.Invocation in project incubator-servicecomb-java-chassis by apache.
the class TestConsumerBizkeeperHandler method testCreateBizkeeperCommand.
@Test
public void testCreateBizkeeperCommand() {
HystrixPlugins.reset();
ConsumerBizkeeperHandler consumerBizkeeperHandler = new ConsumerBizkeeperHandler();
Invocation invocation = Mockito.mock(Invocation.class);
Mockito.when(invocation.getOperationMeta()).thenReturn(Mockito.mock(OperationMeta.class));
Mockito.when(invocation.getOperationMeta().getMicroserviceQualifiedName()).thenReturn("test1");
CommandKey.toHystrixCommandGroupKey("groupname", invocation);
CommandKey.toHystrixCommandKey("groupname", invocation);
BizkeeperCommand command = consumerBizkeeperHandler.createBizkeeperCommand(invocation);
Assert.assertNotNull(command);
}
use of org.apache.servicecomb.core.Invocation in project incubator-servicecomb-java-chassis by apache.
the class TestHystrixPropertiesStrategyExt method testGetCommandPropertiesCacheKey.
@Test
public void testGetCommandPropertiesCacheKey() {
assertNotNull(HystrixPropertiesStrategyExt.getInstance());
HystrixPropertiesStrategyExt hps = HystrixPropertiesStrategyExt.getInstance();
HystrixCommandKey commandKey = Mockito.mock(HystrixCommandKey.class);
Invocation invocation = Mockito.mock(Invocation.class);
Mockito.when(invocation.getOperationMeta()).thenReturn(Mockito.mock(OperationMeta.class));
Mockito.when(invocation.getOperationMeta().getMicroserviceName()).thenReturn("testqualify");
HystrixCommandProperties.Setter setter = HystrixCommandProperties.Setter().withRequestCacheEnabled(true).withRequestLogEnabled(false).withFallbackIsolationSemaphoreMaxConcurrentRequests(Configuration.INSTANCE.getFallbackMaxConcurrentRequests("groupname", "testing", invocation.getOperationMeta().getMicroserviceQualifiedName()));
String str1 = hps.getCommandPropertiesCacheKey(commandKey, setter);
Assert.assertNull(str1);
}
use of org.apache.servicecomb.core.Invocation in project incubator-servicecomb-java-chassis by apache.
the class TestBizkeeperCommand method testGetCacheKeyProvider.
@Test
public void testGetCacheKeyProvider() {
Invocation invocation = Mockito.mock(Invocation.class);
Mockito.when(invocation.getOperationMeta()).thenReturn(Mockito.mock(OperationMeta.class));
Mockito.when(invocation.getOperationMeta().getMicroserviceQualifiedName()).thenReturn("test1");
HystrixCommandProperties.Setter setter = HystrixCommandProperties.Setter().withRequestCacheEnabled(true).withRequestLogEnabled(false);
BizkeeperCommand bizkeeperCommand = new ProviderBizkeeperCommand("groupname", invocation, HystrixObservableCommand.Setter.withGroupKey(CommandKey.toHystrixCommandGroupKey("groupname", invocation)).andCommandKey(CommandKey.toHystrixCommandKey("groupname", invocation)).andCommandPropertiesDefaults(setter));
String str = bizkeeperCommand.getCacheKey();
Assert.assertNull(str);
Response resp = Mockito.mock(Response.class);
Mockito.when(resp.isFailed()).thenReturn(false);
Assert.assertEquals(false, bizkeeperCommand.isFailedResponse(resp));
Mockito.when(resp.isFailed()).thenReturn(true);
InvocationException excp = Mockito.mock(InvocationException.class);
Mockito.when(resp.getResult()).thenReturn(excp);
Mockito.when(excp.getStatusCode()).thenReturn(400);
Assert.assertEquals(false, bizkeeperCommand.isFailedResponse(resp));
Mockito.when(resp.getResult()).thenReturn(excp);
Mockito.when(excp.getStatusCode()).thenReturn(590);
Assert.assertEquals(true, bizkeeperCommand.isFailedResponse(resp));
}
use of org.apache.servicecomb.core.Invocation in project incubator-servicecomb-java-chassis by apache.
the class TestBizkeeperCommand method testResumeWithFallbackProvider.
@Test
public void testResumeWithFallbackProvider() {
Invocation invocation = Mockito.mock(Invocation.class);
Mockito.when(invocation.getOperationMeta()).thenReturn(Mockito.mock(OperationMeta.class));
Mockito.when(invocation.getOperationMeta().getMicroserviceQualifiedName()).thenReturn("test1");
HystrixCommandProperties.Setter setter = HystrixCommandProperties.Setter().withRequestCacheEnabled(true).withRequestLogEnabled(false);
BizkeeperCommand bizkeeperCommand = new ProviderBizkeeperCommand("groupname", invocation, HystrixObservableCommand.Setter.withGroupKey(CommandKey.toHystrixCommandGroupKey("groupname", invocation)).andCommandKey(CommandKey.toHystrixCommandKey("groupname", invocation)).andCommandPropertiesDefaults(setter));
Observable<Response> observe = bizkeeperCommand.resumeWithFallback();
Assert.assertNotNull(observe);
}
Aggregations