Java Code Examples for org.apache.servicecomb.core.Invocation#getOperationMeta()
The following examples show how to use
org.apache.servicecomb.core.Invocation#getOperationMeta() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestInvocationToHttpServletRequest.java From servicecomb-java-chassis with Apache License 2.0 | 6 votes |
@Test public void testGetRemoteAddressEmpty(@Mocked Invocation invocation) throws Exception { handlerContext.remove(Const.REMOTE_ADDRESS); new Expectations() { { invocation.getOperationMeta(); result = operationMeta; operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION); result = swaggerOperation; invocation.getHandlerContext(); result = handlerContext; } }; InvocationToHttpServletRequest request = new InvocationToHttpServletRequest(invocation); String addr = request.getRemoteAddr(); String host = request.getRemoteHost(); int port = request.getRemotePort(); Assert.assertEquals(addr, ""); Assert.assertEquals(host, ""); Assert.assertEquals(port, 0); }
Example 2
Source File: QpsControllerManagerTest.java From servicecomb-java-chassis with Apache License 2.0 | 5 votes |
@Test public void testGetOrCreate(@Mocked Invocation invocation, @Mocked OperationMeta operationMeta) { new Expectations() { { invocation.getOperationMeta(); result = operationMeta; invocation.getSchemaId(); result = "server"; operationMeta.getSchemaQualifiedName(); result = "server.test"; } }; QpsControllerManager testQpsControllerManager = new QpsControllerManager() .setConfigKeyPrefix(Config.CONSUMER_LIMIT_KEY_PREFIX); initTestQpsControllerManager(testQpsControllerManager, invocation, operationMeta); // pojo setConfigWithDefaultPrefix("pojo", 100); QpsController qpsController = testQpsControllerManager.getOrCreate("pojo", invocation); Assert.assertEquals("pojo", qpsController.getKey()); Assert.assertTrue(100 == qpsController.getQpsLimit()); qpsController = testQpsControllerManager.getOrCreate("pojo2", invocation); Assert.assertEquals("pojo2", qpsController.getKey()); Assert.assertNull(qpsController.getQpsLimit()); qpsController = testQpsControllerManager.getOrCreate("poj", invocation); Assert.assertEquals("poj", qpsController.getKey()); Assert.assertNull(qpsController.getQpsLimit()); ArchaiusUtils.setProperty("servicecomb.flowcontrol.Consumer.qps.limit.poj.server", 10000); qpsController = testQpsControllerManager.getOrCreate("poj", invocation); Assert.assertEquals("poj.server", qpsController.getKey()); Assert.assertEquals(qpsController.getQpsLimit(), (Integer) 10000); ArchaiusUtils.setProperty("servicecomb.flowcontrol.Consumer.qps.limit.poj.server.test", 20000); qpsController = testQpsControllerManager.getOrCreate("poj", invocation); Assert.assertEquals("poj.server.test", qpsController.getKey()); Assert.assertEquals(qpsController.getQpsLimit(), (Integer) 20000); testGetOrCreateCommon(testQpsControllerManager, invocation, operationMeta); }
Example 3
Source File: QpsControllerManagerTest.java From servicecomb-java-chassis with Apache License 2.0 | 5 votes |
@Test public void testMock() { Invocation invocation = getMockInvocation("service", "schema", "oper"); OperationMeta operationMeta = invocation.getOperationMeta(); SchemaMeta schemaMeta = operationMeta.getSchemaMeta(); Assert.assertEquals("service", operationMeta.getMicroserviceName()); Assert.assertEquals("service.schema.oper", operationMeta.getMicroserviceQualifiedName()); Assert.assertEquals("schema.oper", operationMeta.getSchemaQualifiedName()); Assert.assertEquals("schema", schemaMeta.getSchemaId()); }
Example 4
Source File: TestProviderQpsFlowControlHandler.java From servicecomb-java-chassis with Apache License 2.0 | 5 votes |
@Test public void testGlobalQpsControl(final @Injectable Invocation invocation, final @Injectable AsyncResponse asyncResp) throws Exception { new Expectations() { { invocation.getHandlerIndex(); result = 0; invocation.getContext(Const.SRC_MICROSERVICE); result = "test"; invocation.getOperationMeta(); result = QpsControllerManagerTest.getMockOperationMeta("pojo", "server", "opr"); invocation.getSchemaId(); result = "server"; asyncResp.producerFail((Throwable) any); result = new RuntimeException("test error"); } }; ProviderQpsFlowControlHandler gHandler = new ProviderQpsFlowControlHandler(); gHandler.handle(invocation, asyncResp); ArchaiusUtils.setProperty(Config.PROVIDER_LIMIT_KEY_GLOBAL, 3); expectedException.expect(RuntimeException.class); expectedException.expectMessage("test error"); gHandler.handle(invocation, asyncResp); gHandler.handle(invocation, asyncResp); }
Example 5
Source File: TestDefaultHttpClientFilter.java From servicecomb-java-chassis with Apache License 2.0 | 5 votes |
@Test public void testAfterReceiveResponseNullProduceProcessor(@Mocked Invocation invocation, @Mocked HttpServletResponseEx responseEx, @Mocked OperationMeta operationMeta, @Mocked RestOperationMeta swaggerRestOperation) throws Exception { CommonExceptionData data = new CommonExceptionData("abcd"); new Expectations() { { invocation.getOperationMeta(); result = operationMeta; operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION); result = swaggerRestOperation; invocation.findResponseType(403); result = SimpleType.constructUnsafe(CommonExceptionData.class); responseEx.getStatus(); result = 403; responseEx.getStatusType(); result = Status.FORBIDDEN; responseEx.getBodyBuffer(); result = Buffer.buffer(JsonUtils.writeValueAsString(data).getBytes()); } }; Response response = filter.afterReceiveResponse(invocation, responseEx); Assert.assertEquals(403, response.getStatusCode()); Assert.assertEquals("Forbidden", response.getReasonPhrase()); Assert.assertEquals(InvocationException.class, response.<InvocationException>getResult().getClass()); InvocationException invocationException = response.getResult(); Assert.assertEquals( 403, invocationException.getStatusCode()); Assert.assertEquals( "CommonExceptionData [message=abcd]", invocationException.getErrorData().toString()); }
Example 6
Source File: TestDefaultHttpClientFilter.java From servicecomb-java-chassis with Apache License 2.0 | 5 votes |
@Test public void testAfterReceiveResponseNormal(@Mocked Invocation invocation, @Mocked HttpServletResponseEx responseEx, @Mocked Buffer bodyBuffer, @Mocked OperationMeta operationMeta, @Mocked RestOperationMeta swaggerRestOperation, @Mocked ProduceProcessor produceProcessor) throws Exception { MultiMap responseHeader = new CaseInsensitiveHeaders(); responseHeader.add("b", "bValue"); Object decodedResult = new Object(); new Expectations() { { responseEx.getHeader(HttpHeaders.CONTENT_TYPE); result = "json"; responseEx.getHeaderNames(); result = Arrays.asList("a", "b"); responseEx.getHeaders("b"); result = responseHeader.getAll("b"); swaggerRestOperation.findProduceProcessor("json"); result = produceProcessor; produceProcessor.decodeResponse(bodyBuffer, (JavaType) any); result = decodedResult; invocation.getOperationMeta(); result = operationMeta; operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION); result = swaggerRestOperation; responseEx.getStatusType(); result = Status.OK; } }; Response response = filter.afterReceiveResponse(invocation, responseEx); Assert.assertSame(decodedResult, response.getResult()); Assert.assertEquals(1, response.getHeaders().getHeaderMap().size()); Assert.assertEquals(response.getHeaders().getHeader("b"), Arrays.asList("bValue")); }
Example 7
Source File: RestServerCodecFilter.java From servicecomb-java-chassis with Apache License 2.0 | 5 votes |
private CompletableFuture<Invocation> decodeRequest(Invocation invocation) { HttpTransportContext transportContext = invocation.getTransportContext(); HttpServletRequestEx requestEx = transportContext.getRequestEx(); OperationMeta operationMeta = invocation.getOperationMeta(); RestOperationMeta restOperationMeta = operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION); Map<String, Object> swaggerArguments = RestCodec.restToArgs(requestEx, restOperationMeta); invocation.setSwaggerArguments(swaggerArguments); return CompletableFuture.completedFuture(invocation); }
Example 8
Source File: ClientRestArgsFilter.java From servicecomb-java-chassis with Apache License 2.0 | 5 votes |
@Override @SuppressWarnings("unchecked") public void beforeSendRequest(Invocation invocation, HttpServletRequestEx requestEx) { RestClientRequestImpl restClientRequest = (RestClientRequestImpl) invocation.getHandlerContext() .get(RestConst.INVOCATION_HANDLER_REQUESTCLIENT); OperationMeta operationMeta = invocation.getOperationMeta(); RestOperationMeta swaggerRestOperation = operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION); try { RestCodec.argsToRest(invocation.getSwaggerArguments(), swaggerRestOperation, restClientRequest); requestEx.setBodyBuffer(restClientRequest.getBodyBuffer()); } catch (Throwable e) { throw ExceptionFactory.convertConsumerException(e); } }
Example 9
Source File: ServerRestArgsFilter.java From servicecomb-java-chassis with Apache License 2.0 | 5 votes |
@Override public Response afterReceiveRequest(Invocation invocation, HttpServletRequestEx requestEx) { OperationMeta operationMeta = invocation.getOperationMeta(); RestOperationMeta restOperationMeta = operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION); Map<String, Object> swaggerArguments = RestCodec.restToArgs(requestEx, restOperationMeta); invocation.setSwaggerArguments(swaggerArguments); return null; }
Example 10
Source File: QpsControllerManagerTest.java From servicecomb-java-chassis with Apache License 2.0 | 4 votes |
@Test public void testGetOrCreateWithGlobalConfig(@Mocked Invocation invocation, @Mocked OperationMeta operationMeta) { new Expectations() { { invocation.getOperationMeta(); result = operationMeta; invocation.getSchemaId(); result = "server"; operationMeta.getSchemaQualifiedName(); result = "server.test"; } }; QpsControllerManager testQpsControllerManager = new QpsControllerManager() .setGlobalQpsController(Config.PROVIDER_LIMIT_KEY_GLOBAL) .setConfigKeyPrefix(Config.CONSUMER_LIMIT_KEY_PREFIX); // global setConfig(Config.PROVIDER_LIMIT_KEY_GLOBAL, 50); QpsController qpsController = testQpsControllerManager.getOrCreate("pojo", invocation); Assert.assertEquals(Config.PROVIDER_LIMIT_KEY_GLOBAL, qpsController.getKey()); Assert.assertTrue(50 == qpsController.getQpsLimit()); qpsController = testQpsControllerManager.getOrCreate("pojo2", invocation); Assert.assertEquals(Config.PROVIDER_LIMIT_KEY_GLOBAL, qpsController.getKey()); Assert.assertTrue(50 == qpsController.getQpsLimit()); qpsController = testQpsControllerManager.getOrCreate("poj", invocation); Assert.assertEquals(Config.PROVIDER_LIMIT_KEY_GLOBAL, qpsController.getKey()); Assert.assertTrue(50 == qpsController.getQpsLimit()); // pojo setConfigWithDefaultPrefix("pojo", 100); qpsController = testQpsControllerManager.getOrCreate("pojo", invocation); Assert.assertEquals("pojo", qpsController.getKey()); Assert.assertTrue(100 == qpsController.getQpsLimit()); qpsController = testQpsControllerManager.getOrCreate("pojo2", invocation); Assert.assertEquals(Config.PROVIDER_LIMIT_KEY_GLOBAL, qpsController.getKey()); Assert.assertTrue(50 == qpsController.getQpsLimit()); qpsController = testQpsControllerManager.getOrCreate("poj", invocation); Assert.assertEquals(Config.PROVIDER_LIMIT_KEY_GLOBAL, qpsController.getKey()); Assert.assertTrue(50 == qpsController.getQpsLimit()); testGetOrCreateCommon(testQpsControllerManager, invocation, operationMeta); }
Example 11
Source File: QpsControllerManagerTest.java From servicecomb-java-chassis with Apache License 2.0 | 4 votes |
@Test public void testQualifiedNameKey(@Mocked Invocation invocation, @Mocked OperationMeta operationMeta) { new Expectations() { { invocation.getOperationMeta(); result = operationMeta; invocation.getSchemaId(); result = "schema"; operationMeta.getSchemaQualifiedName(); result = "schema.opr"; } }; QpsControllerManager qpsControllerManager = new QpsControllerManager(); QpsController qpsController = qpsControllerManager.getOrCreate("service", invocation); Assert.assertEquals("service", qpsController.getKey()); Assert.assertNull(qpsController.getQpsLimit()); new Expectations() { { invocation.getOperationMeta(); result = operationMeta; invocation.getSchemaId(); result = "test_schema"; operationMeta.getSchemaQualifiedName(); result = "test_schema.test_opr"; } }; qpsController = qpsControllerManager.getOrCreate("test_service", invocation); Assert.assertEquals("test_service", qpsController.getKey()); Assert.assertNull(qpsController.getQpsLimit()); new Expectations() { { invocation.getOperationMeta(); result = operationMeta; invocation.getSchemaId(); result = "test_schema"; operationMeta.getSchemaQualifiedName(); result = "test-schema.test-opr"; } }; qpsController = qpsControllerManager.getOrCreate("test-service", invocation); Assert.assertEquals("test-service", qpsController.getKey()); Assert.assertNull(qpsController.getQpsLimit()); new Expectations() { { invocation.getOperationMeta(); result = operationMeta; invocation.getSchemaId(); result = "schema"; operationMeta.getSchemaQualifiedName(); result = "schema.opr.tail"; } }; qpsController = qpsControllerManager.getOrCreate("svc", invocation); Assert.assertEquals("svc", qpsController.getKey()); Assert.assertNull(qpsController.getQpsLimit()); new Expectations() { { invocation.getOperationMeta(); result = operationMeta; invocation.getSchemaId(); result = "schema.opr2"; operationMeta.getSchemaQualifiedName(); result = "schema.opr2.tail"; } }; qpsController = qpsControllerManager.getOrCreate("svc", invocation); Assert.assertEquals("svc", qpsController.getKey()); Assert.assertNull(qpsController.getQpsLimit()); }
Example 12
Source File: QpsControllerManagerTest.java From servicecomb-java-chassis with Apache License 2.0 | 4 votes |
private void testGetOrCreateCommon(QpsControllerManager testQpsControllerManager, Invocation invocation, OperationMeta operationMeta) { new Expectations() { { invocation.getOperationMeta(); result = operationMeta; operationMeta.getSchemaQualifiedName(); result = "server.test"; } }; setConfigWithDefaultPrefix("pojo.server", 200); QpsController qpsController = testQpsControllerManager.getOrCreate("pojo", invocation); Assert.assertEquals("pojo.server", qpsController.getKey()); Assert.assertTrue(200 == qpsController.getQpsLimit()); new Expectations() { { invocation.getOperationMeta(); result = operationMeta; operationMeta.getSchemaQualifiedName(); result = "server2.test"; } }; qpsController = testQpsControllerManager.getOrCreate("pojo", invocation); Assert.assertEquals("pojo", qpsController.getKey()); Assert.assertTrue(100 == qpsController.getQpsLimit()); new Expectations() { { invocation.getOperationMeta(); result = operationMeta; operationMeta.getSchemaQualifiedName(); result = "serve.test"; } }; qpsController = testQpsControllerManager.getOrCreate("pojo", invocation); Assert.assertEquals("pojo", qpsController.getKey()); Assert.assertTrue(100 == qpsController.getQpsLimit()); // pojo.server.test new Expectations() { { invocation.getOperationMeta(); result = operationMeta; operationMeta.getSchemaQualifiedName(); result = "server.test"; } }; setConfigWithDefaultPrefix("pojo.server.test", 300); qpsController = testQpsControllerManager.getOrCreate("pojo", invocation); Assert.assertEquals("pojo.server.test", qpsController.getKey()); Assert.assertTrue(300 == qpsController.getQpsLimit()); new Expectations() { { invocation.getOperationMeta(); result = operationMeta; operationMeta.getSchemaQualifiedName(); result = "server.test2"; } }; qpsController = testQpsControllerManager.getOrCreate("pojo", invocation); Assert.assertEquals("pojo.server", qpsController.getKey()); Assert.assertTrue(200 == qpsController.getQpsLimit()); new Expectations() { { invocation.getOperationMeta(); result = operationMeta; operationMeta.getSchemaQualifiedName(); result = "server.tes"; } }; qpsController = testQpsControllerManager.getOrCreate("pojo", invocation); Assert.assertEquals("pojo.server", qpsController.getKey()); Assert.assertTrue(200 == qpsController.getQpsLimit()); }
Example 13
Source File: HighwayClient.java From servicecomb-java-chassis with Apache License 2.0 | 4 votes |
public void send(Invocation invocation, AsyncResponse asyncResp) throws Exception { invocation.getInvocationStageTrace().startClientFiltersRequest(); invocation.getInvocationStageTrace().startSend(); HighwayClientConnectionPool tcpClientPool = clientMgr.findClientPool(invocation.isSync()); OperationMeta operationMeta = invocation.getOperationMeta(); OperationProtobuf operationProtobuf = ProtobufManager.getOrCreateOperation(invocation); HighwayClientConnection tcpClient = tcpClientPool.findOrCreateClient(invocation.getEndpoint().getEndpoint()); invocation.getInvocationStageTrace().finishGetConnection(System.nanoTime()); HighwayClientPackage clientPackage = new HighwayClientPackage(invocation, operationProtobuf, operationMeta.getConfig().getMsRequestTimeout()); LOGGER.debug("Sending request by highway, qualifiedName={}, endpoint={}.", invocation.getMicroserviceQualifiedName(), invocation.getEndpoint().getEndpoint()); tcpClient.send(clientPackage, ar -> { invocation.getInvocationStageTrace().finishWriteToBuffer(clientPackage.getFinishWriteToBuffer()); invocation.getInvocationStageTrace().finishReceiveResponse(); // 此时是在网络线程中,转换线程 invocation.getResponseExecutor().execute(() -> { invocation.getInvocationStageTrace().startClientFiltersResponse(); if (ar.failed()) { // 只会是本地异常 invocation.getInvocationStageTrace().finishClientFiltersResponse(); if (ar.cause() instanceof TimeoutException) { // give an accurate cause for timeout exception asyncResp.consumerFail(new InvocationException(Status.REQUEST_TIMEOUT, String.format("Request Timeout. Details: %s", ar.cause().getMessage()))); return; } asyncResp.consumerFail(ar.cause()); return; } // 处理应答 try { Response response = HighwayCodec.decodeResponse(invocation, operationProtobuf, ar.result()); invocation.getInvocationStageTrace().finishClientFiltersResponse(); asyncResp.complete(response); } catch (Throwable e) { invocation.getInvocationStageTrace().finishClientFiltersResponse(); asyncResp.consumerFail(e); } }); }); }
Example 14
Source File: TransportClientHandlerInterceptor.java From skywalking with Apache License 2.0 | 2 votes |
/** * Serviecomb chassis Consumers and providers need to register at the service center. If the consumer is not * registered then return false. */ private Boolean checkRegisterStatus(Invocation invocation) { return null != invocation.getOperationMeta() && null != invocation.getEndpoint(); }