use of org.apache.servicecomb.core.BootListener.BootEvent in project java-chassis by ServiceComb.
the class TestProducerBootListener method onBootEvent_close.
@Test
public void onBootEvent_close(@Mocked SCBEngine scbEngine, @Mocked MicroserviceMeta microserviceMeta, @Mocked OperationMeta op1, @Mocked OperationMeta op2, @Mocked GroupExecutor closeable) {
AtomicInteger count = new AtomicInteger();
ExecutorService executorService = new MockUp<ExecutorService>() {
@Mock
void shutdown() {
count.incrementAndGet();
}
}.getMockInstance();
new MockUp<Closeable>(closeable) {
@Mock
void close() {
count.incrementAndGet();
}
};
new Expectations() {
{
scbEngine.getProducerMicroserviceMeta();
result = microserviceMeta;
microserviceMeta.getOperations();
result = Arrays.asList(op1, op2);
op1.getExecutor();
result = executorService;
op2.getExecutor();
result = closeable;
}
};
BootEvent event = new BootEvent();
event.setScbEngine(scbEngine);
event.setEventType(EventType.AFTER_CLOSE);
producerBootListener.onBootEvent(event);
Assert.assertEquals(2, count.get());
}
use of org.apache.servicecomb.core.BootListener.BootEvent in project java-chassis by ServiceComb.
the class TestProducerBootListener method onBootEvent_close_unknown.
@Test
public void onBootEvent_close_unknown(@Mocked SCBEngine scbEngine, @Mocked MicroserviceMeta microserviceMeta, @Mocked OperationMeta op1) {
Executor executor = new UnCloseableExecutor();
new Expectations() {
{
scbEngine.getProducerMicroserviceMeta();
result = microserviceMeta;
microserviceMeta.getOperations();
result = Arrays.asList(op1);
op1.getExecutor();
result = executor;
}
};
try (LogCollector logCollector = new LogCollector()) {
BootEvent event = new BootEvent();
event.setScbEngine(scbEngine);
event.setEventType(EventType.AFTER_CLOSE);
producerBootListener.onBootEvent(event);
Assert.assertEquals("Executor org.apache.servicecomb.core.provider.producer.TestProducerBootListener$UnCloseableExecutor " + "do not support close or shutdown, it may block service shutdown.", logCollector.getLastEvents().getMessage());
}
}
use of org.apache.servicecomb.core.BootListener.BootEvent in project java-chassis by ServiceComb.
the class SCBEngine method triggerEvent.
protected void triggerEvent(EventType eventType) {
BootEvent event = new BootEvent();
event.setScbEngine(this);
event.setEventType(eventType);
for (BootListener listener : bootListeners) {
listener.onBootEvent(event);
}
}
use of org.apache.servicecomb.core.BootListener.BootEvent 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));
}
use of org.apache.servicecomb.core.BootListener.BootEvent 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());
}
Aggregations