use of org.webpieces.webserver.api.ServerConfig in project webpieces by deanhiller.
the class YourCompanyServer method main.
public static void main(Function<ServerConfig, YourCompanyServer> yourServer) {
try {
String version = System.getProperty("java.version");
log.info("Starting Production Server under java version=" + version);
ServerConfig config = new ServerConfig(true);
YourCompanyServer server2 = yourServer.apply(config);
server2.start();
synchronized (YourCompanyServer.class) {
// wait forever so server doesn't shut down..
YourCompanyServer.class.wait();
}
} catch (Throwable e) {
log.error("Failed to startup. exiting jvm", e);
// should not be needed BUT some 3rd party libraries start non-daemon threads :(
System.exit(1);
}
}
use of org.webpieces.webserver.api.ServerConfig in project webpieces by deanhiller.
the class TestLesson2Html method setUp.
@Before
public void setUp() throws InterruptedException, ClassNotFoundException, ExecutionException, TimeoutException {
log.info("Setting up test");
Asserts.assertWasCompiledWithParamNames("test");
// clear in-memory database
jdbc.dropAllTablesFromDatabase();
metrics = new SimpleMeterRegistry();
boolean isRemote = false;
// you may want to create this server ONCE in a static method BUT if you do, also remember to clear out all your
// mocks after every test AND you can no longer run single threaded(tradeoffs, tradeoffs)
// This is however pretty fast to do in many systems...
Server webserver = new Server(getOverrides(metrics), new AppOverridesModule(), new ServerConfig(JavaCache.getCacheLocation()), args);
webserver.start();
http11Socket = connectHttp(webserver.getUnderlyingHttpChannel().getLocalAddress());
}
use of org.webpieces.webserver.api.ServerConfig in project webpieces by deanhiller.
the class TestLesson4BasicStart method testBasicProdStartup.
// This exercises full startup with no mocking in place whatsoever BUT as you add remote systems to
// talk to, you will need to change this test and pass in appOverridesModule to override those
// pieces. In this test, we literally bind a port. We only do this in one or two tests just to
// ensure full server basic functionality is working. All other tests create a server and pass
// in http requests directly. This test can use http client to send requests in which exercises
// our http parser and other pieces (which sometimes can catch bugs when you upgrade webpieces
// so in some cases, this can be valuable)
@Test
public void testBasicProdStartup() throws InterruptedException, IOException, ClassNotFoundException, ExecutionException, TimeoutException {
Asserts.assertWasCompiledWithParamNames("test");
// clear in-memory database
jdbc.dropAllTablesFromDatabase();
// SimpleMeterRegistry metrics = new SimpleMeterRegistry();
// really just making sure we don't throw an exception...which catches quite a few mistakes
Server server = new Server(null, null, new ServerConfig(JavaCache.getCacheLocation()), args);
// In this case, we bind a port
server.start();
System.out.println("bound port=" + server.getUnderlyingHttpChannel().getLocalAddress());
// we should depend on http client and send a request in to ensure operation here...
server.stop();
// ALSO, it is completely reasonable to create a brand new instance(ie. avoid statics and avoid
// non-guice singletons). A guice singleton is only a singleton within the scope of a server
// while a java singleton....well, pretty much sucks. Google "Singletons are evil".
Server server2 = new Server(null, null, new ServerConfig(JavaCache.getCacheLocation()), args);
// In this case, we bind a port
server2.start();
System.out.println("bound port=" + server.getUnderlyingHttpChannel().getLocalAddress());
// we should depend on http client and send a request in to ensure operation here...
server2.stop();
}
use of org.webpieces.webserver.api.ServerConfig in project webpieces by deanhiller.
the class TestLesson6RouteValidation method testBasicProdStartup.
// This test you should always keep to run during the gradle build. It can only be run after the
// gradle plugin html template compiler is run as it uses a file that is generated to validate all the
// routeIds in the html files.
@Test
public void testBasicProdStartup() throws InterruptedException, IOException, ClassNotFoundException {
Asserts.assertWasCompiledWithParamNames("test");
String property = System.getProperty("gradle.running");
if (property == null || !"true".equals(property))
// don't run test except in gradle build
return;
ServerConfig serverConfig = new ServerConfig(JavaCache.getCacheLocation());
serverConfig.setValidateRouteIdsOnStartup(true);
// really just making sure we don't throw an exception...which catches quite a few mistakes
Server server = new Server(null, null, serverConfig, args);
// Start server to force validation
server.start();
}
use of org.webpieces.webserver.api.ServerConfig in project webpieces by deanhiller.
the class TestLesson8JsonHttp2 method setUp.
@Before
public void setUp() {
log.info("Setting up test");
// This line is not really needed but ensures you do not run a test without param names compiled in(which will fail).
Asserts.assertWasCompiledWithParamNames("test");
metrics = new SimpleMeterRegistry();
// you may want to create this server ONCE in a static method BUT if you do, also remember to clear out all your
// mocks after every test AND you can no longer run single threaded(tradeoffs, tradeoffs)
// This is however pretty fast to do in many systems...
Server webserver = new Server(getOverrides(metrics), new AppOverridesModule(), new ServerConfig(JavaCache.getCacheLocation()), args);
webserver.start();
http2Socket = connectHttp(webserver.getUnderlyingHttpChannel().getLocalAddress());
}
Aggregations