Search in sources :

Example 1 with SCBEngine

use of org.apache.servicecomb.core.SCBEngine in project java-chassis by ServiceComb.

the class TestInspectorBootListener method disabled.

@Test
public void disabled() {
    SCBEngine scbEngine = SCBBootstrap.createSCBEngineForTest();
    scbEngine.setProducerMicroserviceMeta(new MicroserviceMeta(scbEngine, "ms", false));
    InspectorConfig inspectorConfig = new InspectorConfig().setEnabled(false);
    new InspectorBootListener(inspectorConfig, null).onAfterTransport(new BootEvent(scbEngine, EventType.AFTER_TRANSPORT));
    Assert.assertNull(scbEngine.getProducerMicroserviceMeta().findSchemaMeta("inspector"));
}
Also used : SCBEngine(org.apache.servicecomb.core.SCBEngine) MicroserviceMeta(org.apache.servicecomb.core.definition.MicroserviceMeta) BootEvent(org.apache.servicecomb.core.BootListener.BootEvent) Test(org.junit.Test)

Example 2 with SCBEngine

use of org.apache.servicecomb.core.SCBEngine in project java-chassis by ServiceComb.

the class TestInspectorBootListener method enabled.

@Test
public void enabled() {
    Holder<Object> holder = new Holder<>();
    SCBEngine scbEngine = SCBBootstrap.createSCBEngineForTest();
    scbEngine.setProducerMicroserviceMeta(new MicroserviceMeta(scbEngine, "ms", false));
    scbEngine.setProducerProviderManager(new ProducerProviderManager(scbEngine) {

        @Override
        public SchemaMeta registerSchema(String schemaId, Object instance) {
            if ("inspector".equals(schemaId)) {
                holder.value = instance;
            }
            return null;
        }
    });
    InspectorConfig inspectorConfig = new InspectorConfig().setEnabled(true);
    new InspectorBootListener(inspectorConfig, null).onAfterTransport(new BootEvent(scbEngine, EventType.AFTER_TRANSPORT));
    Assert.assertNotNull(holder.value);
}
Also used : SCBEngine(org.apache.servicecomb.core.SCBEngine) Holder(org.apache.servicecomb.foundation.common.Holder) SchemaMeta(org.apache.servicecomb.core.definition.SchemaMeta) MicroserviceMeta(org.apache.servicecomb.core.definition.MicroserviceMeta) BootEvent(org.apache.servicecomb.core.BootListener.BootEvent) ProducerProviderManager(org.apache.servicecomb.core.provider.producer.ProducerProviderManager) Test(org.junit.Test)

Example 3 with SCBEngine

use of org.apache.servicecomb.core.SCBEngine in project java-chassis by ServiceComb.

the class TestMetricsBootListener method onBeforeProducerProvider_metrics_endpoint_disabled.

@Test
public void onBeforeProducerProvider_metrics_endpoint_disabled() {
    ArchaiusUtils.setProperty("servicecomb.metrics.endpoint.enabled", false);
    final MetricsBootListener listener = new MetricsBootListener();
    final List<ProducerMeta> producerMetas = new ArrayList<>();
    final BootEvent event = new BootEvent();
    final SCBEngine scbEngine = new SCBEngine() {

        public final ProducerProviderManager producerProviderManager = new ProducerProviderManager(this) {

            @Override
            public void addProducerMeta(String schemaId, Object instance) {
                producerMetas.add(new ProducerMeta(schemaId, instance));
            }
        };

        @Override
        public ProducerProviderManager getProducerProviderManager() {
            return producerProviderManager;
        }
    };
    event.setScbEngine(scbEngine);
    listener.onBeforeProducerProvider(event);
    Assert.assertThat(producerMetas, Matchers.empty());
}
Also used : ProducerMeta(org.apache.servicecomb.core.provider.producer.ProducerMeta) SCBEngine(org.apache.servicecomb.core.SCBEngine) ArrayList(java.util.ArrayList) BootEvent(org.apache.servicecomb.core.BootListener.BootEvent) ProducerProviderManager(org.apache.servicecomb.core.provider.producer.ProducerProviderManager) Test(org.junit.Test)

Example 4 with SCBEngine

use of org.apache.servicecomb.core.SCBEngine in project java-chassis by ServiceComb.

