Search in sources :

Example 71 with Invocation

use of org.apache.servicecomb.core.Invocation in project java-chassis by ServiceComb.

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)

Example 72 with Invocation

use of org.apache.servicecomb.core.Invocation in project java-chassis by ServiceComb.

the class TestBizkeeperCommand method testResumeWithFallbackConsumer.

@Test
public void testResumeWithFallbackConsumer() {
    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 ConsumerBizkeeperCommand("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)

Example 73 with Invocation

use of org.apache.servicecomb.core.Invocation in project java-chassis by ServiceComb.

the class TestCommandKey method testToHystrixCommandKey.

@Test
public void testToHystrixCommandKey() {
    Invocation invocation = Mockito.mock(Invocation.class);
    Mockito.when(invocation.getOperationMeta()).thenReturn(Mockito.mock(OperationMeta.class));
    Mockito.when(invocation.getOperationMeta().getMicroserviceQualifiedName()).thenReturn("test1");
    Assert.assertNotNull(invocation);
    HystrixCommandKey hystrixCommandGroupKey = CommandKey.toHystrixCommandKey("groupname", invocation);
    Assert.assertNotNull(hystrixCommandGroupKey);
}
Also used : HystrixCommandKey(com.netflix.hystrix.HystrixCommandKey) Invocation(org.apache.servicecomb.core.Invocation) OperationMeta(org.apache.servicecomb.core.definition.OperationMeta) Test(org.junit.Test)

Example 74 with Invocation

use of org.apache.servicecomb.core.Invocation in project java-chassis by ServiceComb.

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 75 with Invocation

use of org.apache.servicecomb.core.Invocation in project java-chassis by ServiceComb.

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

Aggregations

Invocation (org.apache.servicecomb.core.Invocation)204 Test (org.junit.Test)125 OperationMeta (org.apache.servicecomb.core.definition.OperationMeta)52 ArrayList (java.util.ArrayList)39 HashMap (java.util.HashMap)37 Response (org.apache.servicecomb.swagger.invocation.Response)37 Before (org.junit.Before)29 MockUp (mockit.MockUp)26 AsyncResponse (org.apache.servicecomb.swagger.invocation.AsyncResponse)23 Expectations (mockit.Expectations)20 InvocationFinishEvent (org.apache.servicecomb.core.event.InvocationFinishEvent)20 MicroserviceInstance (org.apache.servicecomb.registry.api.registry.MicroserviceInstance)19 HystrixCommandProperties (com.netflix.hystrix.HystrixCommandProperties)18 Transport (org.apache.servicecomb.core.Transport)18 RoutingContext (io.vertx.ext.web.RoutingContext)17 Map (java.util.Map)17 ServerAccessLogEvent (org.apache.servicecomb.core.event.ServerAccessLogEvent)17 List (java.util.List)16 Endpoint (org.apache.servicecomb.core.Endpoint)16 InvocationException (org.apache.servicecomb.swagger.invocation.exception.InvocationException)15