use of io.servicecomb.serviceregistry.api.registry.MicroserviceInstance in project java-chassis by ServiceComb.
the class TestSimpleTransactionControlFilter method setUp.
@Before
public void setUp() {
filter = new SimpleTransactionControlFilter();
Map<String, String> properties = new HashMap<>();
properties.put("tag0", "value0");
properties.put("tag1", "value1");
MicroserviceInstance instance = new MicroserviceInstance();
instance.setProperties(properties);
server = Mockito.mock(CseServer.class);
Mockito.when(server.getInstance()).thenReturn(instance);
}
use of io.servicecomb.serviceregistry.api.registry.MicroserviceInstance in project java-chassis by ServiceComb.
the class TestIpPortManager method testCreateServiceRegistryCacheWithInstanceCache.
@Test
public void testCreateServiceRegistryCacheWithInstanceCache() {
boolean validAssert = true;
List<MicroserviceInstance> list = new ArrayList<MicroserviceInstance>();
MicroserviceInstance e1 = new MicroserviceInstance();
list.add(e1);
new MockUp<RegistryUtils>() {
@Mock
public List<MicroserviceInstance> findServiceInstance(String appId, String serviceName, String versionRule) {
return list;
}
};
Microservice microservice = new Microservice();
new MockUp<RegistryUtils>() {
@Mock
private Microservice createMicroserviceFromDefinition() {
return microservice;
}
};
try {
Deencapsulation.setField(manager, "instanceCache", Mockito.mock(InstanceCache.class));
manager.createServiceRegistryCache();
Assert.assertNotNull(manager.get());
Assert.assertNull(manager.next());
} catch (Exception e) {
validAssert = false;
}
Assert.assertTrue(validAssert);
}
use of io.servicecomb.serviceregistry.api.registry.MicroserviceInstance in project java-chassis by ServiceComb.
the class TestInstanceCache method beforeClass.
@BeforeClass
public static void beforeClass() {
MicroserviceInstance instance = new MicroserviceInstance();
instance.setStatus(MicroserviceInstanceStatus.UP);
List<String> endpoints = new ArrayList<>();
endpoints.add("rest://127.0.0.1:8080");
instance.setEndpoints(endpoints);
instance.setInstanceId("1");
Map<String, MicroserviceInstance> instMap = new HashMap<>();
instMap.put(instance.getInstanceId(), instance);
instanceCache = new InstanceCache("testAppID", "testMicroServiceName", "1.0", instMap);
}
use of io.servicecomb.serviceregistry.api.registry.MicroserviceInstance in project java-chassis by ServiceComb.
the class ServiceRegistryClientDemo method main.
public static void main(String[] args) throws Exception {
Log4jUtils.init();
BeanUtils.init();
//Thread.sleep(2000);
ServiceRegistryClient client = new ServiceRegistryClientImpl();
client.init();
// 新增服务
List<String> list = new ArrayList<>();
list.add("xxxxxxx");
Microservice service = new Microservice();
service.setAppId(APP_NAME);
service.setServiceName(SERVICE_NAME);
service.setVersion(VERSION);
service.setLevel("FRONT");
service.setSchemas(list);
String serviceId = client.registerMicroservice(service);
LOG.info("create service {}", serviceId);
List<Microservice> mss = client.getAllMicroservices();
LOG.info("query all services {}", mss.size());
// Watch
client.watch(serviceId, changedEvent -> {
if (changedEvent.succeeded()) {
LOG.info("{} {}/{} changed", changedEvent.result().getAction(), changedEvent.result().getKey().getServiceName(), changedEvent.result().getKey().getVersion());
for (String s : changedEvent.result().getInstance().getEndpoints()) {
LOG.info(" -> {}", s);
}
} else {
LOG.error("", changedEvent.cause());
}
}, open -> {
}, close -> {
});
service = client.getMicroservice(serviceId);
LOG.info("get service {}", service);
serviceId = client.getMicroserviceId(service.getAppId(), service.getServiceName(), service.getVersion());
LOG.info("get service id {}", serviceId);
// 注册实例
List<String> addresses = new ArrayList<>();
addresses.add("grpc:127.0.0.1:8081");
HealthCheck healthCheck = new HealthCheck();
healthCheck.setMode(HealthCheckMode.HEARTBEAT);
healthCheck.setInterval(10);
healthCheck.setTimes(0);
MicroserviceInstance instance = new MicroserviceInstance();
instance.setServiceId(serviceId);
instance.setHostName("TestHost");
instance.setEndpoints(addresses);
instance.setHealthCheck(healthCheck);
String instanceId = client.registerMicroserviceInstance(instance);
LOG.info("register service {} instance {}", serviceId, instanceId);
List<MicroserviceInstance> microserviceInstances = client.getMicroserviceInstance(serviceId, serviceId);
for (MicroserviceInstance microserviceInstance : microserviceInstances) {
LOG.info(microserviceInstance.toString());
}
// 实例心跳
HeartbeatResponse response = client.heartbeat(serviceId, instanceId);
LOG.info("heartbeat {}", response);
// 查询给定idl服务
List<MicroserviceInstance> instances = client.findServiceInstance(serviceId, APP_NAME, SERVICE_NAME, "1.0+");
for (MicroserviceInstance inst : instances) {
LOG.info("{}", inst);
}
// 删除服务
//client.deleteService(service.getProviderServiceId(), true);
LOG.info("finish!!!");
}
use of io.servicecomb.serviceregistry.api.registry.MicroserviceInstance in project java-chassis by ServiceComb.
the class TestIpPortManager method testCreateServiceRegistryCache.
@Test
public void testCreateServiceRegistryCache() {
boolean validAssert = true;
List<MicroserviceInstance> list = new ArrayList<MicroserviceInstance>();
MicroserviceInstance e1 = new MicroserviceInstance();
List<String> endpoints = new ArrayList<>();
endpoints.add("rest://127.0.0.1:8080");
e1.setEndpoints(endpoints);
list.add(e1);
new MockUp<RegistryUtils>() {
@Mock
public List<MicroserviceInstance> findServiceInstance(String appId, String serviceName, String versionRule) {
return list;
}
};
Microservice microservice = new Microservice();
new MockUp<RegistryUtils>() {
@Mock
private Microservice createMicroserviceFromDefinition() {
return microservice;
}
};
try {
manager.createServiceRegistryCache();
Assert.assertNotNull(manager.get());
Assert.assertNull(manager.next());
} catch (Exception e) {
validAssert = false;
}
Assert.assertTrue(validAssert);
}
Aggregations