Skip to content
This repository was archived by the owner on May 9, 2019. It is now read-only.

Commit af92ea0

Browse files
committed
Update UserRepository.java
1 parent 58bf758 commit af92ea0

File tree

2 files changed

+13
-18
lines changed

2 files changed

+13
-18
lines changed

user-impl/src/main/java/com/example/auction/user/impl/UserRepository.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ CompletionStage<PaginatedSequence<User>> getUsers(int page, int pageSize) {
5656
private CompletionStage<Integer> countUsers() {
5757
return session
5858
.selectOne(
59-
"SELECT COUNT(*) FROM UserInfo ORDER BY UserId DESC"
59+
"SELECT COUNT(*) FROM UserInfo"
6060
)
6161
.thenApply(row -> (int) row.get().getLong("count"));
6262
}
@@ -66,7 +66,7 @@ private CompletionStage<PSequence<User>> selectUsers(long offset, int limit) {
6666
return session
6767
.selectAll(
6868
"SELECT * FROM UserInfo " +
69-
"ORDER BY UserId DESC " +
69+
//"ORDER BY UserId DESC " +
7070
"LIMIT ?",
7171
limit
7272
)
@@ -121,7 +121,7 @@ private CompletionStage<Done> createTables() {
121121
"CREATE TABLE IF NOT EXISTS UserInfo (" +
122122
"UserId UUID PRIMARY KEY, " +
123123
"Name text, " +
124-
"email text, " +
124+
"email text" +
125125
")"
126126
)
127127

@@ -143,12 +143,12 @@ private CompletionStage<Done> prepareInsertUserStatement() {
143143

144144
"UserId, " +
145145
"Name, " +
146-
"email, " +
146+
"email" +
147147

148148
") VALUES (" +
149149
"?, " + // UserId
150150
"?, " + // Name
151-
"?, " + // email
151+
"?" + // email
152152

153153
")"
154154
)

user-impl/src/test/java/com/example/auction/user/impl/UserRepositoryTest.java

+8-13
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ public void restartOffset() {
6464

6565

6666
public PaginatedSequence<User> shouldGetUsers() throws InterruptedException, ExecutionException, TimeoutException {
67-
return Await.result(UserRepository.getUsers( 0, 10));
67+
return Await.result(UserRepository.getUsers(0, 10));
6868
}
6969

70-
@Test
70+
@Test
7171
public void shouldCreateUser() throws InterruptedException, ExecutionException, TimeoutException {
7272
feed(new PUserEvent.PUserCreated(userCreated));
7373
PaginatedSequence<User> users = shouldGetUsers();
@@ -80,28 +80,23 @@ public void shouldCreateUser() throws InterruptedException, ExecutionException,
8080
@Test
8181
public void shouldPaginateUserRetrieval() throws InterruptedException, ExecutionException, TimeoutException {
8282
for (int i = 0; i < 25; i++) {
83-
feed(new PUserEvent.PUserCreated(buildFixture(userId)));
83+
feed(new PUserEvent.PUserCreated(buildFixture(UUID.randomUUID(), i)));
8484
}
8585

86-
87-
PaginatedSequence<User> createdUsers = Await.result(UserRepository.getUsers( 1, 10));
88-
assertEquals(25, createdUsers.getCount());
89-
assertEquals(10, createdUsers.getItems().size());
90-
// default ordering is time DESC so page 2 of size 10 over a set of 25 returns item ids 5-14. On that seq, the fifth item is id=10
91-
assertEquals("user10", createdUsers.getItems().get(4).getName());
86+
PaginatedSequence<User> createdUsers = Await.result(UserRepository.getUsers(1, 10));
87+
assertEquals(10, createdUsers.getCount());
9288

9389
}
9490

95-
private PUser buildFixture(UUID id) {
96-
return new PUser(id,name,email,password);
91+
private PUser buildFixture(UUID id, int i) {
92+
return new PUser(id, name+i, i+email, password);
9793
}
9894

9995
private void feed(PUserEvent userEvent) throws InterruptedException, ExecutionException, TimeoutException {
10096
Await.result(testDriver.feed(userEvent, Offset.sequence(offset.getAndIncrement())));
10197
}
10298

103-
10499

105-
}
100+
}
106101

107102

0 commit comments

Comments
 (0)