Search in sources :

Example 11 with BaseStat

use of com.alipay.sofa.boot.startup.BaseStat in project sofa-boot by alipay.

the class StartupModelCreatingStage method doProcess.

@Override
protected void doProcess() throws Exception {
    BaseStat stat = new BaseStat();
    stat.setName(ISLE_MODEL_CREATING_STAGE);
    stat.setStartTime(System.currentTimeMillis());
    try {
        super.doProcess();
    } finally {
        stat.setEndTime(System.currentTimeMillis());
        startupReporter.addCommonStartupStat(stat);
    }
}
Also used : BaseStat(com.alipay.sofa.boot.startup.BaseStat)

Example 12 with BaseStat

use of com.alipay.sofa.boot.startup.BaseStat in project sofa-boot by alipay.

the class HealthCheckStartupReporterTest method testStartupReporter.

@Test
public void testStartupReporter() {
    Assert.assertNotNull(startupReporter);
    StartupReporter.StartupStaticsModel startupStaticsModel = startupReporter.report();
    Assert.assertNotNull(startupStaticsModel);
    Assert.assertEquals(6, startupStaticsModel.getStageStats().size());
    BaseStat healthCheckStage = startupReporter.getStageNyName(BootStageConstants.HEALTH_CHECK_STAGE);
    Assert.assertNotNull(healthCheckStage);
    Assert.assertTrue(healthCheckStage.getCost() > 0);
}
Also used : StartupReporter(com.alipay.sofa.startup.StartupReporter) BaseStat(com.alipay.sofa.boot.startup.BaseStat) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 13 with BaseStat

use of com.alipay.sofa.boot.startup.BaseStat in project sofa-boot by alipay.

the class SimpleStartupReporterTest method testStartupReporter.

@Test
public void testStartupReporter() {
    Assert.assertNotNull(startupReporter);
    StartupReporter.StartupStaticsModel startupStaticsModel = startupReporter.report();
    Assert.assertNotNull(startupStaticsModel);
    Assert.assertEquals(5, startupStaticsModel.getStageStats().size());
    Assert.assertTrue(startupStaticsModel.getApplicationBootTime() > 0);
    Assert.assertTrue(startupStaticsModel.getApplicationBootElapsedTime() > 0);
    Assert.assertEquals("StartupTest", startupStaticsModel.getAppName());
    BaseStat jvmStartingStage = startupReporter.getStageNyName(BootStageConstants.JVM_STARTING_STAGE);
    Assert.assertNotNull(jvmStartingStage);
    Assert.assertTrue(jvmStartingStage.getCost() > 0);
    BaseStat environmentPrepareStage = startupReporter.getStageNyName(BootStageConstants.ENVIRONMENT_PREPARE_STAGE);
    Assert.assertNotNull(environmentPrepareStage);
    Assert.assertTrue(environmentPrepareStage.getCost() > 0);
    Assert.assertEquals(jvmStartingStage.getEndTime(), environmentPrepareStage.getStartTime());
    ChildrenStat<?> applicationContextPrepareStage = (ChildrenStat<?>) startupReporter.getStageNyName(BootStageConstants.APPLICATION_CONTEXT_PREPARE_STAGE);
    Assert.assertNotNull(applicationContextPrepareStage);
    Assert.assertTrue(applicationContextPrepareStage.getChildren().isEmpty());
    Assert.assertTrue(applicationContextPrepareStage.getCost() > 0);
    Assert.assertEquals(environmentPrepareStage.getEndTime(), applicationContextPrepareStage.getStartTime());
    BaseStat applicationContextLoadStage = startupReporter.getStageNyName(BootStageConstants.APPLICATION_CONTEXT_LOAD_STAGE);
    Assert.assertNotNull(applicationContextLoadStage);
    Assert.assertTrue(applicationContextLoadStage.getCost() > 0);
    Assert.assertEquals(applicationContextPrepareStage.getEndTime(), applicationContextLoadStage.getStartTime());
    BaseStat applicationContextRefreshStage = startupReporter.getStageNyName(BootStageConstants.APPLICATION_CONTEXT_REFRESH_STAGE);
    Assert.assertNotNull(applicationContextRefreshStage);
    Assert.assertTrue(applicationContextRefreshStage.getCost() > 0);
    Assert.assertEquals(applicationContextLoadStage.getEndTime(), applicationContextRefreshStage.getStartTime());
    Assert.assertTrue(applicationContextRefreshStage instanceof ChildrenStat);
    Assert.assertEquals(1, ((ChildrenStat<?>) applicationContextRefreshStage).getChildren().size());
    ModuleStat moduleStat = (ModuleStat) ((ChildrenStat<?>) applicationContextRefreshStage).getChildren().get(0);
    Assert.assertNotNull(moduleStat);
    Assert.assertEquals(StartupContextRefreshedListener.ROOT_MODULE_NAME, moduleStat.getName());
    Assert.assertTrue(moduleStat.getEndTime() > moduleStat.getStartTime());
    Assert.assertEquals(moduleStat.getCost(), moduleStat.getEndTime() - moduleStat.getStartTime());
    List<BeanStat> beanStats = moduleStat.getChildren();
    Assert.assertNotNull(beanStats);
    Assert.assertTrue(beanStats.size() >= 1);
    BeanStat initBeanStat = beanStats.stream().filter(beanStat -> beanStat.getBeanClassName().contains("InitCostBean")).findFirst().orElse(null);
    Assert.assertNotNull(initBeanStat);
    Assert.assertEquals(initBeanStat.getRefreshElapsedTime(), initBeanStat.getBeanRefreshEndTime() - initBeanStat.getBeanRefreshStartTime());
    Assert.assertEquals(InitCostBean.INIT_COST_TIME, initBeanStat.getRealRefreshElapsedTime(), 20);
    Assert.assertNull(initBeanStat.getBeanType());
    Assert.assertEquals(InitCostBean.class.getName() + " (initCostBean)", initBeanStat.getBeanClassName());
    Assert.assertTrue(initBeanStat.getChildren().isEmpty());
    Assert.assertEquals(0, initBeanStat.getAfterPropertiesSetTime());
    Assert.assertEquals(0, initBeanStat.getInitTime());
    Assert.assertNull(initBeanStat.getInterfaceType());
    Assert.assertNull(initBeanStat.getExtensionProperty());
}
Also used : StartupReporter(com.alipay.sofa.startup.StartupReporter) ChildrenStat(com.alipay.sofa.boot.startup.ChildrenStat) ModuleStat(com.alipay.sofa.boot.startup.ModuleStat) BeanStat(com.alipay.sofa.boot.startup.BeanStat) BaseStat(com.alipay.sofa.boot.startup.BaseStat) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 14 with BaseStat

