当前位置: 首页>>代码示例>>Java>>正文


Java BQRuntime.shutdown方法代码示例

本文整理汇总了Java中io.bootique.BQRuntime.shutdown方法的典型用法代码示例。如果您正苦于以下问题:Java BQRuntime.shutdown方法的具体用法?Java BQRuntime.shutdown怎么用?Java BQRuntime.shutdown使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.bootique.BQRuntime的用法示例。


在下文中一共展示了BQRuntime.shutdown方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: run

import io.bootique.BQRuntime; //导入方法依赖的package包/类
public CommandOutcome run(Consumer<BQRuntime> beforeShutdownCallback, String... args) {

        BootLogger logger = createBootLogger();
        Bootique bootique = Bootique.app(args).bootLogger(logger);
        configure(bootique);

        BQRuntime runtime = bootique.createRuntime();
        try {
            return runtime.getInstance(Runner.class).run();
        } catch (Exception e) {
            logger.stderr("Error", e);
            return CommandOutcome.failed(1, getStderr());
        } finally {

            try {
                beforeShutdownCallback.accept(runtime);
            }
            finally {
                runtime.shutdown();
            }
        }
    }
 
开发者ID:bootique,项目名称:bootique-bom,代码行数:23,代码来源:BomTestApp.java

示例2: testRun_Debug

import io.bootique.BQRuntime; //导入方法依赖的package包/类
@Test
public void testRun_Debug() throws IOException {
    File logFile = prepareLogFile("target/logback/testRun_Debug.log");

    BQRuntime runtime = app
            .app("--config=src/test/resources/io/bootique/bom/logback/test-debug.yml").createRuntime();
    CommandOutcome outcome = runtime.run();

    // stopping runtime to ensure the logs are flushed before we start making assertions...
    runtime.shutdown();

    assertEquals(0, outcome.getExitCode());

    assertTrue(logFile.isFile());

    String logfileContents = Files.lines(logFile.toPath()).collect(joining("\n"));
    assertTrue(logfileContents.contains("i.b.b.l.LogbackTestCommand: logback-test-debug"));
    assertTrue(logfileContents.contains("i.b.b.l.LogbackTestCommand: logback-test-info"));
    assertTrue(logfileContents.contains("i.b.b.l.LogbackTestCommand: logback-test-warn"));
    assertTrue(logfileContents.contains("i.b.b.l.LogbackTestCommand: logback-test-error"));
}
 
开发者ID:bootique,项目名称:bootique-bom,代码行数:22,代码来源:LogbackAppIT.java

示例3: testRun_Warn

import io.bootique.BQRuntime; //导入方法依赖的package包/类
@Test
public void testRun_Warn() throws IOException {
    File logFile = prepareLogFile("target/logback/testRun_Warn.log");

    BQRuntime runtime = app.app("--config=src/test/resources/io/bootique/bom/logback/test-warn.yml")
            .createRuntime();
    CommandOutcome outcome = runtime.run();

    // stopping runtime to ensure the logs are flushed before we start making assertions...
    runtime.shutdown();

    assertEquals(0, outcome.getExitCode());

    assertTrue(logFile.isFile());

    String logfileContents = Files.lines(logFile.toPath()).collect(joining("\n"));
    assertFalse(logfileContents.contains("i.b.b.l.LogbackTestCommand: logback-test-debug"));
    assertFalse(logfileContents.contains("i.b.b.l.LogbackTestCommand: logback-test-info"));
    assertTrue("Logfile contents: " + logfileContents,
            logfileContents.contains("i.b.b.l.LogbackTestCommand: logback-test-warn"));
    assertTrue(logfileContents.contains("i.b.b.l.LogbackTestCommand: logback-test-error"));
}
 
开发者ID:bootique,项目名称:bootique-bom,代码行数:23,代码来源:LogbackAppIT.java

示例4: testContributeFilters_InitDestroy

import io.bootique.BQRuntime; //导入方法依赖的package包/类
@Test
public void testContributeFilters_InitDestroy() {

    MappedFilter mf1 = new MappedFilter(mockFilter1, Collections.singleton("/a/*"), 10);
    MappedFilter mf2 = new MappedFilter(mockFilter2, Collections.singleton("/a/*"), 0);
    MappedFilter mf3 = new MappedFilter(mockFilter3, Collections.singleton("/a/*"), 5);

    BQRuntime runtime = startApp(b -> JettyModule.extend(b)
            .addMappedFilter(mf1)
            .addMappedFilter(mf2)
            .addMappedFilter(mf3));

    Arrays.asList(mockFilter1, mockFilter2, mockFilter3).forEach(f -> {
        try {
            verify(f).init(any());
        } catch (Exception e) {
            fail("init failed");
        }
    });

    runtime.shutdown();
    Arrays.asList(mockFilter1, mockFilter2, mockFilter3).forEach(f -> verify(f).destroy());
}
 
开发者ID:bootique,项目名称:bootique-jetty,代码行数:24,代码来源:JettyModuleIT.java

示例5: testContributeMappedServlets

