use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.
the class TestClientHttp method testServiceRegistryClientImpl.
@SuppressWarnings("unchecked")
@Test
public void testServiceRegistryClientImpl(@Mocked IpPortManager manager) {
Configuration configuration = ConfigUtil.createLocalConfig();
configuration.setProperty(BootStrapProperties.CONFIG_SERVICE_APPLICATION, "app");
configuration.setProperty(BootStrapProperties.CONFIG_SERVICE_NAME, "ms");
IpPort ipPort = new IpPort("127.0.0.1", 8853);
new Expectations() {
{
manager.getAvailableAddress();
result = ipPort;
}
};
new MockUp<RegistryUtils>() {
@Mock
Microservice getMicroservice() {
return microservice;
}
};
new MockUp<CountDownLatch>() {
@Mock
public void await() throws InterruptedException {
}
};
new MockUp<RestClientUtil>() {
@Mock
void httpDo(RequestContext requestContext, Handler<RestResponse> responseHandler) {
}
};
new MockUp<WebsocketClientUtil>() {
@Mock
void open(IpPort ipPort, String url, Handler<Void> onOpen, Handler<Void> onClose, Handler<Buffer> onMessage, Handler<Throwable> onException, Handler<Throwable> onConnectFailed) {
}
};
// mock up this two client pool, since this UT case doesn't require the client pool actually boot up.
new MockUp<HttpClientPool>() {
@Mock
void create() {
}
};
new MockUp<WebsocketClientPool>() {
@Mock
void create() {
}
};
MicroserviceFactory microserviceFactory = new MicroserviceFactory();
Microservice microservice = microserviceFactory.create(configuration);
ServiceRegistryClientImpl oClient = new ServiceRegistryClientImpl(ServiceRegistryConfig.INSTANCE);
oClient.init();
oClient.registerMicroservice(microservice);
oClient.registerMicroserviceInstance(microservice.getInstance());
Assert.assertNull(oClient.getMicroservice(microservice.getServiceId()));
Assert.assertNull(oClient.getMicroserviceInstance("testConsumerID", "testproviderID"));
Assert.assertNull(oClient.findServiceInstance(microservice.getServiceId(), microservice.getAppId(), microservice.getServiceName(), microservice.getVersion()));
Assert.assertNull(oClient.findServiceInstances(microservice.getServiceId(), microservice.getAppId(), microservice.getServiceName(), microservice.getVersion(), "0"));
Assert.assertNull(oClient.getMicroserviceId(microservice.getAppId(), microservice.getServiceName(), microservice.getVersion(), microservice.getEnvironment()));
Assert.assertNull(oClient.heartbeat(microservice.getServiceId(), microservice.getInstance().getInstanceId()));
oClient.watch("", Mockito.mock(AsyncResultCallback.class));
Assert.assertFalse(oClient.unregisterMicroserviceInstance(microservice.getServiceId(), microservice.getInstance().getInstanceId()));
}
use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.
the class TestSwaggerLoader method loadFromResource_diffApp_dirWithApp.
@Test
public void loadFromResource_diffApp_dirWithApp() {
Swagger swagger = SwaggerGenerator.generate(Hello.class);
mockLocalResource(swagger, String.format("applications/%s/%s/%s.yaml", "other", "ms3", schemaId));
Microservice microservice = appManager.getOrCreateMicroserviceVersions("other", "ms3").getVersions().values().iterator().next().getMicroservice();
Swagger loadedSwagger = RegistrationManager.INSTANCE.getSwaggerLoader().loadSwagger(microservice, null, schemaId);
Assert.assertNotSame(swagger, loadedSwagger);
Assert.assertEquals(swagger, loadedSwagger);
}
use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.
the class TestSwaggerLoader method loadFromRemote.
@Test
public void loadFromRemote() {
Swagger swagger = SwaggerGenerator.generate(Hello.class);
new Expectations(serviceRegistry.getServiceRegistryClient()) {
{
serviceRegistry.getServiceRegistryClient().getAggregatedSchema(serviceId, schemaId);
result = SwaggerUtils.swaggerToString(swagger);
}
};
RegistrationManager.INSTANCE.getSwaggerLoader().unregisterSwagger(appId, serviceName, schemaId);
Microservice microservice = appManager.getOrCreateMicroserviceVersions(appId, serviceName).getVersions().values().iterator().next().getMicroservice();
Swagger loadedSwagger = RegistrationManager.INSTANCE.getSwaggerLoader().loadSwagger(microservice, null, schemaId);
Assert.assertNotSame(swagger, loadedSwagger);
Assert.assertEquals(swagger, loadedSwagger);
}
use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.
the class TestSwaggerLoader method loadFromResource_sameApp_dirWithApp.
@Test
public void loadFromResource_sameApp_dirWithApp() {
Swagger swagger = SwaggerGenerator.generate(Hello.class);
mockLocalResource(swagger, String.format("applications/%s/%s/%s.yaml", appId, serviceName, schemaId));
RegistrationManager.INSTANCE.getSwaggerLoader().unregisterSwagger(appId, serviceName, schemaId);
Microservice microservice = appManager.getOrCreateMicroserviceVersions(appId, serviceName).getVersions().values().iterator().next().getMicroservice();
Swagger loadedSwagger = RegistrationManager.INSTANCE.getSwaggerLoader().loadSwagger(microservice, null, schemaId);
Assert.assertNotSame(swagger, loadedSwagger);
Assert.assertEquals(swagger, loadedSwagger);
}
use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.
the class TestAbstractRegisterTask method setup.
@Before
public void setup() {
eventBus = new EventBus();
microservice = new Microservice();
microservice.setAppId("app");
microservice.setServiceName("ms");
microservice.setInstance(new MicroserviceInstance());
}
Aggregations