Search in sources :

Example 81 with Microservice

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");
}
Also used : Microservice(org.apache.servicecomb.registry.api.registry.Microservice) MicroserviceInstance(org.apache.servicecomb.registry.api.registry.MicroserviceInstance) EventBus(com.google.common.eventbus.EventBus) Subscribe(com.google.common.eventbus.Subscribe) Before(org.junit.Before)

Example 82 with Microservice

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());
}
Also used : LogCollector(org.apache.servicecomb.foundation.test.scaffolding.log.LogCollector) Microservice(org.apache.servicecomb.registry.api.registry.Microservice) MicroserviceInstance(org.apache.servicecomb.registry.api.registry.MicroserviceInstance) EventBus(com.google.common.eventbus.EventBus) Subscribe(com.google.common.eventbus.Subscribe) Before(org.junit.Before)

Example 83 with Microservice

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());
}
Also used : Expectations(mockit.Expectations) Microservice(org.apache.servicecomb.registry.api.registry.Microservice) Holder(org.apache.servicecomb.serviceregistry.client.http.Holder) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) GetSchemaResponse(org.apache.servicecomb.serviceregistry.api.response.GetSchemaResponse) Test(org.junit.Test)

Example 84 with Microservice

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());
}
Also used : Expectations(mockit.Expectations) Microservice(org.apache.servicecomb.registry.api.registry.Microservice) Holder(org.apache.servicecomb.serviceregistry.client.http.Holder) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) GetSchemaResponse(org.apache.servicecomb.serviceregistry.api.response.GetSchemaResponse) Test(org.junit.Test)

Example 85 with Microservice

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());
}
Also used : Microservice(org.apache.servicecomb.registry.api.registry.Microservice) MicroserviceInstance(org.apache.servicecomb.registry.api.registry.MicroserviceInstance) URIEndpointObject(org.apache.servicecomb.foundation.common.net.URIEndpointObject)

Aggregations

Microservice (org.apache.servicecomb.registry.api.registry.Microservice)86 Test (org.junit.Test)53 MicroserviceInstance (org.apache.servicecomb.registry.api.registry.MicroserviceInstance)20 Expectations (mockit.Expectations)15 ArrayList (java.util.ArrayList)14 List (java.util.List)13 GetSchemaResponse (org.apache.servicecomb.serviceregistry.api.response.GetSchemaResponse)10 Holder (org.apache.servicecomb.serviceregistry.client.http.Holder)10 HashMap (java.util.HashMap)9 MicroserviceFactory (org.apache.servicecomb.registry.api.registry.MicroserviceFactory)9 Swagger (io.swagger.models.Swagger)8 Before (org.junit.Before)8 MockUp (mockit.MockUp)6 Configuration (org.apache.commons.configuration.Configuration)6 AccessController (org.apache.servicecomb.authentication.provider.AccessController)6 Subscribe (com.google.common.eventbus.Subscribe)5 MicroserviceInstances (org.apache.servicecomb.registry.api.registry.MicroserviceInstances)5 EventBus (com.google.common.eventbus.EventBus)4 Version (org.apache.servicecomb.foundation.common.Version)4 HashSet (java.util.HashSet)3