use of org.apache.servicecomb.core.definition.SchemaMeta 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.definition.SchemaMeta in project incubator-servicecomb-java-chassis by apache.
the class ProducerProviderManager method init.
public void init() throws Exception {
for (ProducerProvider provider : producerProviderList) {
provider.init();
}
Microservice microservice = RegistryUtils.getMicroservice();
MicroserviceMeta microserviceMeta = microserviceMetaManager.getOrCreateMicroserviceMeta(microservice);
for (SchemaMeta schemaMeta : microserviceMeta.getSchemaMetas()) {
String content = SchemaUtils.swaggerToString(schemaMeta.getSwagger());
microservice.addSchema(schemaMeta.getSchemaId(), content);
}
}
use of org.apache.servicecomb.core.definition.SchemaMeta in project incubator-servicecomb-java-chassis by apache.
the class TestDynamicSchemaLoader method testRegisterSchemas.
@SuppressWarnings("deprecation")
@Test
public void testRegisterSchemas() {
DynamicSchemaLoader.INSTANCE.registerSchemas("classpath*:test/test/schema.yaml");
SchemaMeta schemaMeta = microserviceMetaManager.ensureFindSchemaMeta("perfClient", "schema");
Assert.assertEquals("cse.gen.app.perfClient.schema", schemaMeta.getPackageName());
}
use of org.apache.servicecomb.core.definition.SchemaMeta in project incubator-servicecomb-java-chassis by apache.
the class TestSchemaListenerManager method testInitializationListener.
@Test
public void testInitializationListener() {
SchemaListener listener = new SchemaListener() {
@Override
public void onSchemaLoaded(SchemaMeta... schemaMetas) {
Assert.assertEquals(1, schemaMetas.length);
Assert.assertEquals("test", schemaMetas[0].getSchemaId());
}
};
SchemaListenerManager mgr = new SchemaListenerManager();
mgr.setSchemaListenerList(Arrays.asList(listener));
mgr.setMicroserviceMetaManager(new MicroserviceMetaManager());
mgr.notifySchemaListener(schemaMeta);
}
use of org.apache.servicecomb.core.definition.SchemaMeta in project incubator-servicecomb-java-chassis by apache.
the class TestProducerSchemaFactory method init.
@BeforeClass
public static void init() {
ServiceRegistry serviceRegistry = ServiceRegistryFactory.createLocal();
RegistryUtils.setServiceRegistry(serviceRegistry);
ConverterMgr converterMgr = new ConverterMgr();
ProducerArgumentsMapperFactory producerArgsMapperFactory = new ProducerArgumentsMapperFactory();
producerArgsMapperFactory.setConverterMgr(converterMgr);
MicroserviceMetaManager microserviceMetaManager = new MicroserviceMetaManager();
SchemaLoader schemaLoader = new SchemaLoader() {
@Override
public void putSelfBasePathIfAbsent(String microserviceName, String basePath) {
}
};
CompositeSwaggerGeneratorContext compositeSwaggerGeneratorContext = new CompositeSwaggerGeneratorContext();
producerSchemaFactory.setSwaggerEnv(swaggerEnv);
ReflectUtils.setField(producerSchemaFactory, "microserviceMetaManager", microserviceMetaManager);
ReflectUtils.setField(producerSchemaFactory, "schemaLoader", schemaLoader);
ReflectUtils.setField(producerSchemaFactory, "compositeSwaggerGeneratorContext", compositeSwaggerGeneratorContext);
Executor reactiveExecutor = new ReactiveExecutor();
Executor normalExecutor = (cmd) -> {
};
new MockUp<BeanUtils>() {
@SuppressWarnings("unchecked")
@Mock
<T> T getBean(String name) {
if (ExecutorManager.EXECUTOR_REACTIVE.equals(name)) {
return (T) reactiveExecutor;
}
return (T) normalExecutor;
}
};
// ApplicationContext applicationContext = Mockito.mock(ApplicationContext.class);
// BeanUtils.setContext(applicationContext);
// Mockito.when(applicationContext.getBean(ExecutorManager.EXECUTOR_REACTIVE)).thenReturn(new ReactiveExecutor());
UnitTestMeta.init();
schemaMeta = producerSchemaFactory.getOrCreateProducerSchema("app:ms", "schema", TestProducerSchemaFactoryImpl.class, new TestProducerSchemaFactoryImpl());
}
Aggregations