import io.bootique.BQRuntime; //导入方法依赖的package包/类
@Test
public void testContributeMappedServlets() throws Exception {

    MappedServlet mappedServlet1 = new MappedServlet(mockServlet1, new HashSet<>(Arrays.asList("/a/*", "/b/*")));
    MappedServlet mappedServlet2 = new MappedServlet(mockServlet2, new HashSet<>(Arrays.asList("/c/*")));

    BQRuntime runtime = startApp(b ->
            JettyModule.extend(b).addMappedServlet(mappedServlet1).addMappedServlet(mappedServlet2));

    verify(mockServlet1).init(any());
    verify(mockServlet2).init(any());

    WebTarget base = ClientBuilder.newClient().target("http://localhost:8080");

    Response r1 = base.path("/a").request().get();
    assertEquals(Status.OK.getStatusCode(), r1.getStatus());

    Response r2 = base.path("/b").request().get();
    assertEquals(Status.OK.getStatusCode(), r2.getStatus());

    Response r3 = base.path("/c").request().get();
    assertEquals(Status.OK.getStatusCode(), r3.getStatus());

    Response r4 = base.path("/d").request().get();
    assertEquals(Status.NOT_FOUND.getStatusCode(), r4.getStatus());

    verify(mockServlet1, times(2)).service(any(), any());
    verify(mockServlet2).service(any(), any());

    runtime.shutdown();
    verify(mockServlet1).destroy();
    verify(mockServlet2).destroy();
}
 
开发者ID:bootique,项目名称:bootique-jetty,代码行数:34,代码来源:JettyModuleIT.java

示例6: testContributeListeners_ServletContextListener

import io.bootique.BQRuntime; //导入方法依赖的package包/类
@Test
public void testContributeListeners_ServletContextListener() {

    ServletContextListener scListener = mock(ServletContextListener.class);

    BQRuntime runtime = startApp(b -> JettyModule.extend(b).addListener(scListener));

    verify(scListener).contextInitialized(any());
    verify(scListener, times(0)).contextDestroyed(any());

    runtime.shutdown();
    verify(scListener).contextInitialized(any());
    verify(scListener).contextDestroyed(any());
}
 
开发者ID:bootique,项目名称:bootique-jetty,代码行数:15,代码来源:JettyModuleIT.java

示例7: testForName_ListenerLifecycle

import io.bootique.BQRuntime; //导入方法依赖的package包/类
@Test
public void testForName_ListenerLifecycle() {

    TestListener listener = new TestListener();

    BQRuntime runtime = testFactory.app("-c", "classpath:DataSourceFactoryIT_2ds.yml")
            .autoLoadModules()
            .module(b -> JdbcModule
                    .extend(b)
                    .addFactoryType(Factory1.class)
                    .addDataSourceListener(listener))
            .createRuntime();


    listener.assertEmpty();
    DataSource ds1 = runtime.getInstance(DataSourceFactory.class).forName("ds1");
    listener.assertDSStartup("jdbc:dummy1", ds1, 1);

    DataSource ds2 = runtime.getInstance(DataSourceFactory.class).forName("ds2");
    listener.assertDSStartup("jdbc:dummy2", ds2, 2);

    runtime.getInstance(DataSourceFactory.class).forName("ds2");
    listener.assertDSStartup("jdbc:dummy2", ds2, 2);

    runtime.shutdown();
    listener.assertShutdown();
}
 
开发者ID:bootique,项目名称:bootique-jdbc,代码行数:28,代码来源:DataSourceFactoryIT.java

示例8: testHeartbeat

import io.bootique.BQRuntime; //导入方法依赖的package包/类
@Test
public void testHeartbeat() throws InterruptedException {

    TestListener listener = new TestListener();

    BQRuntime runtime = testFactory.app("-c", "classpath:HealthCheckModuleHeartbeatIT.yml")
            .autoLoadModules()
            .module(b -> HealthCheckModule.extend(b)
                    .addHealthCheck("hc1", success)
                    .addHealthCheck("ignored", failure)
                    .addHeartbeatListener(listener))
            .createRuntime();

    threadTester.assertNoHeartbeat();

    Heartbeat hb = runtime.getInstance(Heartbeat.class);

    Thread.sleep(100);

    // not started yet...
    threadTester.assertNoHeartbeat();

    // start..
    hb.start();
    Thread.sleep(100);
    threadTester.assertHasHeartbeat();

    // we can't reliably predict the exact number of invocations at any given moment in the test, but we can
    // check that the heart is beating...

    int c1 = listener.counter;

    Thread.sleep(100);
    int c2 = listener.counter;
    assertTrue(c1 < c2);

    Thread.sleep(100);
    int c3 = listener.counter;
    assertTrue(c2 < c3);

    threadTester.assertPoolSize(2);

    runtime.shutdown();
    threadTester.assertNoHeartbeat();
}
 
开发者ID:bootique,项目名称:bootique-metrics,代码行数:46,代码来源:HeartbeatIT.java


注:本文中的io.bootique.BQRuntime.shutdown方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。