use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.
the class TestSwaggerLoader method registerSwagger.
@Test
public void registerSwagger() {
Swagger swagger = SwaggerGenerator.generate(Hello.class);
RegistrationManager.INSTANCE.getSwaggerLoader().registerSwagger("default:ms2", schemaId, swagger);
Microservice microservice = appManager.getOrCreateMicroserviceVersions(appId, serviceName).getVersions().values().iterator().next().getMicroservice();
Assert.assertSame(swagger, RegistrationManager.INSTANCE.getSwaggerLoader().loadSwagger(microservice, null, schemaId));
}
use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.
the class TestSwaggerLoader method loadFromResource_diffApp_dirWithoutApp.
@Test
public void loadFromResource_diffApp_dirWithoutApp() {
Swagger swagger = SwaggerGenerator.generate(Hello.class);
mockLocalResource(swagger, String.format("microservices/%s/%s.yaml", "ms3", schemaId));
Microservice microservice = appManager.getOrCreateMicroserviceVersions("other", "ms3").getVersions().values().iterator().next().getMicroservice();
Assert.assertNull(RegistrationManager.INSTANCE.getSwaggerLoader().loadSwagger(microservice, null, schemaId));
}
use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.
the class TestMicroserviceInstanceRegisterTask method setup.
@Before
public void setup() {
ConfigUtil.installDynamicConfig();
eventBus = new EventBus();
taskList = new ArrayList<>();
eventBus.register(new Object() {
@Subscribe
public void onEvent(MicroserviceInstanceRegisterTask task) {
taskList.add(task);
}
});
microservice = new Microservice();
microservice.setAppId("app");
microservice.setServiceName("ms");
microservice.setServiceId("serviceId");
microservice.setInstance(new MicroserviceInstance());
HealthCheck healthCheck = new HealthCheck();
healthCheck.setMode(HealthCheckMode.HEARTBEAT);
microservice.getInstance().setHealthCheck(healthCheck);
}
use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.
the class ProducerBootListener method onAfterTransport.
@Override
public void onAfterTransport(BootEvent event) {
// register schema to microservice;
Microservice microservice = RegistrationManager.INSTANCE.getMicroservice();
String swaggerSchema = "http";
for (String endpoint : microservice.getInstance().getEndpoints()) {
if (endpoint.startsWith("rest://") && endpoint.indexOf("sslEnabled=true") > 0) {
swaggerSchema = "https";
}
}
MicroserviceMeta microserviceMeta = event.getScbEngine().getProducerMicroserviceMeta();
for (SchemaMeta schemaMeta : microserviceMeta.getSchemaMetas().values()) {
Swagger swagger = schemaMeta.getSwagger();
swagger.addScheme(Scheme.forValue(swaggerSchema));
String content = SwaggerUtils.swaggerToString(swagger);
LOGGER.info("generate swagger for {}/{}/{}, swagger: {}", microserviceMeta.getAppId(), microserviceMeta.getMicroserviceName(), schemaMeta.getSchemaId(), content);
RegistrationManager.INSTANCE.addSchema(schemaMeta.getSchemaId(), content);
}
saveBasePaths(microserviceMeta);
}
use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.
the class TestServiceRegistryClientImpl method testException.
@Test
public void testException() {
ArchaiusUtils.setProperty(BootStrapProperties.CONFIG_SERVICE_APPLICATION, "app");
ArchaiusUtils.setProperty(BootStrapProperties.CONFIG_SERVICE_NAME, "ms");
MicroserviceFactory microserviceFactory = new MicroserviceFactory();
Microservice microservice = microserviceFactory.create();
Assert.assertNull(oClient.registerMicroservice(microservice));
Assert.assertNull(oClient.registerMicroserviceInstance(microservice.getInstance()));
oClient.init();
Assert.assertNull(oClient.getMicroserviceId(microservice.getAppId(), microservice.getServiceName(), microservice.getVersion(), microservice.getEnvironment()));
Assert.assertThat(oClient.getAllMicroservices().isEmpty(), is(true));
Assert.assertNull(oClient.registerMicroservice(microservice));
Assert.assertNull(oClient.getMicroservice("microserviceId"));
Assert.assertNull(oClient.getMicroserviceInstance("consumerId", "providerId"));
Assert.assertFalse(oClient.unregisterMicroserviceInstance("microserviceId", "microserviceInstanceId"));
Assert.assertNull(oClient.heartbeat("microserviceId", "microserviceInstanceId"));
Assert.assertNull(oClient.findServiceInstance("selfMicroserviceId", "appId", "serviceName", "versionRule"));
Assert.assertNull(oClient.findServiceInstances("selfMicroserviceId", "appId", "serviceName", "versionRule", "0"));
Assert.assertEquals("a", new ClientException("a").getMessage());
ArchaiusUtils.resetConfig();
}
Aggregations