Search in sources :

Example 1 with ProducerProviderManager

use of org.apache.servicecomb.core.provider.producer.ProducerProviderManager 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 2 with ProducerProviderManager

use of org.apache.servicecomb.core.provider.producer.ProducerProviderManager 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 3 with ProducerProviderManager

use of org.apache.servicecomb.core.provider.producer.ProducerProviderManager 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 4 with ProducerProviderManager

use of org.apache.servicecomb.core.provider.producer.ProducerProviderManager in project java-chassis by ServiceComb.

the class TestHealthBootListener method onBeforeProducerProvider_health_endpoint_enabled_by_default.

@Test
public void onBeforeProducerProvider_health_endpoint_enabled_by_default() {
    final HealthBootListener listener = new HealthBootListener();
    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("healthEndpoint"));
    Assert.assertThat(producerMeta.getInstance(), Matchers.instanceOf(HealthCheckerRestPublisher.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) HealthCheckerRestPublisher(org.apache.servicecomb.metrics.core.publish.HealthCheckerRestPublisher) ProducerProviderManager(org.apache.servicecomb.core.provider.producer.ProducerProviderManager) Test(org.junit.Test)

Example 5 with ProducerProviderManager

use of org.apache.servicecomb.core.provider.producer.ProducerProviderManager in project java-chassis by ServiceComb.

the class TestHealthBootListener method onBeforeProducerProvider_health_endpoint_disabled.

@Test
public void onBeforeProducerProvider_health_endpoint_disabled() {
    ArchaiusUtils.setProperty("servicecomb.health.endpoint.enabled", false);
    final HealthBootListener listener = new HealthBootListener();
    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)

Aggregations

BootEvent (org.apache.servicecomb.core.BootListener.BootEvent)5 SCBEngine (org.apache.servicecomb.core.SCBEngine)5 ProducerProviderManager (org.apache.servicecomb.core.provider.producer.ProducerProviderManager)5 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)4 ProducerMeta (org.apache.servicecomb.core.provider.producer.ProducerMeta)4 MicroserviceMeta (org.apache.servicecomb.core.definition.MicroserviceMeta)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