use of org.apache.servicecomb.core.event.InvocationStartEvent in project incubator-servicecomb-java-chassis by apache.
the class Invocation method onStart.
public void onStart() {
this.startTime = System.nanoTime();
EventManager.post(new InvocationStartEvent(this));
// old logic, need to be deleted
EventBus.getInstance().triggerEvent(new InvocationStartedEvent(getMicroserviceQualifiedName(), invocationType, startTime));
}
use of org.apache.servicecomb.core.event.InvocationStartEvent 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.InvocationStartEvent in project incubator-servicecomb-java-chassis by apache.
the class TestAbstractRestInvocation method scheduleInvocationNormal.
@Test
public void scheduleInvocationNormal(@Mocked OperationMeta operationMeta) {
long time = 123;
new MockUp<System>() {
@Mock
long nanoTime() {
return time;
}
};
Holder<InvocationStartEvent> eventHolder = new Holder<>();
Object subscriber = new Object() {
@Subscribe
public void onStart(InvocationStartEvent event) {
eventHolder.value = event;
}
};
EventManager.register(subscriber);
Executor executor = new ReactiveExecutor();
requestEx = new AbstractHttpServletRequest() {
};
requestEx.setAttribute(RestConst.REST_REQUEST, requestEx);
new Expectations() {
{
restOperation.getOperationMeta();
result = operationMeta;
operationMeta.getExecutor();
result = executor;
}
};
Holder<Boolean> result = new Holder<>();
restInvocation = new AbstractRestInvocationForTest() {
@Override
protected void runOnExecutor() {
result.value = true;
}
};
restInvocation.requestEx = requestEx;
restInvocation.restOperationMeta = restOperation;
restInvocation.scheduleInvocation();
EventManager.unregister(subscriber);
Assert.assertTrue(result.value);
Assert.assertEquals(time, invocation.getStartTime());
Assert.assertSame(invocation, eventHolder.value.getInvocation());
}
Aggregations