use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.
the class TestMicroserviceInstanceHeartbeatTask method setup.
@Before
public void setup() {
eventBus = new EventBus();
heartbeatTaskList = new ArrayList<>();
eventBus.register(new Object() {
@Subscribe
public void onEvent(MicroserviceInstanceHeartbeatTask task) {
heartbeatTaskList.add(task);
}
});
microservice = new Microservice();
microservice.setAppId("app");
microservice.setServiceName("ms");
microservice.setServiceId("serviceId");
microservice.setInstance(new MicroserviceInstance());
microservice.getInstance().setInstanceId("instanceId");
}
use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.
the class TestMicroserviceRegisterTask method setup.
@Before
public void setup() {
collector = new LogCollector();
eventBus = new EventBus();
taskList = new ArrayList<>();
eventBus.register(new Object() {
@Subscribe
public void onEvent(MicroserviceRegisterTask task) {
taskList.add(task);
}
});
microservice = new Microservice();
microservice.setAppId("app");
microservice.setServiceName("ms");
microservice.setInstance(new MicroserviceInstance());
}
use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.
the class TestMicroserviceRegisterTask method testReRegisterForDevAndLocalSchemasAreLess.
@Test
public void testReRegisterForDevAndLocalSchemasAreLess(@Mocked ServiceRegistryClient srClient) {
Microservice otherMicroservice = new Microservice();
otherMicroservice.setAppId(microservice.getAppId());
otherMicroservice.setServiceName("ms1");
otherMicroservice.addSchema("s1", null);
otherMicroservice.addSchema("s2", null);
List<GetSchemaResponse> list = new ArrayList<>();
GetSchemaResponse resp = new GetSchemaResponse();
resp.setSchemaId("s1");
list.add(resp);
resp = new GetSchemaResponse();
resp.setSchemaId("s2");
list.add(resp);
Holder<List<GetSchemaResponse>> onlineSchemasHolder = new Holder<>();
onlineSchemasHolder.setValue(list).setStatusCode(200);
Holder<String> removeSchemaResult = new Holder<>();
removeSchemaResult.setStatusCode(200);
new Expectations() {
{
srClient.getMicroserviceId(anyString, anyString, anyString, anyString);
result = "serviceId";
srClient.getMicroservice(anyString);
result = otherMicroservice;
srClient.getSchemas(anyString);
result = onlineSchemasHolder;
srClient.getSchema("serviceId", "s1");
result = null;
srClient.registerSchema("serviceId", "s1", "s1Content");
result = true;
}
};
microservice.addSchema("s1", "s1Content");
microservice.setEnvironment("development");
MicroserviceRegisterTask registerTask = new MicroserviceRegisterTask(eventBus, srClient, microservice);
registerTask.run();
Assert.assertEquals(true, registerTask.isRegistered());
Assert.assertEquals(true, registerTask.isSchemaIdSetMatch());
Assert.assertEquals("serviceId", microservice.getServiceId());
Assert.assertEquals(1, taskList.size());
}
use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.
the class TestMicroserviceRegisterTask method testReRegisteredSetForDev.
@Test
public void testReRegisteredSetForDev(@Mocked ServiceRegistryClient srClient) {
ArchaiusUtils.resetConfig();
ArchaiusUtils.setProperty("service_description.environment", "development");
Microservice otherMicroservice = new Microservice();
otherMicroservice.setAppId(microservice.getAppId());
otherMicroservice.setServiceName("ms1");
otherMicroservice.addSchema("s1", "");
List<GetSchemaResponse> list = new ArrayList<>();
GetSchemaResponse resp = new GetSchemaResponse();
resp.setSchemaId("s1");
resp.setSummary("c1188d709631a9038874f9efc6eb894f");
list.add(resp);
Holder<List<GetSchemaResponse>> onlineSchemasHolder = new Holder<>();
onlineSchemasHolder.setStatusCode(200).setValue(list);
new Expectations() {
{
srClient.getMicroserviceId(anyString, anyString, anyString, anyString);
result = "serviceId";
srClient.getMicroservice(anyString);
result = otherMicroservice;
srClient.getSchemas(anyString);
result = onlineSchemasHolder;
srClient.registerSchema(microservice.getServiceId(), anyString, anyString);
result = true;
}
};
microservice.addSchema("s1", "");
microservice.setEnvironment("development");
MicroserviceRegisterTask registerTask = new MicroserviceRegisterTask(eventBus, srClient, microservice);
registerTask.run();
Assert.assertEquals(true, registerTask.isRegistered());
Assert.assertEquals(true, registerTask.isSchemaIdSetMatch());
Assert.assertEquals("serviceId", microservice.getServiceId());
Assert.assertEquals(1, taskList.size());
}
use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.
the class MultiErrorCodeServiceClient method prepareServerDirectURL.
private static void prepareServerDirectURL() {
Microservice microservice = RegistrationManager.INSTANCE.getMicroservice();
MicroserviceInstance microserviceInstance = (MicroserviceInstance) DiscoveryManager.INSTANCE.getAppManager().getOrCreateMicroserviceVersionRule(microservice.getAppId(), "jaxrs", DefinitionConst.VERSION_RULE_ALL).getVersionedCache().mapData().values().stream().findFirst().get();
URIEndpointObject edgeAddress = new URIEndpointObject(microserviceInstance.getEndpoints().get(0));
serverDirectURL = String.format("http://%s:%d/", edgeAddress.getHostOrIp(), edgeAddress.getPort());
}
Aggregations