Search in sources :

Example 6 with Microservice

use of org.apache.servicecomb.serviceregistry.api.registry.Microservice in project incubator-servicecomb-java-chassis by apache.

the class TestMicroserviceVersionMetaFactory method create.

@Test
public void create(@Mocked ConsumerSchemaFactory consumerSchemaFactory, @Mocked SchemaListenerManager schemaListenerManager) {
    String microserviceName = "app:ms";
    String microserviceId = "id";
    Microservice microservice = new Microservice();
    microservice.setVersion("1.0.0");
    new Expectations(RegistryUtils.class) {

        {
            RegistryUtils.getMicroservice(microserviceId);
            result = microservice;
        }
    };
    CseContext.getInstance().setConsumerSchemaFactory(consumerSchemaFactory);
    CseContext.getInstance().setSchemaListenerManager(schemaListenerManager);
    MicroserviceVersionMetaFactory factory = new MicroserviceVersionMetaFactory();
    MicroserviceVersion microserviceVersion = factory.create(microserviceName, microserviceId);
    Assert.assertThat(microserviceVersion, Matchers.instanceOf(MicroserviceVersionMeta.class));
}
Also used : Expectations(mockit.Expectations) Microservice(org.apache.servicecomb.serviceregistry.api.registry.Microservice) MicroserviceVersion(org.apache.servicecomb.serviceregistry.consumer.MicroserviceVersion) Test(org.junit.Test)

Example 7 with Microservice

use of org.apache.servicecomb.serviceregistry.api.registry.Microservice 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());
}
Also used : Microservice(org.apache.servicecomb.serviceregistry.api.registry.Microservice) HashMap(java.util.HashMap) MicroserviceInstance(org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance) Test(org.junit.Test)

Example 8 with Microservice

use of org.apache.servicecomb.serviceregistry.api.registry.Microservice in project incubator-servicecomb-java-chassis by apache.

the class MicroserviceVersionTestUtils method createMicroserviceVersion.

public static MicroserviceVersion createMicroserviceVersion(String microserviceId, String version) {
    Microservice microservice = new Microservice();
    microservice.setServiceId(microserviceId);
    microservice.setVersion(version);
    new Expectations(RegistryUtils.class) {

        {
            RegistryUtils.getMicroservice(microserviceId);
            result = microservice;
        }
    };
    return new MicroserviceVersion(microserviceId);
}
Also used : Expectations(mockit.Expectations) Microservice(org.apache.servicecomb.serviceregistry.api.registry.Microservice)

Example 9 with Microservice

use of org.apache.servicecomb.serviceregistry.api.registry.Microservice in project incubator-servicecomb-java-chassis by apache.

the class TestLocalServiceRegistry method testSchema.

@Test
public void testSchema() {
    ServiceRegistry serviceRegistry = ServiceRegistryFactory.createLocal();
    Microservice microservice = serviceRegistry.getMicroservice();
    microservice.addSchema("s1", "s1-content");
    serviceRegistry.init();
    serviceRegistry.run();
    try {
        serviceRegistry.getServiceRegistryClient().isSchemaExist("notExist", "s1");
        Assert.fail("must throw exception");
    } catch (IllegalArgumentException e) {
        Assert.assertEquals("Invalid serviceId, serviceId=notExist", e.getMessage());
    }
    try {
        serviceRegistry.getServiceRegistryClient().getSchema("notExist", "s1");
        Assert.fail("must throw exception");
    } catch (IllegalArgumentException e) {
        Assert.assertEquals("Invalid serviceId, serviceId=notExist", e.getMessage());
    }
    Assert.assertEquals(true, serviceRegistry.getServiceRegistryClient().isSchemaExist(microservice.getServiceId(), "s1"));
    String content = serviceRegistry.getServiceRegistryClient().getSchema(microservice.getServiceId(), "s1");
    Assert.assertEquals("s1-content", content);
}
Also used : Microservice(org.apache.servicecomb.serviceregistry.api.registry.Microservice) ServiceRegistry(org.apache.servicecomb.serviceregistry.ServiceRegistry) Test(org.junit.Test)

Example 10 with Microservice

use of org.apache.servicecomb.serviceregistry.api.registry.Microservice in project incubator-servicecomb-java-chassis by apache.

the class TestMicroserviceInstanceHeartbeatTask method testOtherMicroservice.

@Test
public void testOtherMicroservice(@Mocked ServiceRegistryClient srClient, @Mocked ServiceRegistryConfig serviceRegistryConfig, @Mocked MicroserviceWatchTask watchTask) {
    Microservice otherMicroservice = new Microservice();
    otherMicroservice.setServiceName("ms1");
    new Expectations() {

        {
            watchTask.getMicroservice();
            result = otherMicroservice;
        }
    };
    MicroserviceInstanceHeartbeatTask heartbeatTask = new MicroserviceInstanceHeartbeatTask(eventBus, srClient, microservice);
    watchTask.taskStatus = TaskStatus.READY;
    eventBus.post(watchTask);
    heartbeatTask.run();
    Assert.assertNull(heartbeatTask.getHeartbeatResult());
    Assert.assertEquals(false, heartbeatTask.isNeedRegisterInstance());
    Assert.assertEquals(0, heartbeatTaskList.size());
}
Also used : Expectations(mockit.Expectations) Microservice(org.apache.servicecomb.serviceregistry.api.registry.Microservice) Test(org.junit.Test)

Aggregations

Microservice (org.apache.servicecomb.serviceregistry.api.registry.Microservice)47 Test (org.junit.Test)24 MicroserviceInstance (org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance)15 Expectations (mockit.Expectations)11 HashMap (java.util.HashMap)6 ArrayList (java.util.ArrayList)5 EventBus (com.google.common.eventbus.EventBus)4 Before (org.junit.Before)4 Subscribe (com.google.common.eventbus.Subscribe)3 MockUp (mockit.MockUp)3 ServiceRegistry (org.apache.servicecomb.serviceregistry.ServiceRegistry)3 MicroserviceFactory (org.apache.servicecomb.serviceregistry.api.registry.MicroserviceFactory)3 MicroserviceInstances (org.apache.servicecomb.serviceregistry.client.http.MicroserviceInstances)3 Endpoint (org.apache.servicecomb.core.Endpoint)2 SchemaMeta (org.apache.servicecomb.core.definition.SchemaMeta)2 ClientException (org.apache.servicecomb.serviceregistry.client.ClientException)2 Version (org.apache.servicecomb.serviceregistry.version.Version)2 VersionRule (org.apache.servicecomb.serviceregistry.version.VersionRule)2 Handler (io.vertx.core.Handler)1 HttpClientOptions (io.vertx.core.http.HttpClientOptions)1