Search in sources :

Example 41 with Invocation

use of io.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(io.servicecomb.core.Response) Invocation(io.servicecomb.core.Invocation) HystrixCommandProperties(com.netflix.hystrix.HystrixCommandProperties) OperationMeta(io.servicecomb.core.definition.OperationMeta) Test(org.junit.Test)

Example 42 with Invocation

use of io.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(io.servicecomb.core.Invocation) OperationMeta(io.servicecomb.core.definition.OperationMeta) Test(org.junit.Test)

Example 43 with Invocation

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

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(io.servicecomb.core.Invocation) HystrixCommandProperties(com.netflix.hystrix.HystrixCommandProperties) OperationMeta(io.servicecomb.core.definition.OperationMeta) Test(org.junit.Test)

Example 44 with Invocation

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

the class TestProviderBizkeeperHandler method testCreateBizkeeperCommand.

@Test
public void testCreateBizkeeperCommand() {
    HystrixPlugins.reset();
    ProviderBizkeeperHanlder providerBizkeeperHanlder = new ProviderBizkeeperHanlder();
    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 = providerBizkeeperHanlder.createBizkeeperCommand(invocation);
    Assert.assertNotNull(command);
}
Also used : Invocation(io.servicecomb.core.Invocation) OperationMeta(io.servicecomb.core.definition.OperationMeta) Test(org.junit.Test)

Example 45 with Invocation

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

the class TestLoadbalanceHandler method testLoadbalanceHandlerHandleWithCseServer.

@Test
public void testLoadbalanceHandlerHandleWithCseServer() throws Exception {
    boolean status = true;
    new MockUp<LoadbalanceHandler>() {

        @Mock
        private LoadBalancer createLoadBalancer(String appId, String microserviceName, String microserviceVersionRule, String transportName) {
            return lb;
        }
    };
    LoadbalanceHandler lh = new LoadbalanceHandler();
    Invocation invocation = Mockito.mock(Invocation.class);
    Mockito.when(invocation.getConfigTransportName()).thenReturn("baadshah");
    Mockito.when(invocation.getMicroserviceVersionRule()).thenReturn("VERSION_RULE_LATEST");
    AsyncResponse asyncResp = Mockito.mock(AsyncResponse.class);
    Mockito.when(invocation.getAppId()).thenReturn("test");
    Mockito.when(invocation.getMicroserviceName()).thenReturn("test");
    CseServer server = Mockito.mock(CseServer.class);
    Mockito.when((CseServer) lb.chooseServer()).thenReturn(server);
    try {
        lh.handle(invocation, asyncResp);
    } catch (Exception e) {
        status = false;
    }
    Assert.assertTrue(status);
}
Also used : Invocation(io.servicecomb.core.Invocation) MockUp(mockit.MockUp) AsyncResponse(io.servicecomb.core.AsyncResponse) Test(org.junit.Test)

Aggregations

Invocation (io.servicecomb.core.Invocation)70 Test (org.junit.Test)55 OperationMeta (io.servicecomb.core.definition.OperationMeta)29 Response (io.servicecomb.core.Response)20 AsyncResponse (io.servicecomb.core.AsyncResponse)19 RestOperationMeta (io.servicecomb.common.rest.definition.RestOperationMeta)10 HystrixCommandProperties (com.netflix.hystrix.HystrixCommandProperties)9 OperationProtobuf (io.servicecomb.codec.protobuf.definition.OperationProtobuf)9 WrapSchema (io.servicecomb.codec.protobuf.utils.WrapSchema)9 MockUp (mockit.MockUp)9 InvocationException (io.servicecomb.core.exception.InvocationException)8 Endpoint (io.servicecomb.core.Endpoint)7 IpPort (io.servicecomb.foundation.common.net.IpPort)6 HttpClientRequest (io.vertx.core.http.HttpClientRequest)6 HttpClientResponse (io.vertx.core.http.HttpClientResponse)6 URLPathBuilder (io.servicecomb.common.rest.definition.path.URLPathBuilder)5 Buffer (io.vertx.core.buffer.Buffer)5 HttpClient (io.vertx.core.http.HttpClient)4 ArrayList (java.util.ArrayList)4 ProduceProcessor (io.servicecomb.common.rest.codec.produce.ProduceProcessor)3