-
Notifications
You must be signed in to change notification settings - Fork 367
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
35 changed files
with
327 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
buildscript { | ||
repositories { | ||
mavenLocal() | ||
mavenCentral() | ||
maven { url "http://repo.spring.io/release" } | ||
maven { url "http://repo.spring.io/snapshot" } | ||
maven { url "https://repo.spring.io/libs-snapshot" } | ||
maven { url "http://repo.spring.io/milestone" } | ||
maven { url "https://repo.spring.io/libs-milestone" } | ||
} | ||
|
||
dependencies { | ||
classpath boot.springBootPlugin | ||
} | ||
} | ||
|
||
apply plugin: 'org.springframework.boot' | ||
|
||
dependencies { | ||
compile boot.starterWebflux, boot.starterWeb | ||
testCompile boot.starterTest, testing.junit5Engine, testing.junit5Runner | ||
} | ||
|
||
jar { | ||
manifest { | ||
attributes("Created-By": "Iuliana Cosmina", | ||
"Specification-Title": "Pro Spring 5", | ||
"Class-Path": configurations.compile.collect { it.getName() }.join(' ')) | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
chapter18/boot-tests/src/main/java/com/apress/prospring5/ch18/Application.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,28 @@ | ||
package com.apress.prospring5.ch18; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.boot.builder.SpringApplicationBuilder; | ||
import org.springframework.context.ConfigurableApplicationContext; | ||
|
||
|
||
/** | ||
* Created by iuliana.cosmina on 8/6/17. | ||
*/ | ||
@SpringBootApplication | ||
public class Application { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(Application.class); | ||
|
||
public static void main(String[] args) throws Exception { | ||
ConfigurableApplicationContext ctx = new SpringApplicationBuilder(Application.class) | ||
.run(args); | ||
assert (ctx != null); | ||
logger.info("Application started..."); | ||
|
||
System.in.read(); | ||
ctx.close(); | ||
} | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
chapter18/boot-tests/src/main/java/com/apress/prospring5/ch18/FluxGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,16 @@ | ||
package com.apress.prospring5.ch18; | ||
|
||
import org.springframework.stereotype.Component; | ||
import reactor.core.publisher.Flux; | ||
|
||
/** | ||
* Created by iuliana.cosmina on 8/6/17. | ||
*/ | ||
@Component | ||
public class FluxGenerator { | ||
|
||
public Flux<String> generate(String... args){ | ||
return Flux.just(args); | ||
} | ||
|
||
} |
27 changes: 16 additions & 11 deletions
27
chapter18/boot-tests/src/test/java/com/apress/prospring5/ch18/test/IntegrationOneTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,42 @@ | ||
package com.apress.prospring5.ch18.test; | ||
|
||
import com.apress.prospring5.ch18.entities.Singer; | ||
import com.apress.prospring5.ch18.FluxGenerator; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.context.junit4.SpringRunner; | ||
import reactor.core.publisher.Flux; | ||
import reactor.util.function.Tuple2; | ||
|
||
import java.time.Duration; | ||
|
||
/** | ||
* Created by iuliana.cosmina on 8/6/17. | ||
*/ | ||
@RunWith(SpringRunner.class) | ||
@SpringBootTest | ||
public class IntegrationOneTest { | ||
|
||
private final Logger logger = LoggerFactory.getLogger(IntegrationOneTest.class); | ||
@Autowired FluxGenerator fluxGenerator; | ||
|
||
@Test | ||
public void test1One() { | ||
Flux<String> numbers = Flux.just("1", "2", "3"); | ||
Flux<Long> periodFlux = Flux.interval(Duration.ofSeconds(2)); | ||
Flux.zip(numbers, periodFlux).map(Tuple2::getT1).doOnNext(logger::info); | ||
fluxGenerator.generate("1", "2", "3").collectList().block().forEach(s -> | ||
executeSlow(2000, s) | ||
); | ||
} | ||
|
||
@Test | ||
public void test2One() { | ||
Flux<String> numbers = Flux.just("11", "22", "33"); | ||
Flux<Long> periodFlux = Flux.interval(Duration.ofSeconds(2)); | ||
Flux.zip(numbers, periodFlux).map(Tuple2::getT1).doOnNext(logger::info); | ||
fluxGenerator.generate("11", "22", "33").collectList().block().forEach(s -> executeSlow(1000, s)); | ||
} | ||
|
||
private void executeSlow(int duration, String s) { | ||
try { | ||
Thread.sleep(duration); | ||
logger.info(s); | ||
} catch (InterruptedException e) { | ||
} | ||
} | ||
} | ||
|
Oops, something went wrong.