Skip to content

Commit 28849f9

Browse files
committed
optimize Example
1 parent 2a98a3b commit 28849f9

File tree

5 files changed

+30
-12
lines changed

5 files changed

+30
-12
lines changed

spring-boot-data-aggregator-example/src/main/java/io/github/lvyahui8/spring/example/aggregate/UserAggregate.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ public User userWithPosts(
2222
return user;
2323
}
2424

25-
@DataProvider(id="userFullData")
26-
public User userFullData(@DataConsumer(id = "user") User user,
27-
@DataConsumer(id = "posts") List<Post> posts,
28-
@DataConsumer(id = "followers") List<User> followers) {
25+
@DataProvider("userFullData")
26+
public User userFullData(@DataConsumer("user") User user,
27+
@DataConsumer("posts") List<Post> posts,
28+
@DataConsumer("followers") List<User> followers) {
2929
user.setFollowers(followers);
3030
user.setPosts(posts);
3131
return user;

spring-boot-data-aggregator-example/src/main/java/io/github/lvyahui8/spring/example/service/impl/FollowServiceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
@Service
1717
public class FollowServiceImpl implements FollowService {
18-
@DataProvider(id = "followers")
18+
@DataProvider("followers")
1919
@Override
2020
public List<User> getFollowers(@InvokeParameter("userId") Long userId) {
2121
try { Thread.sleep(1000L); } catch (InterruptedException e) {}

spring-boot-data-aggregator-example/src/main/java/io/github/lvyahui8/spring/example/service/impl/PostServiceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717
@Service
1818
public class PostServiceImpl implements PostService {
19-
@DataProvider(id = "posts")
19+
@DataProvider("posts")
2020
@Override
2121
public List<Post> getPosts(@InvokeParameter("userId") Long userId) {
2222
Assert.isTrue(userId != null && userId != 0, "userId must be not null and gt 0!");

spring-boot-data-aggregator-example/src/main/java/io/github/lvyahui8/spring/example/service/impl/UserServiceImpl.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package io.github.lvyahui8.spring.example.service.impl;
22

3-
import io.github.lvyahui8.spring.annotation.DataProvider;
4-
import io.github.lvyahui8.spring.annotation.InvokeParameter;
53
import io.github.lvyahui8.spring.annotation.DataProvider;
64
import io.github.lvyahui8.spring.annotation.InvokeParameter;
75
import io.github.lvyahui8.spring.example.model.User;
@@ -15,7 +13,7 @@
1513
@Service
1614
public class UserServiceImpl implements UserService {
1715

18-
@DataProvider(id = "user")
16+
@DataProvider("user")
1917
@Override
2018
public User get(@InvokeParameter("userId") Long id) {
2119
/* */
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
package io.github.lvyahui8.spring.example;
22

33
import io.github.lvyahui8.spring.aggregate.facade.DataBeanAggregateQueryFacade;
4+
import io.github.lvyahui8.spring.autoconfigure.BeanAggregateProperties;
45
import io.github.lvyahui8.spring.example.model.User;
6+
import lombok.extern.slf4j.Slf4j;
57
import org.junit.Test;
68
import org.junit.runner.RunWith;
79
import org.springframework.beans.factory.annotation.Autowired;
810
import org.springframework.boot.test.context.SpringBootTest;
911
import org.springframework.test.context.junit4.SpringRunner;
12+
import org.springframework.util.Assert;
1013

1114
import java.util.Collections;
1215

@@ -16,15 +19,32 @@
1619
*/
1720
@RunWith(SpringRunner.class)
1821
@SpringBootTest
22+
@Slf4j
1923
public class DataBeanAggregateQueryFacadeTest {
2024

2125
@Autowired
2226
private DataBeanAggregateQueryFacade dataBeanAggregateQueryFacade;
2327

28+
@Autowired
29+
private BeanAggregateProperties beanAggregateProperties;
30+
2431
@Test
2532
public void testExceptionProcessing() throws Exception {
26-
User user = dataBeanAggregateQueryFacade.get("userWithPosts",
27-
Collections.singletonMap("userId", 0L), User.class);
28-
System.out.println(user);
33+
boolean success = false;
34+
if(! beanAggregateProperties.isIgnoreException()) {
35+
try {
36+
dataBeanAggregateQueryFacade.get("userWithPosts",
37+
Collections.singletonMap("userId", 0L), User.class);
38+
} catch (Exception e) {
39+
log.info("default settings is SUSPEND, catch an exception: {}",e.getMessage(),e);
40+
success = true;
41+
}
42+
} else {
43+
User user = dataBeanAggregateQueryFacade.get("userWithPosts",
44+
Collections.singletonMap("userId", 0L), User.class);
45+
System.out.println(user);
46+
success = true;
47+
}
48+
Assert.isTrue(success,"exception handle success");
2949
}
3050
}

0 commit comments

Comments
 (0)