use of org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance in project incubator-servicecomb-java-chassis by apache.
the class TestCseDiscoveryClient method testCseDiscoveryClient.
@Test
public void testCseDiscoveryClient(@Mocked RegistryUtils registryUtils, @Injectable ServiceRegistryClient serviceRegistryClient, @Mocked DiscoveryTree discoveryTree, @Injectable DiscoveryTreeNode versionedCache) {
List<Microservice> microserviceList = new ArrayList<>();
Microservice service1 = new Microservice();
service1.setServiceName("service1");
microserviceList.add(service1);
Microservice server2 = new Microservice();
microserviceList.add(server2);
server2.setServiceName("server2");
Map<String, MicroserviceInstance> servers = new HashMap<>();
List<String> endpoints = new ArrayList<>();
endpoints.add("rest://localhost:3333");
endpoints.add("rest://localhost:4444");
MicroserviceInstance instance1 = new MicroserviceInstance();
instance1.setServiceId("service1");
instance1.setInstanceId("service1-instance1");
instance1.setEndpoints(endpoints);
servers.put("service1-instance1", instance1);
new Expectations() {
{
RegistryUtils.getServiceRegistryClient();
result = serviceRegistryClient;
serviceRegistryClient.getAllMicroservices();
result = microserviceList;
discoveryTree.discovery((DiscoveryContext) any, anyString, anyString, anyString);
result = versionedCache;
versionedCache.data();
result = servers;
}
};
DiscoveryClient client = new CseDiscoveryClient();
Assert.assertEquals("Spring Cloud CSE Discovery Client", client.description());
Assert.assertEquals(null, client.getLocalServiceInstance());
Assert.assertEquals(2, client.getServices().size());
Assert.assertEquals("server2", client.getServices().get(1));
Assert.assertEquals(2, client.getInstances("service1-instance1").size());
Assert.assertEquals(4444, client.getInstances("service1-instance1").get(1).getPort());
}
use of org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance in project incubator-servicecomb-java-chassis by apache.
the class TestLoadbalanceHandler method getOrCreateLoadBalancer.
@Test
public void getOrCreateLoadBalancer() throws Exception {
MicroserviceInstance instance = new MicroserviceInstance();
instance.setInstanceId("id");
instance.getEndpoints().add("rest://localhost:8080");
Map<String, MicroserviceInstance> instanceMap = new HashMap<>();
instanceMap.put(instance.getInstanceId(), instance);
VersionedCache instanceVersionedCache = new VersionedCache().autoCacheVersion().name("instanceCache").data(instanceMap);
new Expectations() {
{
invocation.getConfigTransportName();
result = "rest";
instanceCacheManager.getOrCreateVersionedCache(anyString, anyString, anyString);
result = instanceVersionedCache;
}
};
LoadBalancer lb = handler.getOrCreateLoadBalancer(invocation);
Assert.assertEquals(2, lb.getFilterSize());
Assert.assertEquals("instanceCache/rest", lb.getName());
Assert.assertEquals("[rest://localhost:8080]", Deencapsulation.getField(lb, "serverList").toString());
}
use of org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance in project incubator-servicecomb-java-chassis by apache.
the class TestCseServerDiscoveryFilter method createEndpointNormal.
@Test
public void createEndpointNormal() {
new Expectations() {
{
transportManager.findTransport(anyString);
result = trasport;
}
};
MicroserviceInstance instance = new MicroserviceInstance();
CseServer server = (CseServer) filter.createEndpoint(Const.RESTFUL, "rest://localhost:8080", instance);
Assert.assertSame(instance, server.getInstance());
Assert.assertSame(trasport, server.getEndpoint().getTransport());
Assert.assertEquals("rest://localhost:8080", server.getEndpoint().getEndpoint());
}
use of org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance in project incubator-servicecomb-java-chassis by apache.
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 org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance in project incubator-servicecomb-java-chassis by apache.
the class TestAuthHandlerBoot method testGenerateRSAKey.
@Test
public void testGenerateRSAKey() {
MicroserviceInstance microserviceInstance = new MicroserviceInstance();
Microservice microservice = new Microservice();
microservice.setInstance(microserviceInstance);
new Expectations(RegistryUtils.class) {
{
RegistryUtils.getMicroserviceInstance();
result = microserviceInstance;
}
};
AuthHandlerBoot authHandlerBoot = new AuthHandlerBoot();
BootEvent bootEvent = new BootEvent();
bootEvent.setEventType(BootListener.EventType.BEFORE_REGISTRY);
authHandlerBoot.onBootEvent(bootEvent);
Assert.assertNotNull(RSAKeypair4Auth.INSTANCE.getPrivateKey());
Assert.assertNotNull(RSAKeypair4Auth.INSTANCE.getPublicKey());
}
Aggregations