Search in sources :

Example 1 with BootEvent

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

the class SCBEngine method safeTriggerEvent.

protected void safeTriggerEvent(EventType eventType) {
    BootEvent event = new BootEvent();
    event.setScbEngine(this);
    event.setEventType(eventType);
    for (BootListener listener : bootListeners) {
        try {
            listener.onBootEvent(event);
            LOGGER.info("BootListener {} succeed to process {}.", listener.getClass().getName(), eventType);
        } catch (Throwable e) {
            LOGGER.error("BootListener {} failed to process {}.", listener.getClass().getName(), eventType, e);
        }
    }
}
Also used : BootEvent(org.apache.servicecomb.core.BootListener.BootEvent)

Example 2 with BootEvent

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

the class TestAuthHandlerBoot method testMicroserviceInstancePublicKey.

@Test
public void testMicroserviceInstancePublicKey() {
    AuthHandlerBoot authHandlerBoot = new AuthHandlerBoot();
    BootEvent bootEvent = new BootEvent();
    bootEvent.setEventType(BootListener.EventType.BEFORE_REGISTRY);
    authHandlerBoot.onBootEvent(bootEvent);
    String publicKey = RegistrationManager.INSTANCE.getMicroserviceInstance().getProperties().get(DefinitionConst.INSTANCE_PUBKEY_PRO);
    Assert.assertNotNull(publicKey);
}
Also used : AuthHandlerBoot(org.apache.servicecomb.AuthHandlerBoot) BootEvent(org.apache.servicecomb.core.BootListener.BootEvent) Test(org.junit.Test)

Example 3 with BootEvent

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

the class TestInspectorBootListener method filterEvent.

@Test
public void filterEvent() {
    BootEvent event = new BootEvent();
    InspectorBootListener listener = new InspectorBootListener(new InspectorConfig(), null);
    try (LogCollector logCollector = new LogCollector()) {
        for (EventType eventType : EventType.values()) {
            if (!EventType.AFTER_TRANSPORT.equals(eventType)) {
                event.setEventType(eventType);
                listener.onBootEvent(event);
            }
        }
        Assert.assertTrue(logCollector.getEvents().isEmpty());
    }
}
Also used : LogCollector(org.apache.servicecomb.foundation.test.scaffolding.log.LogCollector) EventType(org.apache.servicecomb.core.BootListener.EventType) BootEvent(org.apache.servicecomb.core.BootListener.BootEvent) Test(org.junit.Test)

Example 4 with BootEvent

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

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

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