Search in sources :

Example 1 with ServerConfig

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);
    }
}
Also used : ServerConfig(org.webpieces.webserver.api.ServerConfig)

Example 2 with ServerConfig

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());
}
Also used : ServerConfig(org.webpieces.webserver.api.ServerConfig) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) Before(org.junit.Before)

Example 3 with ServerConfig

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();
}
Also used : ServerConfig(org.webpieces.webserver.api.ServerConfig) Test(org.junit.Test)

Example 4 with ServerConfig

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();
}
Also used : ServerConfig(org.webpieces.webserver.api.ServerConfig) Test(org.junit.Test)

Example 5 with ServerConfig

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());
}
Also used : ServerConfig(org.webpieces.webserver.api.ServerConfig) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) Before(org.junit.Before)

Aggregations

ServerConfig (org.webpieces.webserver.api.ServerConfig)9 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)6 Before (org.junit.Before)5 Test (org.junit.Test)2 InetSocketAddress (java.net.InetSocketAddress)1 FirefoxDriver (org.openqa.selenium.firefox.FirefoxDriver)1 HttpSocket (org.webpieces.httpclient11.api.HttpSocket)1 OverridesForTestRealServer (org.webpieces.webserver.test.OverridesForTestRealServer)1 WebBrowserSimulator (org.webpieces.webserver.test.WebBrowserSimulator)1 Server (webpiecesxxxxxpackage.Server)1