use of org.apache.servicecomb.serviceregistry.ServiceRegistry in project incubator-servicecomb-java-chassis by apache.
the class TestConsumerSchemaFactory method init.
@BeforeClass
public static void init() {
ServiceRegistry serviceRegistry = ServiceRegistryFactory.createLocal();
serviceRegistry.init();
RegistryUtils.setServiceRegistry(serviceRegistry);
SchemaListenerManager schemaListenerManager = new SchemaListenerManager();
schemaListenerManager.setSchemaListenerList(Arrays.asList(schemaListener));
MicroserviceMetaManager microserviceMetaManager = new MicroserviceMetaManager();
SchemaLoader schemaLoader = new SchemaLoader() {
@Override
public void putSelfBasePathIfAbsent(String microserviceName, String basePath) {
}
};
CompositeSwaggerGeneratorContext compositeSwaggerGeneratorContext = new CompositeSwaggerGeneratorContext();
ReflectUtils.setField(consumerSchemaFactory, "schemaListenerManager", schemaListenerManager);
ReflectUtils.setField(consumerSchemaFactory, "microserviceMetaManager", microserviceMetaManager);
ReflectUtils.setField(consumerSchemaFactory, "schemaLoader", schemaLoader);
ReflectUtils.setField(consumerSchemaFactory, "compositeSwaggerGeneratorContext", compositeSwaggerGeneratorContext);
SchemaMeta schemaMeta = new UnitTestMeta().getOrCreateSchemaMeta(TestConsumerSchemaFactoryImpl.class);
String content = UnitTestSwaggerUtils.pretty(schemaMeta.getSwagger());
Microservice microservice = new Microservice();
microservice.setAppId("app");
microservice.setServiceId("0");
microservice.setServiceName("ms");
microservice.setVersion("1.0.0");
microservice.addSchema("schema", content);
serviceRegistry.getServiceRegistryClient().registerMicroservice(microservice);
MicroserviceInstance instance = new MicroserviceInstance();
instance.setServiceId("0");
instance.setInstanceId("0");
serviceRegistry.getServiceRegistryClient().registerMicroserviceInstance(instance);
}
use of org.apache.servicecomb.serviceregistry.ServiceRegistry in project incubator-servicecomb-java-chassis by apache.
the class TestLocalServiceRegistry method testSchema.
@Test
public void testSchema() {
ServiceRegistry serviceRegistry = ServiceRegistryFactory.createLocal();
Microservice microservice = serviceRegistry.getMicroservice();
microservice.addSchema("s1", "s1-content");
serviceRegistry.init();
serviceRegistry.run();
try {
serviceRegistry.getServiceRegistryClient().isSchemaExist("notExist", "s1");
Assert.fail("must throw exception");
} catch (IllegalArgumentException e) {
Assert.assertEquals("Invalid serviceId, serviceId=notExist", e.getMessage());
}
try {
serviceRegistry.getServiceRegistryClient().getSchema("notExist", "s1");
Assert.fail("must throw exception");
} catch (IllegalArgumentException e) {
Assert.assertEquals("Invalid serviceId, serviceId=notExist", e.getMessage());
}
Assert.assertEquals(true, serviceRegistry.getServiceRegistryClient().isSchemaExist(microservice.getServiceId(), "s1"));
String content = serviceRegistry.getServiceRegistryClient().getSchema(microservice.getServiceId(), "s1");
Assert.assertEquals("s1-content", content);
}
use of org.apache.servicecomb.serviceregistry.ServiceRegistry in project incubator-servicecomb-java-chassis by apache.
the class TestLocalServiceRegistry method testLifeCycle.
@Test
public void testLifeCycle() {
ServiceRegistry serviceRegistry = ServiceRegistryFactory.createLocal();
serviceRegistry.init();
Assert.assertNull(serviceRegistry.getMicroserviceInstance().getInstanceId());
serviceRegistry.run();
Assert.assertNotNull(serviceRegistry.getMicroserviceInstance().getInstanceId());
serviceRegistry.destroy();
Assert.assertTrue(serviceRegistry.getServiceRegistryClient().getMicroserviceInstance("", serviceRegistry.getMicroservice().getServiceId()).isEmpty());
}
use of org.apache.servicecomb.serviceregistry.ServiceRegistry in project incubator-servicecomb-java-chassis by apache.
the class TestRemoteServiceRegistry method testLifeCycle.
@Test
public void testLifeCycle(@Injectable ServiceRegistryConfig config, @Injectable MicroserviceDefinition definition, @Injectable ServiceRegistry registry) {
ArrayList<IpPort> ipPortList = new ArrayList<>();
ipPortList.add(new IpPort("127.0.0.1", 9980));
ipPortList.add(new IpPort("127.0.0.1", 9981));
new Expectations() {
{
definition.getConfiguration();
result = ConfigUtil.createLocalConfig();
config.getIpPort();
result = ipPortList;
config.getTransport();
result = "rest";
config.isRegistryAutoDiscovery();
result = true;
config.getHeartbeatInterval();
result = 30;
config.getInstancePullInterval();
result = 30;
config.isWatch();
result = false;
}
};
ServiceRegistry oldRegistry = RegistryUtils.getServiceRegistry();
RegistryUtils.setServiceRegistry(registry);
EventBus bus = new EventBus();
RemoteServiceRegistry remote = new TestingRemoteServiceRegistry(bus, config, definition);
remote.init();
remote.run();
// includes complete tasks
Assert.assertTrue(2 <= remote.getTaskPool().getTaskCount());
bus.post(new ShutdownEvent());
remote.getTaskPool().schedule(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
}
}, 0, TimeUnit.SECONDS);
Assert.assertTrue(remote.getTaskPool().isShutdown());
RegistryUtils.setServiceRegistry(oldRegistry);
}
use of org.apache.servicecomb.serviceregistry.ServiceRegistry in project incubator-servicecomb-java-chassis by apache.
the class TestCseClientHttpRequest method testNormal.
@Test
public void testNormal() throws IOException {
ServiceRegistry serviceRegistry = ServiceRegistryFactory.createLocal();
serviceRegistry.init();
RegistryUtils.setServiceRegistry(serviceRegistry);
UnitTestMeta meta = new UnitTestMeta();
CseContext.getInstance().getSchemaListenerManager().setSchemaListenerList(Arrays.asList(new RestEngineSchemaListener()));
SchemaMeta schemaMeta = meta.getOrCreateSchemaMeta(SpringmvcImpl.class);
CseContext.getInstance().getSchemaListenerManager().notifySchemaListener(schemaMeta);
Holder<Invocation> holder = new Holder<>();
CseClientHttpRequest client = new CseClientHttpRequest(URI.create("cse://app:test/" + SpringmvcImpl.class.getSimpleName() + "/bytes"), HttpMethod.POST) {
/**
* {@inheritDoc}
*/
@Override
protected Response doInvoke(Invocation invocation) {
holder.value = invocation;
return Response.ok("result");
}
};
byte[] body = "abc".getBytes();
client.setRequestBody(body);
client.execute();
Assert.assertArrayEquals(body, holder.value.getSwaggerArgument(0));
}
Aggregations