|
3 | 3 | import java.util.concurrent.CompletableFuture; |
4 | 4 |
|
5 | 5 | import io.codebottle.api.CodeBottle; |
6 | | -import io.codebottle.api.model.Snippet; |
7 | | -import org.junit.Before; |
8 | 6 | import org.junit.Test; |
9 | 7 |
|
10 | 8 | import static java.lang.System.currentTimeMillis; |
| 9 | +import static java.lang.System.out; |
| 10 | +import static org.junit.Assert.assertNotEquals; |
11 | 11 |
|
12 | 12 | public class PerformanceTest { |
13 | 13 | @Test |
14 | 14 | public void requestEverything() { |
15 | | - long start, end; |
16 | | - |
17 | | - System.out.printf("Started requesting everything at %d epoch\n", start = currentTimeMillis()); |
18 | | - |
| 15 | + final long start = currentTimeMillis(); |
| 16 | + |
| 17 | + out.print("Requesting everything..."); |
| 18 | + |
19 | 19 | final CodeBottle codeBottle = CodeBottle.builder().build(); |
20 | 20 |
|
21 | | - codeBottle.requestSnippets().join() |
22 | | - .stream() |
23 | | - .map(Snippet::requestRevisions) |
24 | | - .forEachOrdered(CompletableFuture::join); |
25 | | - |
26 | | - System.out.printf("Finished ingesting everything at %d epoch; took %d milliseconds\n\n", end = currentTimeMillis(), end - start); |
| 21 | + // wait for all loading to finish |
| 22 | + CompletableFuture.allOf(codeBottle.lazyLoading, codeBottle.requestAllRevisions()) |
| 23 | + .join(); |
| 24 | + |
| 25 | + out.print(" OK!\n"); |
27 | 26 |
|
28 | 27 | final int languageCount = codeBottle.getLanguages().size(); |
29 | 28 | final int categoryCount = codeBottle.getCategories().size(); |
30 | 29 | final int snippetCount = codeBottle.getSnippets().size(); |
31 | 30 | final int revisionCount = codeBottle.getSnippetRevisions().size(); |
32 | 31 |
|
33 | | - System.out.printf("Requested:\n\tLanguages:\t%d\n\tCategories:\t%d\n\tSnippets:\t%d\n\tRevisions:\t%d\n", languageCount, categoryCount, snippetCount, revisionCount); |
34 | | - } |
| 32 | + out.print("Checking for cache integrity..."); |
| 33 | + |
| 34 | + assertNotEquals(0, languageCount); |
| 35 | + assertNotEquals(0, categoryCount); |
| 36 | + assertNotEquals(0, snippetCount); |
| 37 | + assertNotEquals(0, revisionCount); |
| 38 | + |
| 39 | + out.print(" OK!\n"); |
| 40 | + |
| 41 | + out.printf("\nCache Summary:\n\tLanguages:\t%d\n\tCategories:\t%d\n\tSnippets:\t%d\n\tRevisions:\t%d", |
| 42 | + languageCount, categoryCount, snippetCount, revisionCount); |
| 43 | + |
| 44 | + out.printf("\n\nTook %d milliseconds.", currentTimeMillis() - start); |
| 45 | + } |
35 | 46 | } |
0 commit comments