11
11
import org .junit .jupiter .api .Test ;
12
12
import org .testcontainers .shaded .org .apache .commons .lang3 .StringUtils ;
13
13
import org .vss .exception .ConflictException ;
14
+ import org .vss .exception .NoSuchKeyException ;
14
15
15
16
import static org .hamcrest .MatcherAssert .assertThat ;
16
17
import static org .hamcrest .Matchers .is ;
19
20
import static org .junit .jupiter .api .Assertions .assertDoesNotThrow ;
20
21
import static org .junit .jupiter .api .Assertions .assertFalse ;
21
22
import static org .junit .jupiter .api .Assertions .assertThrows ;
22
- import static org .junit .jupiter .api .Assertions .assertTrue ;
23
23
24
24
public abstract class AbstractKVStoreIntegrationTest {
25
25
@@ -153,25 +153,25 @@ void putAndDeleteShouldSucceedAsAtomicTransaction() {
153
153
assertThat (response .getVersion (), is (1L ));
154
154
assertThat (response .getValue ().toStringUtf8 (), is ("k2v1" ));
155
155
156
- assertTrue ( getObject ("k1" ). getValue (). isEmpty ( ));
156
+ assertThrows ( NoSuchKeyException . class , () -> getObject ("k1" ));
157
157
158
158
// Delete fails (and hence put as well) due to mismatched version for the deleted item.
159
159
assertThrows (ConflictException .class , () -> putAndDeleteObjects (null , List .of (kv ("k3" , "k3v1" , 0 )), List .of (kv ("k2" , "" , 3 ))));
160
160
161
- assertTrue ( getObject ("k3" ). getValue (). isEmpty ( ));
162
- assertFalse ( getObject ("k2" ). getValue (). isEmpty ( ));
161
+ assertThrows ( NoSuchKeyException . class , () -> getObject ("k3" ));
162
+ assertDoesNotThrow (() -> getObject ("k2" ));
163
163
164
164
// Put fails (and hence delete as well) due to mismatched version for the put item.
165
165
assertThrows (ConflictException .class , () -> putAndDeleteObjects (null , List .of (kv ("k3" , "k3v1" , 1 )), List .of (kv ("k2" , "" , 1 ))));
166
166
167
- assertTrue ( getObject ("k3" ). getValue (). isEmpty ( ));
168
- assertFalse ( getObject ("k2" ). getValue (). isEmpty ( ));
167
+ assertThrows ( NoSuchKeyException . class , () -> getObject ("k3" ));
168
+ assertDoesNotThrow (() -> getObject ("k2" ));
169
169
170
170
// Put and delete both fail due to mismatched global version.
171
171
assertThrows (ConflictException .class , () -> putAndDeleteObjects (2L , List .of (kv ("k3" , "k3v1" , 0 )), List .of (kv ("k2" , "" , 1 ))));
172
172
173
- assertTrue ( getObject ("k3" ). getValue (). isEmpty ( ));
174
- assertFalse ( getObject ("k2" ). getValue (). isEmpty ( ));
173
+ assertThrows ( NoSuchKeyException . class , () -> getObject ("k3" ));
174
+ assertDoesNotThrow (() -> getObject ("k2" ));
175
175
176
176
assertThat (getObject (KVStore .GLOBAL_VERSION_KEY ).getVersion (), is (0L ));
177
177
}
@@ -182,18 +182,14 @@ void deleteShouldSucceedWhenItemExists() {
182
182
// Conditional Delete
183
183
assertDoesNotThrow (() -> deleteObject (kv ("k1" , "" , 1 )));
184
184
185
- KeyValue response = getObject ("k1" );
186
- assertThat (response .getKey (), is ("k1" ));
187
- assertTrue (response .getValue ().isEmpty ());
185
+ assertThrows (NoSuchKeyException .class , () -> getObject ("k1" ));
188
186
189
187
assertDoesNotThrow (() -> putObjects (null , List .of (kv ("k1" , "k1v1" , 0 ))));
190
188
assertDoesNotThrow (() -> putObjects (null , List .of (kv ("k1" , "k1v2" , 1 ))));
191
189
// NonConditional Delete
192
190
assertDoesNotThrow (() -> deleteObject (kv ("k1" , "" , -1 )));
193
191
194
- response = getObject ("k1" );
195
- assertThat (response .getKey (), is ("k1" ));
196
- assertTrue (response .getValue ().isEmpty ());
192
+ assertThrows (NoSuchKeyException .class , () -> getObject ("k1" ));
197
193
}
198
194
199
195
@ Test
@@ -207,18 +203,12 @@ void deleteShouldBeIdempotent() {
207
203
assertDoesNotThrow (() -> deleteObject (kv ("k1" , "" , 1 )));
208
204
assertDoesNotThrow (() -> deleteObject (kv ("k1" , "" , 1 )));
209
205
210
- KeyValue response = getObject ("k1" );
211
- assertThat (response .getKey (), is ("k1" ));
212
- assertTrue (response .getValue ().isEmpty ());
206
+ assertThrows (NoSuchKeyException .class , () -> getObject ("k1" ));
213
207
}
214
208
215
209
@ Test
216
- void getShouldReturnEmptyResponseWhenKeyDoesNotExist () {
217
- KeyValue response = getObject ("non_existent_key" );
218
-
219
- assertThat (response .getKey (), is ("non_existent_key" ));
220
- assertTrue (response .getValue ().isEmpty ());
221
- assertThat (response .getVersion (), is (0L ));
210
+ void getShouldThrowNoSuchKeyExceptionWhenKeyDoesNotExist () {
211
+ assertThrows (NoSuchKeyException .class , () -> getObject ("non_existent_key" ));
222
212
}
223
213
224
214
@ Test
0 commit comments