use of org.apache.servicecomb.serviceregistry.api.registry.Microservice in project incubator-servicecomb-java-chassis by apache.
the class Consumer method prepareEdge.
private URIEndpointObject prepareEdge() {
Microservice microservice = RegistryUtils.getMicroservice();
EndpointsCache endpointsCache = new EndpointsCache(microservice.getAppId(), "edge", "latest", "");
Endpoint ep = endpointsCache.getLatestEndpoints().get(0);
URIEndpointObject edgeAddress = (URIEndpointObject) ep.getAddress();
edgePrefix = String.format("http://%s:%d/api/business", edgeAddress.getHostOrIp(), edgeAddress.getPort());
return edgeAddress;
}
use of org.apache.servicecomb.serviceregistry.api.registry.Microservice in project incubator-servicecomb-java-chassis by apache.
the class TestOperationInstancesDiscoveryFilter method regMicroservice.
private Microservice regMicroservice(String serviceId, String version, Class<?> schemaCls, int instanceCount) {
String schemaId = "sid";
Microservice microservice = new Microservice();
microservice.setServiceId(serviceId);
microservice.setAppId(appId);
microservice.setServiceName(microserviceName);
microservice.setVersion(version);
microservice.setSchemas(Arrays.asList(schemaId));
serviceRegistry.getServiceRegistryClient().registerMicroservice(microservice);
SwaggerGenerator generator = new SwaggerGenerator(swaggerGeneratorContext, schemaCls);
String schemaContent = SwaggerUtils.swaggerToString(generator.generate());
serviceRegistry.getServiceRegistryClient().registerSchema(serviceId, schemaId, schemaContent);
for (int idx = 0; idx < instanceCount; idx++) {
MicroserviceInstance instance = createInstance(serviceId);
serviceRegistry.getServiceRegistryClient().registerMicroserviceInstance(instance);
}
return microservice;
}
use of org.apache.servicecomb.serviceregistry.api.registry.Microservice in project incubator-servicecomb-java-chassis by apache.
the class PojoProducerProvider method init.
@Override
public void init() throws Exception {
for (PojoProducerMeta pojoProducerMeta : pojoProducers.getProducers()) {
initPojoProducerMeta(pojoProducerMeta);
Microservice microservice = RegistryUtils.getMicroservice();
try {
producerSchemaFactory.getOrCreateProducerSchema(microservice.getServiceName(), pojoProducerMeta.getSchemaId(), pojoProducerMeta.getInstanceClass(), pojoProducerMeta.getInstance());
} catch (Throwable e) {
throw new IllegalArgumentException("create producer schema failed, class=" + pojoProducerMeta.getInstanceClass().getName(), e);
}
}
}
use of org.apache.servicecomb.serviceregistry.api.registry.Microservice in project incubator-servicecomb-java-chassis by apache.
the class TestClientHttp method testServiceRegistryClientImpl.
@SuppressWarnings("unchecked")
@Test
public void testServiceRegistryClientImpl(@Mocked IpPortManager manager) {
IpPort ipPort = new IpPort("127.0.0.1", 8853);
new Expectations() {
{
manager.getAvailableAddress();
result = ipPort;
}
};
new MockUp<CountDownLatch>() {
@Mock
public void await() throws InterruptedException {
}
};
new MockUp<RestUtils>() {
@Mock
void httpDo(RequestContext requestContext, Handler<RestResponse> responseHandler) {
}
};
new MockUp<WebsocketUtils>() {
@Mock
void open(IpPort ipPort, String url, Handler<Void> onOpen, Handler<Void> onClose, Handler<Buffer> onMessage, Handler<Throwable> onException, Handler<Throwable> onConnectFailed) {
}
};
MicroserviceFactory microserviceFactory = new MicroserviceFactory();
Microservice microservice = microserviceFactory.create("app", "ms");
ServiceRegistryClientImpl oClient = new ServiceRegistryClientImpl(manager);
oClient.init();
oClient.registerMicroservice(microservice);
oClient.registerMicroserviceInstance(microservice.getInstance());
Assert.assertEquals(null, oClient.getMicroservice(microservice.getServiceId()));
Assert.assertEquals(null, oClient.getMicroserviceInstance("testConsumerID", "testproviderID"));
Assert.assertEquals(null, oClient.findServiceInstance(microservice.getServiceId(), microservice.getAppId(), microservice.getServiceName(), microservice.getVersion()));
Assert.assertEquals(null, oClient.findServiceInstances(microservice.getServiceId(), microservice.getAppId(), microservice.getServiceName(), microservice.getVersion(), "0"));
Assert.assertEquals(null, oClient.getMicroserviceId(microservice.getAppId(), microservice.getServiceName(), microservice.getVersion()));
Assert.assertEquals(null, oClient.heartbeat(microservice.getServiceId(), microservice.getInstance().getInstanceId()));
oClient.watch("", Mockito.mock(AsyncResultCallback.class));
Assert.assertEquals(false, oClient.unregisterMicroserviceInstance(microservice.getServiceId(), microservice.getInstance().getInstanceId()));
}
use of org.apache.servicecomb.serviceregistry.api.registry.Microservice in project incubator-servicecomb-java-chassis by apache.
the class TestServiceRegistryClientImpl method testException.
@Test
public void testException() {
MicroserviceFactory microserviceFactory = new MicroserviceFactory();
Microservice microservice = microserviceFactory.create("app", "ms");
Assert.assertEquals(null, oClient.registerMicroservice(microservice));
Assert.assertEquals(null, oClient.registerMicroserviceInstance(microservice.getInstance()));
oClient.init();
Assert.assertEquals(null, oClient.getMicroserviceId(microservice.getAppId(), microservice.getServiceName(), microservice.getVersion()));
Assert.assertThat(oClient.getAllMicroservices().isEmpty(), is(true));
Assert.assertEquals(null, oClient.registerMicroservice(microservice));
Assert.assertEquals(null, oClient.getMicroservice("microserviceId"));
Assert.assertEquals(null, oClient.getMicroserviceInstance("consumerId", "providerId"));
Assert.assertEquals(false, oClient.unregisterMicroserviceInstance("microserviceId", "microserviceInstanceId"));
Assert.assertEquals(null, oClient.heartbeat("microserviceId", "microserviceInstanceId"));
Assert.assertEquals(null, oClient.findServiceInstance("selfMicroserviceId", "appId", "serviceName", "versionRule"));
Assert.assertEquals(null, oClient.findServiceInstances("selfMicroserviceId", "appId", "serviceName", "versionRule", "0"));
Assert.assertEquals("a", new ClientException("a").getMessage());
}
Aggregations