本文整理汇总了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();
}
}
}
示例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"));
}
示例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"));
}
示例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());
}
示例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();
}
示例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());
}
示例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();
}
示例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();
}