Search in sources :

Example 1 with SchemaInfo

use of org.apache.servicecomb.service.center.client.model.SchemaInfo in project incubator-servicecomb-java-chassis by apache.

the class ServiceCenterClientTest method TestUpdateServiceSchema.

@Test
public void TestUpdateServiceSchema() throws IOException {
    ServiceCenterRawClient serviceCenterRawClient = Mockito.mock(ServiceCenterRawClient.class);
    HttpResponse httpResponse = new HttpResponse();
    httpResponse.setStatusCode(200);
    httpResponse.setMessage("ok");
    Mockito.when(serviceCenterRawClient.putHttpRequest(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(httpResponse);
    ServiceCenterClient serviceCenterClient = new ServiceCenterClient(serviceCenterRawClient);
    boolean result = serviceCenterClient.updateServiceSchemaContext("111", new SchemaInfo());
    Assert.assertNotNull(result);
    Assert.assertEquals(true, result);
}
Also used : HttpResponse(org.apache.servicecomb.http.client.common.HttpResponse) SchemaInfo(org.apache.servicecomb.service.center.client.model.SchemaInfo) Test(org.junit.Test)

Example 2 with SchemaInfo

use of org.apache.servicecomb.service.center.client.model.SchemaInfo in project incubator-servicecomb-java-chassis by apache.

the class ServiceCenterClientTest method TestGetServiceSchemas.

@Test
public void TestGetServiceSchemas() throws IOException {
    ServiceCenterRawClient serviceCenterRawClient = Mockito.mock(ServiceCenterRawClient.class);
    HttpResponse httpResponse = new HttpResponse();
    httpResponse.setStatusCode(200);
    httpResponse.setMessage("ok");
    String responseString = "{\n" + "  \"schemas\": [\n" + "    {\n" + "      \"schemaId\": \"111111\",\n" + "      \"schema\": \"test\",\n" + "      \"summary\": \"test\"\n" + "    }\n" + "  ]\n" + "}";
    httpResponse.setContent(responseString);
    Mockito.when(serviceCenterRawClient.getHttpRequest(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(httpResponse);
    ServiceCenterClient serviceCenterClient = new ServiceCenterClient(serviceCenterRawClient);
    List<SchemaInfo> schemaResponse = serviceCenterClient.getServiceSchemasList("111", false);
    ObjectMapper mapper = new ObjectMapper();
    JsonNode jsonNode = mapper.readTree(mapper.writeValueAsString(schemaResponse));
    Assert.assertNotNull(jsonNode);
    Assert.assertEquals("111111", jsonNode.get(0).get("schemaId").textValue());
    Assert.assertEquals("test", jsonNode.get(0).get("schema").textValue());
}
Also used : HttpResponse(org.apache.servicecomb.http.client.common.HttpResponse) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SchemaInfo(org.apache.servicecomb.service.center.client.model.SchemaInfo) Test(org.junit.Test)

Example 3 with SchemaInfo

use of org.apache.servicecomb.service.center.client.model.SchemaInfo in project incubator-servicecomb-java-chassis by apache.

the class RegistryClientTest method testRestTransport.

@Override
public void testRestTransport() throws Exception {
    AddressManager addressManager = new AddressManager("default", Arrays.asList("http://127.0.0.1:30100"), new EventBus());
    SSLProperties sslProperties = new SSLProperties();
    sslProperties.setEnabled(false);
    ServiceCenterClient serviceCenterClient = new ServiceCenterClient(addressManager, sslProperties, new DefaultRequestAuthHeaderProvider(), "default", null);
    EventBus eventBus = new SimpleEventBus();
    ServiceCenterConfiguration serviceCenterConfiguration = new ServiceCenterConfiguration();
    ServiceCenterRegistration serviceCenterRegistration = new ServiceCenterRegistration(serviceCenterClient, serviceCenterConfiguration, eventBus);
    Microservice microservice = new Microservice();
    microservice.setAppId("app_registry");
    microservice.setServiceName("name_registry");
    microservice.setVersion("1.0.0");
    microservice.setEnvironment("development");
    List<String> schemas = new ArrayList<>();
    schemas.add("SchemaA");
    schemas.add("SchemaB");
    microservice.setSchemas(schemas);
    MicroserviceInstance microserviceInstance = new MicroserviceInstance();
    microserviceInstance.setHostName("host_registry");
    List<String> endpoints = new ArrayList<>();
    endpoints.add("rest://127.0.0.1/");
    microserviceInstance.setEndpoints(endpoints);
    List<SchemaInfo> schemaInfos = new ArrayList<>();
    SchemaInfo schemaA = new SchemaInfo();
    schemaA.setSchemaId("SchemaA");
    schemaA.setSchema("schema contents in any format");
    schemaA.setSummary(Hashing.sha256().newHasher().putString("schema contents in any format".toString(), Charsets.UTF_8).hash().toString());
    schemaInfos.add(schemaA);
    SchemaInfo schemaB = new SchemaInfo();
    schemaB.setSchemaId("SchemaA");
    schemaB.setSchema("schema contents in any format");
    schemaB.setSummary(Hashing.sha256().newHasher().putString("schema contents in any format".toString(), Charsets.UTF_8).hash().toString());
    schemaInfos.add(schemaB);
    serviceCenterRegistration.setMicroservice(microservice);
    serviceCenterRegistration.setMicroserviceInstance(microserviceInstance);
    serviceCenterRegistration.setSchemaInfos(schemaInfos);
    eventBus.register(this);
    serviceCenterRegistration.startRegistration();
    registrationCounter.await(30000, TimeUnit.MILLISECONDS);
    if (hasRegistered) {
        TestMgr.check(events.size() >= 3, true);
        TestMgr.check(events.get(0).isSuccess(), true);
        TestMgr.check(events.get(0) instanceof MicroserviceRegistrationEvent, true);
        TestMgr.check(events.get(1).isSuccess(), true);
        TestMgr.check(events.get(1) instanceof MicroserviceInstanceRegistrationEvent, true);
        TestMgr.check(events.get(2).isSuccess(), true);
        TestMgr.check(events.get(2) instanceof HeartBeatEvent, true);
    } else {
        TestMgr.check(events.size() >= 4, true);
        TestMgr.check(events.get(0).isSuccess(), true);
        TestMgr.check(events.get(0) instanceof MicroserviceRegistrationEvent, true);
        TestMgr.check(events.get(1).isSuccess(), true);
        TestMgr.check(events.get(1) instanceof SchemaRegistrationEvent, true);
        TestMgr.check(events.get(2).isSuccess(), true);
        TestMgr.check(events.get(2) instanceof MicroserviceInstanceRegistrationEvent, true);
        TestMgr.check(events.get(3).isSuccess(), true);
        TestMgr.check(events.get(3) instanceof HeartBeatEvent, true);
    }
    ServiceCenterDiscovery discovery = new ServiceCenterDiscovery(serviceCenterClient, eventBus);
    discovery.updateMyselfServiceId(microservice.getServiceId());
    discovery.startDiscovery();
    discovery.registerIfNotPresent(new SubscriptionKey(microservice.getAppId(), microservice.getServiceName()));
    discoveryCounter.await(30000, TimeUnit.MILLISECONDS);
    TestMgr.check(instances != null, true);
    TestMgr.check(instances.size(), 1);
    discovery.stop();
    serviceCenterRegistration.stop();
    serviceCenterClient.deleteMicroserviceInstance(microservice.getServiceId(), microserviceInstance.getInstanceId());
}
Also used : SchemaRegistrationEvent(org.apache.servicecomb.service.center.client.RegistrationEvents.SchemaRegistrationEvent) AddressManager(org.apache.servicecomb.service.center.client.AddressManager) SubscriptionKey(org.apache.servicecomb.service.center.client.ServiceCenterDiscovery.SubscriptionKey) ServiceCenterConfiguration(org.apache.servicecomb.service.center.client.model.ServiceCenterConfiguration) ServiceCenterRegistration(org.apache.servicecomb.service.center.client.ServiceCenterRegistration) ServiceCenterDiscovery(org.apache.servicecomb.service.center.client.ServiceCenterDiscovery) SSLProperties(org.apache.servicecomb.http.client.common.HttpConfiguration.SSLProperties) ArrayList(java.util.ArrayList) MicroserviceInstance(org.apache.servicecomb.service.center.client.model.MicroserviceInstance) EventBus(com.google.common.eventbus.EventBus) SimpleEventBus(org.apache.servicecomb.foundation.common.event.SimpleEventBus) DefaultRequestAuthHeaderProvider(org.apache.servicecomb.http.client.auth.DefaultRequestAuthHeaderProvider) MicroserviceRegistrationEvent(org.apache.servicecomb.service.center.client.RegistrationEvents.MicroserviceRegistrationEvent) HeartBeatEvent(org.apache.servicecomb.service.center.client.RegistrationEvents.HeartBeatEvent) Microservice(org.apache.servicecomb.service.center.client.model.Microservice) ServiceCenterClient(org.apache.servicecomb.service.center.client.ServiceCenterClient) SimpleEventBus(org.apache.servicecomb.foundation.common.event.SimpleEventBus) MicroserviceInstanceRegistrationEvent(org.apache.servicecomb.service.center.client.RegistrationEvents.MicroserviceInstanceRegistrationEvent) SchemaInfo(org.apache.servicecomb.service.center.client.model.SchemaInfo)

Example 4 with SchemaInfo

use of org.apache.servicecomb.service.center.client.model.SchemaInfo in project java-chassis by ServiceComb.

the class ServiceCenterClientTest method TestGetServiceSchemas.

@Test
public void TestGetServiceSchemas() throws IOException {
    ServiceCenterRawClient serviceCenterRawClient = Mockito.mock(ServiceCenterRawClient.class);
    HttpResponse httpResponse = new HttpResponse();
    httpResponse.setStatusCode(200);
    httpResponse.setMessage("ok");
    String responseString = "{\n" + "  \"schemas\": [\n" + "    {\n" + "      \"schemaId\": \"111111\",\n" + "      \"schema\": \"test\",\n" + "      \"summary\": \"test\"\n" + "    }\n" + "  ]\n" + "}";
    httpResponse.setContent(responseString);
    Mockito.when(serviceCenterRawClient.getHttpRequest(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(httpResponse);
    ServiceCenterClient serviceCenterClient = new ServiceCenterClient(serviceCenterRawClient);
    List<SchemaInfo> schemaResponse = serviceCenterClient.getServiceSchemasList("111", false);
    ObjectMapper mapper = new ObjectMapper();
    JsonNode jsonNode = mapper.readTree(mapper.writeValueAsString(schemaResponse));
    Assert.assertNotNull(jsonNode);
    Assert.assertEquals("111111", jsonNode.get(0).get("schemaId").textValue());
    Assert.assertEquals("test", jsonNode.get(0).get("schema").textValue());
}
Also used : HttpResponse(org.apache.servicecomb.http.client.common.HttpResponse) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SchemaInfo(org.apache.servicecomb.service.center.client.model.SchemaInfo) Test(org.junit.Test)

Example 5 with SchemaInfo

use of org.apache.servicecomb.service.center.client.model.SchemaInfo in project java-chassis by ServiceComb.

the class ServiceCenterClientTest method TestUpdateServiceSchema.

@Test
public void TestUpdateServiceSchema() throws IOException {
    ServiceCenterRawClient serviceCenterRawClient = Mockito.mock(ServiceCenterRawClient.class);
    HttpResponse httpResponse = new HttpResponse();
    httpResponse.setStatusCode(200);
    httpResponse.setMessage("ok");
    Mockito.when(serviceCenterRawClient.putHttpRequest(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(httpResponse);
    ServiceCenterClient serviceCenterClient = new ServiceCenterClient(serviceCenterRawClient);
    boolean result = serviceCenterClient.updateServiceSchemaContext("111", new SchemaInfo());
    Assert.assertNotNull(result);
    Assert.assertEquals(true, result);
}
Also used : HttpResponse(org.apache.servicecomb.http.client.common.HttpResponse) SchemaInfo(org.apache.servicecomb.service.center.client.model.SchemaInfo) Test(org.junit.Test)

Aggregations

SchemaInfo (org.apache.servicecomb.service.center.client.model.SchemaInfo)6 HttpResponse (org.apache.servicecomb.http.client.common.HttpResponse)4 Test (org.junit.Test)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 EventBus (com.google.common.eventbus.EventBus)2 ArrayList (java.util.ArrayList)2 SimpleEventBus (org.apache.servicecomb.foundation.common.event.SimpleEventBus)2 DefaultRequestAuthHeaderProvider (org.apache.servicecomb.http.client.auth.DefaultRequestAuthHeaderProvider)2 SSLProperties (org.apache.servicecomb.http.client.common.HttpConfiguration.SSLProperties)2 AddressManager (org.apache.servicecomb.service.center.client.AddressManager)2 HeartBeatEvent (org.apache.servicecomb.service.center.client.RegistrationEvents.HeartBeatEvent)2 MicroserviceInstanceRegistrationEvent (org.apache.servicecomb.service.center.client.RegistrationEvents.MicroserviceInstanceRegistrationEvent)2 MicroserviceRegistrationEvent (org.apache.servicecomb.service.center.client.RegistrationEvents.MicroserviceRegistrationEvent)2 SchemaRegistrationEvent (org.apache.servicecomb.service.center.client.RegistrationEvents.SchemaRegistrationEvent)2 ServiceCenterClient (org.apache.servicecomb.service.center.client.ServiceCenterClient)2 ServiceCenterDiscovery (org.apache.servicecomb.service.center.client.ServiceCenterDiscovery)2 SubscriptionKey (org.apache.servicecomb.service.center.client.ServiceCenterDiscovery.SubscriptionKey)2 ServiceCenterRegistration (org.apache.servicecomb.service.center.client.ServiceCenterRegistration)2 Microservice (org.apache.servicecomb.service.center.client.model.Microservice)2