Search in sources :

Example 6 with BootEvent

use of org.apache.servicecomb.core.BootListener.BootEvent 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 7 with BootEvent

use of org.apache.servicecomb.core.BootListener.BootEvent 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 8 with BootEvent

use of org.apache.servicecomb.core.BootListener.BootEvent in project incubator-servicecomb-java-chassis by apache.

the class CseApplicationListener method triggerEvent.

protected void triggerEvent(EventType eventType) {
    BootEvent event = new BootEvent();
    event.setEventType(eventType);
    for (BootListener listener : bootListenerList) {
        listener.onBootEvent(event);
    }
}
Also used : BootEvent(org.apache.servicecomb.core.BootListener.BootEvent)

Example 9 with BootEvent

use of org.apache.servicecomb.core.BootListener.BootEvent in project incubator-servicecomb-java-chassis by apache.

the class TestAuthHandlerBoot method testGenerateRSAKey.

@Test
public void testGenerateRSAKey() {
    MicroserviceInstance microserviceInstance = new MicroserviceInstance();
    Microservice microservice = new Microservice();
    microservice.setInstance(microserviceInstance);
    new Expectations(RegistryUtils.class) {

        {
            RegistryUtils.getMicroserviceInstance();
            result = microserviceInstance;
        }
    };
    AuthHandlerBoot authHandlerBoot = new AuthHandlerBoot();
    BootEvent bootEvent = new BootEvent();
    bootEvent.setEventType(BootListener.EventType.BEFORE_REGISTRY);
    authHandlerBoot.onBootEvent(bootEvent);
    Assert.assertNotNull(RSAKeypair4Auth.INSTANCE.getPrivateKey());
    Assert.assertNotNull(RSAKeypair4Auth.INSTANCE.getPublicKey());
}
Also used : Expectations(mockit.Expectations) Microservice(org.apache.servicecomb.serviceregistry.api.registry.Microservice) AuthHandlerBoot(org.apache.servicecomb.AuthHandlerBoot) BootEvent(org.apache.servicecomb.core.BootListener.BootEvent) MicroserviceInstance(org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance) Test(org.junit.Test)

Example 10 with BootEvent

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

the class TestProducerBootListener method onBootEvent_notClose.

@Test
public void onBootEvent_notClose() {
    BootEvent event = new BootEvent();
    event.setEventType(EventType.BEFORE_CLOSE);
    // should not throw exception
    producerBootListener.onBootEvent(event);
}
Also used : BootEvent(org.apache.servicecomb.core.BootListener.BootEvent) Test(org.junit.Test)

Aggregations

BootEvent (org.apache.servicecomb.core.BootListener.BootEvent)16 Test (org.junit.Test)13 SCBEngine (org.apache.servicecomb.core.SCBEngine)6 ProducerProviderManager (org.apache.servicecomb.core.provider.producer.ProducerProviderManager)5 ArrayList (java.util.ArrayList)4 ProducerMeta (org.apache.servicecomb.core.provider.producer.ProducerMeta)4 Expectations (mockit.Expectations)3 AuthHandlerBoot (org.apache.servicecomb.AuthHandlerBoot)3 MicroserviceMeta (org.apache.servicecomb.core.definition.MicroserviceMeta)2 LogCollector (org.apache.servicecomb.foundation.test.scaffolding.log.LogCollector)2 Executor (java.util.concurrent.Executor)1 ExecutorService (java.util.concurrent.ExecutorService)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Mock (mockit.Mock)1 MockUp (mockit.MockUp)1 EventType (org.apache.servicecomb.core.BootListener.EventType)1 SchemaMeta (org.apache.servicecomb.core.definition.SchemaMeta)1 GroupExecutor (org.apache.servicecomb.core.executor.GroupExecutor)1 Holder (org.apache.servicecomb.foundation.common.Holder)1 HealthCheckerRestPublisher (org.apache.servicecomb.metrics.core.publish.HealthCheckerRestPublisher)1