the class TestMetricsBootListener method onBeforeProducerProvider_metrics_endpoint_enabled_by_default.

@Test
public void onBeforeProducerProvider_metrics_endpoint_enabled_by_default() {
    final MetricsBootListener listener = new MetricsBootListener();
    final List<ProducerMeta> producerMetas = new ArrayList<>();
    final BootEvent event = new BootEvent();
    final ProducerMeta producerMeta = new ProducerMeta();
    final SCBEngine scbEngine = new SCBEngine() {

        public final ProducerProviderManager producerProviderManager = new ProducerProviderManager(this) {

            @Override
            public void addProducerMeta(String schemaId, Object instance) {
                producerMeta.setSchemaId(schemaId);
                producerMeta.setInstance(instance);
                producerMetas.add(producerMeta);
            }
        };

        @Override
        public ProducerProviderManager getProducerProviderManager() {
            return producerProviderManager;
        }
    };
    event.setScbEngine(scbEngine);
    listener.onBeforeProducerProvider(event);
    Assert.assertThat(producerMetas, Matchers.contains(producerMeta));
    Assert.assertThat(producerMeta.getSchemaId(), Matchers.equalTo("metricsEndpoint"));
    Assert.assertThat(producerMeta.getInstance(), Matchers.instanceOf(MetricsRestPublisher.class));
}
Also used : ProducerMeta(org.apache.servicecomb.core.provider.producer.ProducerMeta) SCBEngine(org.apache.servicecomb.core.SCBEngine) ArrayList(java.util.ArrayList) BootEvent(org.apache.servicecomb.core.BootListener.BootEvent) MetricsRestPublisher(org.apache.servicecomb.metrics.core.publish.MetricsRestPublisher) ProducerProviderManager(org.apache.servicecomb.core.provider.producer.ProducerProviderManager) Test(org.junit.Test)

Example 5 with SCBEngine

use of org.apache.servicecomb.core.SCBEngine in project java-chassis by ServiceComb.

the class PojoReferenceMetaTest method testHasConsumerInterface.

@Test
public void testHasConsumerInterface() {
    SCBEngine scbEngine = SCBBootstrap.createSCBEngineForTest();
    PojoReferenceMeta pojoReferenceMeta = new PojoReferenceMeta();
    pojoReferenceMeta.setMicroserviceName("test");
    pojoReferenceMeta.setSchemaId("schemaId");
    pojoReferenceMeta.setConsumerIntf(IPerson.class);
    pojoReferenceMeta.afterPropertiesSet();
    Assert.assertEquals(IPerson.class, pojoReferenceMeta.getObjectType());
    assertThat(pojoReferenceMeta.getProxy(), instanceOf(IPerson.class));
    Assert.assertEquals(true, pojoReferenceMeta.isSingleton());
    scbEngine.destroy();
}
Also used : IPerson(org.apache.servicecomb.provider.pojo.IPerson) SCBEngine(org.apache.servicecomb.core.SCBEngine) Test(org.junit.Test)

Aggregations

SCBEngine (org.apache.servicecomb.core.SCBEngine)12 Test (org.junit.Test)11 BootEvent (org.apache.servicecomb.core.BootListener.BootEvent)6 ProducerProviderManager (org.apache.servicecomb.core.provider.producer.ProducerProviderManager)5 ArrayList (java.util.ArrayList)4 ProducerMeta (org.apache.servicecomb.core.provider.producer.ProducerMeta)4 MicroserviceMeta (org.apache.servicecomb.core.definition.MicroserviceMeta)2 JavaType (com.fasterxml.jackson.databind.JavaType)1 Method (java.lang.reflect.Method)1 Transport (org.apache.servicecomb.core.Transport)1 SchemaMeta (org.apache.servicecomb.core.definition.SchemaMeta)1 Holder (org.apache.servicecomb.foundation.common.Holder)1 HealthCheckerRestPublisher (org.apache.servicecomb.metrics.core.publish.HealthCheckerRestPublisher)1 MetricsRestPublisher (org.apache.servicecomb.metrics.core.publish.MetricsRestPublisher)1 IPerson (org.apache.servicecomb.provider.pojo.IPerson)1 PersonReference (org.apache.servicecomb.provider.pojo.PersonReference)1 ServletRestTransport (org.apache.servicecomb.transport.rest.servlet.ServletRestTransport)1