-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathHomePageControllerTest.java
More file actions
62 lines (54 loc) · 2.65 KB
/
HomePageControllerTest.java
File metadata and controls
62 lines (54 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package examples.bloghomepagebuilder.controller;
import com.google.common.base.Stopwatch;
import examples.bloghomepagebuilder.builders.*;
import examples.bloghomepagebuilder.data.HomePageRequest;
import examples.bloghomepagebuilder.data.HomePageResponse;
import io.appform.databuilderframework.engine.*;
import io.appform.databuilderframework.model.DataFlow;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.junit.Assert;
import org.junit.Test;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
@Slf4j
public class HomePageControllerTest {
//private final DataFlowExecutor executor = new MultiThreadedDataFlowExecutor(Executors.newFixedThreadPool(10));
private final DataFlow homePageDataFlow;
public HomePageControllerTest() throws DataBuilderFrameworkException {
homePageDataFlow = new DataFlowBuilder()
.withDataBuilder(new ApiAuthChecker())
.withDataBuilder(new PostListBuilder())
.withDataBuilder(new BlogPostSource())
.withDataBuilder(new GetFollowers())
.withDataBuilder(new LatestBlogSelector())
.withDataBuilder(new RecommendationBuilder())
.withDataBuilder(new UserDataExpander())
.withDataBuilder(new HomePageBuilder())
.withTargetData(HomePageResponse.class)
.build();
log.info("Dataflow: {}", homePageDataFlow);
}
@Test
public void testHomePage() throws Exception {
runHomePageTest(new SimpleDataFlowExecutor());
}
@Test
public void testHomePageMT() throws Exception {
runHomePageTest(new MultiThreadedDataFlowExecutor(Executors.newFixedThreadPool(10)));
}
@Test
public void testHomePageMTOpt() throws Exception {
runHomePageTest(new OptimizedMultiThreadedDataFlowExecutor(Executors.newFixedThreadPool(10)));
}
private void runHomePageTest(DataFlowExecutor executor) throws Exception {
val request = new HomePageRequest("2321312312", "2323454", "Blah".getBytes());
val stopwatch = Stopwatch.createStarted();
for(long i = 0; i < 10000_000; i++) {
HomePageResponse response = executor.run(homePageDataFlow, request).get(HomePageResponse.class);
Assert.assertNotNull(response);
//System.out.println(new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(response));
}
log.info("Time taken: {}", stopwatch.elapsed(TimeUnit.MILLISECONDS));
}
}