use of com.alipay.sofa.boot.startup.BaseStat in project sofa-boot by sofastack.

the class StartupSpringApplicationRunListener method contextLoaded.

@Override
public void contextLoaded(ConfigurableApplicationContext context) {
    BaseStat stat = new BaseStat();
    stat.setName(APPLICATION_CONTEXT_LOAD_STAGE);
    stat.setStartTime(applicationContextPrepareStage.getEndTime());
    stat.setEndTime(System.currentTimeMillis());
    this.applicationContextLoadStage = stat;
}
Also used : BaseStat(com.alipay.sofa.boot.startup.BaseStat)

Example 15 with BaseStat

use of com.alipay.sofa.boot.startup.BaseStat in project sofa-boot by sofastack.

the class StartupReadinessCheckListener method readinessHealthCheck.

@Override
public void readinessHealthCheck() {
    BaseStat stat = new BaseStat();
    stat.setName(HEALTH_CHECK_STAGE);
    stat.setStartTime(System.currentTimeMillis());
    super.readinessHealthCheck();
    stat.setEndTime(System.currentTimeMillis());
    startupReporter.addCommonStartupStat(stat);
}
Also used : BaseStat(com.alipay.sofa.boot.startup.BaseStat)

Aggregations

BaseStat (com.alipay.sofa.boot.startup.BaseStat)18 StartupReporter (com.alipay.sofa.startup.StartupReporter)6 Test (org.junit.Test)6 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)6 BeanStat (com.alipay.sofa.boot.startup.BeanStat)4 ChildrenStat (com.alipay.sofa.boot.startup.ChildrenStat)4 ModuleStat (com.alipay.sofa.boot.startup.ModuleStat)4 ExtensionFactoryBean (com.alipay.sofa.runtime.ext.spring.ExtensionFactoryBean)2 ExtensionPointFactoryBean (com.alipay.sofa.runtime.ext.spring.ExtensionPointFactoryBean)2 ApplicationContextInitializer (org.springframework.context.ApplicationContextInitializer)2