Search in sources :

Example 21 with Invocation

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"));
}
Also used : Invocation(org.apache.servicecomb.core.Invocation) OperationMeta(org.apache.servicecomb.core.definition.OperationMeta) Test(org.junit.Test)

Example 22 with Invocation

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);
}
Also used : Invocation(org.apache.servicecomb.core.Invocation) OperationMeta(org.apache.servicecomb.core.definition.OperationMeta) Test(org.junit.Test)

Example 23 with Invocation

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);
}
Also used : HystrixCommandKey(com.netflix.hystrix.HystrixCommandKey) Invocation(org.apache.servicecomb.core.Invocation) HystrixCommandProperties(com.netflix.hystrix.HystrixCommandProperties) OperationMeta(org.apache.servicecomb.core.definition.OperationMeta) Test(org.junit.Test)

Example 24 with Invocation

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));
}
Also used : Response(org.apache.servicecomb.swagger.invocation.Response) Invocation(org.apache.servicecomb.core.Invocation) InvocationException(org.apache.servicecomb.swagger.invocation.exception.InvocationException) HystrixCommandProperties(com.netflix.hystrix.HystrixCommandProperties) OperationMeta(org.apache.servicecomb.core.definition.OperationMeta) Test(org.junit.Test)

Example 25 with Invocation

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);
}
Also used : Response(org.apache.servicecomb.swagger.invocation.Response) Invocation(org.apache.servicecomb.core.Invocation) HystrixCommandProperties(com.netflix.hystrix.HystrixCommandProperties) OperationMeta(org.apache.servicecomb.core.definition.OperationMeta) Test(org.junit.Test)

Aggregations

Invocation (org.apache.servicecomb.core.Invocation)66 Test (org.junit.Test)50 OperationMeta (org.apache.servicecomb.core.definition.OperationMeta)23 Response (org.apache.servicecomb.swagger.invocation.Response)19 AsyncResponse (org.apache.servicecomb.swagger.invocation.AsyncResponse)16 MockUp (mockit.MockUp)11 HystrixCommandProperties (com.netflix.hystrix.HystrixCommandProperties)9 ArrayList (java.util.ArrayList)9 Server (com.netflix.loadbalancer.Server)8 HashMap (java.util.HashMap)8 Holder (javax.xml.ws.Holder)8 Expectations (mockit.Expectations)7 Mock (mockit.Mock)7 InvocationException (org.apache.servicecomb.swagger.invocation.exception.InvocationException)5 AbstractSpan (org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)5 Map (java.util.Map)4 AbstractConfiguration (org.apache.commons.configuration.AbstractConfiguration)4 RestOperationMeta (org.apache.servicecomb.common.rest.definition.RestOperationMeta)4 Endpoint (org.apache.servicecomb.core.Endpoint)4 CseServer (org.apache.servicecomb.loadbalance.CseServer)4