use of org.apache.servicecomb.core.event.InvocationFinishEvent in project incubator-servicecomb-java-chassis by apache.
the class TestHighwayServerInvoke method test.
@Test
public void test() {
Holder<InvocationStartEvent> startHolder = new Holder<>();
Holder<InvocationFinishEvent> finishHolder = new Holder<>();
Object subscriber = new Object() {
@Subscribe
public void onStart(InvocationStartEvent event) {
startHolder.value = event;
}
@Subscribe
public void onFinish(InvocationFinishEvent event) {
finishHolder.value = event;
}
};
EventManager.register(subscriber);
MockUtil.getInstance().mockHighwayCodec();
SchemaMeta schemaMeta = unitTestMeta.getOrCreateSchemaMeta(Impl.class);
OperationMeta operationMeta = schemaMeta.ensureFindOperation("add");
operationMeta.setExecutor(new ReactiveExecutor());
HighwayServerInvoke highwayServerInvoke = new HighwayServerInvoke();
highwayServerInvoke.setMicroserviceMetaManager(unitTestMeta.getMicroserviceMetaManager());
RequestHeader requestHeader = MockUtil.getInstance().requestHeader;
// 初始化失败
requestHeader.setDestMicroservice(null);
Assert.assertFalse(highwayServerInvoke.init(connection, 0, null, null));
// 初始化成功
requestHeader.setDestMicroservice(schemaMeta.getMicroserviceName());
requestHeader.setSchemaId(schemaMeta.getSchemaId());
requestHeader.setOperationName(operationMeta.getOperationId());
Assert.assertTrue(highwayServerInvoke.init(connection, 0, requestHeader, null));
// exe失败
MockUtil.getInstance().decodeRequestSucc = false;
highwayServerInvoke.execute();
EventManager.unregister(subscriber);
Assert.assertEquals(true, Buffer.buffer(netSocketBuffer).toString().startsWith("CSE.TCP"));
Assert.assertSame(highwayServerInvoke.invocation, startHolder.value.getInvocation());
Assert.assertSame(highwayServerInvoke.invocation, finishHolder.value.getInvocation());
Assert.assertTrue(highwayServerInvoke.invocation.getStartExecutionTime() != 0);
}
use of org.apache.servicecomb.core.event.InvocationFinishEvent in project incubator-servicecomb-java-chassis by apache.
the class Invocation method onFinish.
public void onFinish(Response response) {
EventManager.post(new InvocationFinishEvent(this, response));
// old logic, need to be deleted
triggerFinishedEvent(response.getStatusCode());
}
use of org.apache.servicecomb.core.event.InvocationFinishEvent in project incubator-servicecomb-java-chassis by apache.
the class TestPublishModelFactory method prepareRegistry.
protected Registry prepareRegistry() {
CompositeRegistry globalRegistry = SpectatorUtils.createCompositeRegistry(null);
Registry registry = new DefaultRegistry(new ManualClock());
EventBus eventBus = new EventBus();
DefaultMetricsInitializer metricsInitializer = new DefaultMetricsInitializer() {
protected Registry createRegistry(MetricsBootstrapConfig config) {
return registry;
}
};
metricsInitializer.init(globalRegistry, eventBus, new MetricsBootstrapConfig());
new MockUp<System>() {
@Mock
long nanoTime() {
return 10;
}
};
invocationType = InvocationType.CONSUMER;
new MockUp<Invocation>() {
@Mock
InvocationType getInvocationType() {
return invocationType;
}
@Mock
boolean isConsumer() {
return InvocationType.CONSUMER.equals(invocationType);
}
@Mock
String getRealTransportName() {
return Const.RESTFUL;
}
@Mock
String getMicroserviceQualifiedName() {
return "m.s.o";
}
@Mock
long getStartExecutionTime() {
return 5;
}
};
new Expectations() {
{
response.getStatusCode();
result = 200;
}
};
InvocationFinishEvent finishEvent = new InvocationFinishEvent(invocation, response);
eventBus.post(finishEvent);
invocationType = InvocationType.PRODUCER;
eventBus.post(finishEvent);
return registry;
}
Aggregations