use of org.apache.servicecomb.core.Invocation in project incubator-servicecomb-java-chassis by apache.
the class TestBizkeeperCommand method testConstructProvider.
@Test
public void testConstructProvider() {
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> response = bizkeeperCommand.construct();
Assert.assertNotNull(response);
}
use of org.apache.servicecomb.core.Invocation in project incubator-servicecomb-java-chassis by apache.
the class TestBizkeeperCommand method testGetCacheKeyWithContextInitializedProvider.
@Test
public void testGetCacheKeyWithContextInitializedProvider() {
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));
HystrixRequestContext.initializeContext();
String cacheKey = bizkeeperCommand.getCacheKey();
Assert.assertNotNull(cacheKey);
}
use of org.apache.servicecomb.core.Invocation in project incubator-servicecomb-java-chassis by apache.
the class TestBizkeeperCommand method testGetCacheKeyWithContextInitializedConsumer.
@Test
public void testGetCacheKeyWithContextInitializedConsumer() {
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));
HystrixRequestContext.initializeContext();
String cacheKey = bizkeeperCommand.getCacheKey();
Assert.assertNotNull(cacheKey);
}
use of org.apache.servicecomb.core.Invocation in project incubator-servicecomb-java-chassis by apache.
the class TestVertxHttpMethod method testDoMethodNullPointerException.
@Test
public void testDoMethodNullPointerException(@Mocked HttpClient httpClient) throws Exception {
Context context = new MockUp<Context>() {
@Mock
public void runOnContext(Handler<Void> action) {
action.handle(null);
}
}.getMockInstance();
HttpClientWithContext httpClientWithContext = new HttpClientWithContext(httpClient, context);
Invocation invocation = mock(Invocation.class);
AsyncResponse asyncResp = mock(AsyncResponse.class);
try {
this.doMethod(httpClientWithContext, invocation, asyncResp);
fail("Expect to throw NullPointerException, but got none");
} catch (NullPointerException e) {
}
}
use of org.apache.servicecomb.core.Invocation in project incubator-servicecomb-java-chassis by apache.
the class TestHighwayCodec method testDecodeResponse.
@Test
public void testDecodeResponse() throws Exception {
Invocation invocation = Mockito.mock(Invocation.class);
Mockito.when(operationProtobuf.findResponseSchema(200)).thenReturn(Mockito.mock(WrapSchema.class));
Map<String, String> context = new HashMap<>();
Mockito.when(invocation.getContext()).thenReturn(context);
TcpData tcpData = Mockito.mock(TcpData.class);
Mockito.when(tcpData.getHeaderBuffer()).thenReturn(bodyBuffer);
commonMock();
ResponseHeader header = new ResponseHeader();
header.setStatusCode(200);
header.setContext(new HashMap<>());
header.getContext().put("a", "10");
Buffer responseBuf = HighwayCodec.encodeResponse(0, header, null, null, new ProtobufFeature());
TcpData tcp = new TcpData(responseBuf.slice(23, responseBuf.length()), null);
Response response = HighwayCodec.decodeResponse(invocation, operationProtobuf, tcp, null);
Assert.assertEquals("10", invocation.getContext().get("a"));
Assert.assertEquals(200, response.getStatusCode());
}
Aggregations