use of org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance 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.api.registry.MicroserviceInstance in project incubator-servicecomb-java-chassis by apache.
the class TestSimpleLoadBalanceHandler method handle.
@Test
public void handle(@Mocked Transport transport) throws Exception {
MicroserviceInstance instance = new MicroserviceInstance();
instance.setInstanceId("id");
instance.getEndpoints().add("rest://localhost:8080");
instance.getEndpoints().add("highway://localhost:8081");
instanceVersionedCache.data(Collections.singletonMap("id", instance)).autoCacheVersion().name("vr");
new Expectations() {
{
transportManager.findTransport(anyString);
result = transport;
invocation.getConfigTransportName();
result = "";
}
};
handler.handle(invocation, ar);
AtomicInteger idx = indexMap.values().iterator().next();
Assert.assertEquals(1, idx.get());
handler.handle(invocation, ar);
Assert.assertEquals(2, idx.get());
}
use of org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance in project incubator-servicecomb-java-chassis by apache.
the class TestPropertiesLoader method testInstancePropertiesLoader.
@Test
public void testInstancePropertiesLoader() {
Microservice microservice = ServiceRegistryFactory.createLocal().getMicroservice();
MicroserviceInstance instance = microservice.getInstance();
Map<String, String> expectedMap = new HashMap<>();
expectedMap.put("key0", "value0");
expectedMap.put("ek0", "ev0");
Assert.assertEquals(expectedMap, instance.getProperties());
}
use of org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance in project incubator-servicecomb-java-chassis by apache.
the class TestMicroserviceInstanceRegisterTask method registerHostSuccess.
@Test
public void registerHostSuccess() {
MicroserviceInstance instance = microservice.getInstance();
new Expectations(RegistryUtils.class) {
{
RegistryUtils.getPublishHostName();
result = "hostName";
serviceRegistryConfig.isPreferIpAddress();
result = false;
serviceRegistryConfig.getHeartbeatInterval();
result = 10;
serviceRegistryConfig.getResendHeartBeatTimes();
result = 20;
srClient.registerMicroserviceInstance(instance);
result = "instanceId";
}
};
MicroserviceInstanceRegisterTask registerTask = new MicroserviceInstanceRegisterTask(eventBus, serviceRegistryConfig, srClient, microservice);
registerTask.taskStatus = TaskStatus.READY;
registerTask.run();
Assert.assertEquals(true, registerTask.isRegistered());
Assert.assertEquals("hostName", instance.getHostName());
Assert.assertEquals("instanceId", instance.getInstanceId());
Assert.assertEquals(10, instance.getHealthCheck().getInterval());
Assert.assertEquals(20, instance.getHealthCheck().getTimes());
Assert.assertEquals(1, taskList.size());
}
use of org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance in project incubator-servicecomb-java-chassis by apache.
the class TestMicroserviceInstanceRegisterTask method setup.
@Before
public void setup() {
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);
}
Aggregations