Skip to content

Commit

Permalink
Add minimal webapp sample
Browse files Browse the repository at this point in the history
This example is used to experiment about classpath filtering
and benchmarking.

Issue gh-34
  • Loading branch information
sdeleuze committed Jun 14, 2018
1 parent 7b8c376 commit 55ea9fe
Show file tree
Hide file tree
Showing 9 changed files with 132 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ You can have a look to the sample applications:

* https://github.com/spring-projects/spring-fu/tree/master/samples/reactive-webapp[Reactive webapp]
* https://github.com/spring-projects/spring-fu/tree/master/samples/coroutine-webapp[Coroutine webapp]
* https://github.com/spring-projects/spring-fu/tree/master/samples/minimal-webapp[Minimal webapp]

[[functional-configuration]]
== Functional configuration
Expand Down
4 changes: 1 addition & 3 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
dependencies {
api("org.springframework:spring-core")
api("org.springframework:spring-context") {
exclude(module = "spring-aop")
}
api("org.springframework:spring-context")
api("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
api("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.slf4j:slf4j-api:1.7.25")
Expand Down
1 change: 0 additions & 1 deletion modules/webflux/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
dependencies {
api(project(":core"))
api(project(":modules:logging"))
api("org.springframework:spring-webflux")
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package org.springframework.fu.module.webflux

import org.slf4j.LoggerFactory
import org.springframework.beans.factory.NoSuchBeanDefinitionException
import org.springframework.beans.factory.getBeansOfType
import org.springframework.context.ApplicationContext
Expand Down Expand Up @@ -65,7 +64,6 @@ open class WebFluxModule(private val init: WebFluxModule.() -> Unit): AbstractMo
open class WebFluxServerModule(private val init: WebFluxServerModule.() -> Unit,
private val serverModule: WebServerModule): AbstractModule() {

private val logWebflux = LoggerFactory.getLogger(WebFluxModule::class.java)
private val builder = HandlerStrategies.empty()

override fun initialize(context: GenericApplicationContext) {
Expand Down Expand Up @@ -104,7 +102,6 @@ open class WebFluxModule(private val init: WebFluxModule.() -> Unit): AbstractMo
else {
RouterFunction<ServerResponse> { Mono.empty() }
}
logWebflux.info("$router")

RouterFunctions.toWebHandler(router, builder.build())
}
Expand Down
17 changes: 17 additions & 0 deletions samples/minimal-webapp/README.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
= Minimal webapp

This is a Spring Fu example of a minimal webapp with filtered classpath.

Stats are Size of the executable JAR is:


* Tomcat: 866 ms startup, 12.1 MB executable JAR, 3400 classes, 10 MB heap, 0 MB Permgen
* Netty: 1058 ms startup, 12.6 MB executable JAR, 3360 classes, 10 MB heap, 0 MB Permgen
* Undertow: TODO when https://github.com/spring-projects/spring-fu/issues/59 will be fixed
* Jetty: TODO when https://github.com/spring-projects/spring-fu/issues/60 will be fixed

The app could be benchmark with the following command:

`sudo perf stat -e cpu-clock -r10 java -jar -XX:TieredStopAtLevel=1 -noverify -Djava.security.egd=file:/dev/./urandom samples/minimal-webapp/build/libs/minimal-webapp-1.0.0.BUILD-SNAPSHOT-all.jar`


48 changes: 48 additions & 0 deletions samples/minimal-webapp/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import org.jetbrains.kotlin.gradle.dsl.Coroutines

plugins {
application
id ("com.github.johnrengelman.shadow")
}

application {
mainClassName = "org.springframework.fu.sample.minimal.ApplicationKt"
}

dependencies {
implementation(project(":modules:webflux-netty"))
testImplementation(project(":modules:test"))
}

configurations {
all {
exclude(module = "spring-aop")
}
}

tasks.withType<ShadowJar> {
exclude("org/springframework/cglib/**",
"org/springframework/beans/factory/groovy/**",
"org/springframework/beans/factory/xml/**",
"org/springframework/cache",
"org/springframework/context/annotation",
"org/springframework/context/support/*Xml*.class",
"org/springframework/context/support/*Groovy*.class",
"org/springframework/ejb/**",
"org/springframework/instrument/classloading/**",
"org/springframework/jmx/**",
"org/springframework/jndi/**",
"org/springframework/remoting/**",
"org/springframework/scheduling/**",
"org/springframework/scripting/**",
"org/springframework/web/accept/**",
"org/springframework/web/bind/**",
"org/springframework/web/client/**",
"org/springframework/web/context/**",
"org/springframework/web/filter/**",
"org/springframework/web/jsf/**",
"org/springframework/web/method/**",
"org/springframework/web/multipart/**",
"org/springframework/util/xml/**")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.fu.sample.minimal

import org.springframework.fu.application
import org.springframework.fu.module.webflux.netty.netty
import org.springframework.fu.module.webflux.webflux

val app = application {
webflux {
server(netty()) {
routes {
GET("/") {
ok().syncBody("Hello world!")
}
}
}
}
}

fun main(args: Array<String>) = app.run(await = true)
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.springframework.fu.sample.minimal

import org.junit.jupiter.api.AfterAll
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Test
import org.springframework.test.web.reactive.server.*
import org.springframework.test.web.reactive.server.WebTestClient

class IntegrationTests {

private val client = WebTestClient.bindToServer().baseUrl("http://localhost:8080").build()

@BeforeAll
fun beforeAll() {
app.run(profiles = "test")
}

@Test
fun `Request root endpoint`() {
client.get().uri("/").exchange()
.expectStatus().is2xxSuccessful
.expectBody<String>().isEqualTo("Hello world!")
}

@AfterAll
fun afterAll() {
app.stop()
}
}
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ include("bootstraps",
"modules:webflux-netty",
"modules:webflux-tomcat",
"samples:coroutine-webapp",
"samples:minimal-webapp",
"samples:reactive-webapp")

0 comments on commit 55ea9fe

Please sign in to comment.