18
18
19
19
import static com .google .common .truth .Truth .assertThat ;
20
20
import static org .junit .Assert .assertEquals ;
21
+ import static org .junit .Assert .assertFalse ;
21
22
import static org .junit .Assert .assertNotEquals ;
22
23
import static org .junit .Assert .assertNotNull ;
23
24
import static org .junit .Assert .assertNull ;
24
25
import static org .junit .Assert .assertThrows ;
25
26
import static org .junit .Assert .assertTrue ;
26
27
28
+ import com .google .cloud .spanner .Options .RpcOrderBy ;
27
29
import com .google .cloud .spanner .Options .RpcPriority ;
28
30
import com .google .spanner .v1 .DirectedReadOptions ;
29
31
import com .google .spanner .v1 .DirectedReadOptions .IncludeReplicas ;
30
32
import com .google .spanner .v1 .DirectedReadOptions .ReplicaSelection ;
33
+ import com .google .spanner .v1 .ReadRequest .OrderBy ;
31
34
import com .google .spanner .v1 .RequestOptions .Priority ;
32
35
import org .junit .Test ;
33
36
import org .junit .runner .RunWith ;
@@ -79,14 +82,16 @@ public void allOptionsPresent() {
79
82
Options .limit (10 ),
80
83
Options .prefetchChunks (1 ),
81
84
Options .dataBoostEnabled (true ),
82
- Options .directedRead (DIRECTED_READ_OPTIONS ));
85
+ Options .directedRead (DIRECTED_READ_OPTIONS ),
86
+ Options .orderBy (RpcOrderBy .NO_ORDER ));
83
87
assertThat (options .hasLimit ()).isTrue ();
84
88
assertThat (options .limit ()).isEqualTo (10 );
85
89
assertThat (options .hasPrefetchChunks ()).isTrue ();
86
90
assertThat (options .prefetchChunks ()).isEqualTo (1 );
87
91
assertThat (options .hasDataBoostEnabled ()).isTrue ();
88
92
assertTrue (options .dataBoostEnabled ());
89
93
assertTrue (options .hasDirectedReadOptions ());
94
+ assertTrue (options .hasOrderBy ());
90
95
assertEquals (DIRECTED_READ_OPTIONS , options .directedReadOptions ());
91
96
}
92
97
@@ -101,6 +106,7 @@ public void allOptionsAbsent() {
101
106
assertThat (options .hasTag ()).isFalse ();
102
107
assertThat (options .hasDataBoostEnabled ()).isFalse ();
103
108
assertThat (options .hasDirectedReadOptions ()).isFalse ();
109
+ assertThat (options .hasOrderBy ()).isFalse ();
104
110
assertNull (options .withExcludeTxnFromChangeStreams ());
105
111
assertThat (options .toString ()).isEqualTo ("" );
106
112
assertThat (options .equals (options )).isTrue ();
@@ -182,7 +188,8 @@ public void readOptionsTest() {
182
188
Options .limit (limit ),
183
189
Options .tag (tag ),
184
190
Options .dataBoostEnabled (true ),
185
- Options .directedRead (DIRECTED_READ_OPTIONS ));
191
+ Options .directedRead (DIRECTED_READ_OPTIONS ),
192
+ Options .orderBy (RpcOrderBy .NO_ORDER ));
186
193
187
194
assertThat (options .toString ())
188
195
.isEqualTo (
@@ -197,10 +204,14 @@ public void readOptionsTest() {
197
204
+ " "
198
205
+ "directedReadOptions: "
199
206
+ DIRECTED_READ_OPTIONS
207
+ + " "
208
+ + "orderBy: "
209
+ + RpcOrderBy .NO_ORDER
200
210
+ " " );
201
211
assertThat (options .tag ()).isEqualTo (tag );
202
212
assertEquals (dataBoost , options .dataBoostEnabled ());
203
213
assertEquals (DIRECTED_READ_OPTIONS , options .directedReadOptions ());
214
+ assertEquals (OrderBy .ORDER_BY_NO_ORDER , options .orderBy ());
204
215
}
205
216
206
217
@ Test
@@ -354,6 +365,24 @@ public void testTransactionOptionsPriority() {
354
365
assertEquals ("priority: " + priority + " " , options .toString ());
355
366
}
356
367
368
+ @ Test
369
+ public void testReadOptionsOrderBy () {
370
+ RpcOrderBy orderBy = RpcOrderBy .NO_ORDER ;
371
+ Options options = Options .fromReadOptions (Options .orderBy (orderBy ));
372
+ assertTrue (options .hasOrderBy ());
373
+ assertEquals ("orderBy: " + orderBy + " " , options .toString ());
374
+ }
375
+
376
+ @ Test
377
+ public void testReadOptionsWithOrderByEquality () {
378
+ Options optionsWithNoOrderBy1 = Options .fromReadOptions (Options .orderBy (RpcOrderBy .NO_ORDER ));
379
+ Options optionsWithNoOrderBy2 = Options .fromReadOptions (Options .orderBy (RpcOrderBy .NO_ORDER ));
380
+ assertTrue (optionsWithNoOrderBy1 .equals (optionsWithNoOrderBy2 ));
381
+
382
+ Options optionsWithPkOrder = Options .fromReadOptions (Options .orderBy (RpcOrderBy .PRIMARY_KEY ));
383
+ assertFalse (optionsWithNoOrderBy1 .equals (optionsWithPkOrder ));
384
+ }
385
+
357
386
@ Test
358
387
public void testQueryOptionsPriority () {
359
388
RpcPriority priority = RpcPriority .MEDIUM ;
0 commit comments