@@ -264,19 +264,9 @@ public void getState_TransactionIdForGroupCommitGivenAndParentIdAndChildIdMatch_
264
264
// The IDs used to find the state are:
265
265
// - parentId:childId1
266
266
// - parentId:childId2
267
- doReturn (
268
- // For the first call,
269
- // - The first get with the full ID shouldn't find a state.
270
- Optional .empty (),
271
- // - The second get with the parent ID should return the state.
272
- Optional .of (resultForGroupCommitState ),
273
- // For the second call,
274
- // - The first get with the full ID shouldn't find a state.
275
- Optional .empty (),
276
- // - The second get with the parent ID should return the state.
277
- Optional .of (resultForGroupCommitState ))
267
+ doReturn (Optional .of (resultForGroupCommitState ))
278
268
.when (storage )
279
- .get (any ( Get . class ));
269
+ .get (coordinator . createGetWith ( parentId ));
280
270
281
271
// Act
282
272
Optional <Coordinator .State > state1 = spiedCoordinator .getState (fullId1 );
@@ -291,9 +281,9 @@ public void getState_TransactionIdForGroupCommitGivenAndParentIdAndChildIdMatch_
291
281
assertThat (state1 .get ().getCreatedAt ()).isEqualTo (ANY_TIME_1 );
292
282
verify (spiedCoordinator ).getStateForGroupCommit (fullId1 );
293
283
verify (spiedCoordinator ).getStateForGroupCommit (fullId2 );
294
- verify (storage , times (4 )).get (getArgumentCaptor .capture ());
284
+ verify (storage , times (2 )).get (getArgumentCaptor .capture ());
295
285
assertGetArgumentCaptorForGetState (
296
- getArgumentCaptor .getAllValues (), Arrays .asList (fullId1 , parentId , fullId2 , parentId ));
286
+ getArgumentCaptor .getAllValues (), Arrays .asList (parentId , parentId ));
297
287
}
298
288
299
289
@ ParameterizedTest
@@ -310,6 +300,20 @@ public void getState_TransactionIdForSingleCommitGivenAndFullIdMatches_ShouldRet
310
300
String childId = UUID .randomUUID ().toString ();
311
301
String fullId = keyManipulator .fullKey (parentId , childId );
312
302
List <String > childIds = Collections .emptyList ();
303
+ String dummyChildId1 = UUID .randomUUID ().toString ();
304
+ String dummyChildId2 = UUID .randomUUID ().toString ();
305
+ List <String > dummyChildIds = Arrays .asList (dummyChildId1 , dummyChildId2 );
306
+
307
+ Result resultForGroupCommitState = mock (Result .class );
308
+ when (resultForGroupCommitState .getValue (Attribute .ID ))
309
+ .thenReturn (Optional .of (new TextValue (Attribute .ID , parentId )));
310
+ when (resultForGroupCommitState .getValue (Attribute .CHILD_IDS ))
311
+ .thenReturn (
312
+ Optional .of (new TextValue (Attribute .CHILD_IDS , Joiner .on (',' ).join (dummyChildIds ))));
313
+ when (resultForGroupCommitState .getValue (Attribute .STATE ))
314
+ .thenReturn (Optional .of (new IntValue (Attribute .STATE , transactionState .get ())));
315
+ when (resultForGroupCommitState .getValue (Attribute .CREATED_AT ))
316
+ .thenReturn (Optional .of (new BigIntValue (Attribute .CREATED_AT , ANY_TIME_1 )));
313
317
314
318
Result resultForSingleCommitState = mock (Result .class );
315
319
when (resultForSingleCommitState .getValue (Attribute .ID ))
@@ -323,13 +327,18 @@ public void getState_TransactionIdForSingleCommitGivenAndFullIdMatches_ShouldRet
323
327
324
328
// Assuming these states exist:
325
329
//
326
- // id | child_ids | state
327
- // ------------------+-----------+----------
328
- // parentId:childId | [] | COMMITTED
330
+ // id | child_ids | state
331
+ // ------------------+---------------------- +----------
332
+ // parentId:childId | [childId1, childId2] | COMMITTED
329
333
//
330
334
// The IDs used to find the state are:
331
335
// - parentId:childId
332
- doReturn (Optional .of (resultForSingleCommitState )).when (storage ).get (any (Get .class ));
336
+ doReturn (Optional .of (resultForGroupCommitState ))
337
+ .when (storage )
338
+ .get (coordinator .createGetWith (parentId ));
339
+ doReturn (Optional .of (resultForSingleCommitState ))
340
+ .when (storage )
341
+ .get (coordinator .createGetWith (fullId ));
333
342
334
343
// Act
335
344
Optional <Coordinator .State > state = spiedCoordinator .getState (fullId );
@@ -341,9 +350,9 @@ public void getState_TransactionIdForSingleCommitGivenAndFullIdMatches_ShouldRet
341
350
Assertions .assertThat (state .get ().getState ()).isEqualTo (transactionState );
342
351
assertThat (state .get ().getCreatedAt ()).isEqualTo (ANY_TIME_1 );
343
352
verify (spiedCoordinator ).getStateForGroupCommit (fullId );
344
- verify (storage ).get (getArgumentCaptor .capture ());
353
+ verify (storage , times ( 2 ) ).get (getArgumentCaptor .capture ());
345
354
assertGetArgumentCaptorForGetState (
346
- getArgumentCaptor .getAllValues (), Collections . singletonList ( fullId ));
355
+ getArgumentCaptor .getAllValues (), Arrays . asList ( parentId , fullId ));
347
356
}
348
357
349
358
@ ParameterizedTest
@@ -381,14 +390,11 @@ public void getState_TransactionIdForGroupCommitGivenAndOnlyParentIdMatches_Shou
381
390
//
382
391
// The IDs used to find the state are:
383
392
// - parentId:childIdX
384
- doReturn (
385
- // The first get with the full ID should return empty.
386
- Optional .empty (),
387
- // The second get with the parent ID should return a state, but it doesn't contain the
388
- // child ID.
389
- Optional .of (resultForGroupCommitState ))
393
+ doReturn (Optional .of (resultForGroupCommitState ))
390
394
.when (storage )
391
- .get (any (Get .class ));
395
+ .get (coordinator .createGetWith (parentId ));
396
+
397
+ doReturn (Optional .empty ()).when (storage ).get (coordinator .createGetWith (targetFullId ));
392
398
393
399
// Act
394
400
Optional <Coordinator .State > state = spiedCoordinator .getState (targetFullId );
@@ -398,7 +404,7 @@ public void getState_TransactionIdForGroupCommitGivenAndOnlyParentIdMatches_Shou
398
404
verify (spiedCoordinator ).getStateForGroupCommit (targetFullId );
399
405
verify (storage , times (2 )).get (getArgumentCaptor .capture ());
400
406
assertGetArgumentCaptorForGetState (
401
- getArgumentCaptor .getAllValues (), Arrays .asList (targetFullId , parentId ));
407
+ getArgumentCaptor .getAllValues (), Arrays .asList (parentId , targetFullId ));
402
408
}
403
409
404
410
@ ParameterizedTest
@@ -413,11 +419,23 @@ public void getState_TransactionIdForGroupCommitGivenAndOnlyParentIdMatches_Shou
413
419
CoordinatorGroupCommitKeyManipulator keyManipulator =
414
420
new CoordinatorGroupCommitKeyManipulator ();
415
421
String parentId = keyManipulator .generateParentKey ();
422
+ List <String > childIds =
423
+ Arrays .asList (UUID .randomUUID ().toString (), UUID .randomUUID ().toString ());
416
424
417
425
// Look up with the same parent ID and a wrong child ID.
418
426
// But the full ID matches the single committed state.
419
427
String targetFullId = keyManipulator .fullKey (parentId , UUID .randomUUID ().toString ());
420
428
429
+ Result resultForGroupCommitState = mock (Result .class );
430
+ when (resultForGroupCommitState .getValue (Attribute .ID ))
431
+ .thenReturn (Optional .of (new TextValue (Attribute .ID , parentId )));
432
+ when (resultForGroupCommitState .getValue (Attribute .CHILD_IDS ))
433
+ .thenReturn (Optional .of (new TextValue (Attribute .CHILD_IDS , Joiner .on (',' ).join (childIds ))));
434
+ when (resultForGroupCommitState .getValue (Attribute .STATE ))
435
+ .thenReturn (Optional .of (new IntValue (Attribute .STATE , transactionState .get ())));
436
+ when (resultForGroupCommitState .getValue (Attribute .CREATED_AT ))
437
+ .thenReturn (Optional .of (new BigIntValue (Attribute .CREATED_AT , ANY_TIME_1 )));
438
+
421
439
Result resultForSingleCommitState = mock (Result .class );
422
440
when (resultForSingleCommitState .getValue (Attribute .ID ))
423
441
.thenReturn (Optional .of (new TextValue (Attribute .ID , targetFullId )));
@@ -437,7 +455,12 @@ public void getState_TransactionIdForGroupCommitGivenAndOnlyParentIdMatches_Shou
437
455
//
438
456
// The IDs used to find the state are:
439
457
// - parentId:childIdX
440
- doReturn (Optional .of (resultForSingleCommitState )).when (storage ).get (any (Get .class ));
458
+ doReturn (Optional .of (resultForGroupCommitState ))
459
+ .when (storage )
460
+ .get (coordinator .createGetWith (parentId ));
461
+ doReturn (Optional .of (resultForSingleCommitState ))
462
+ .when (storage )
463
+ .get (coordinator .createGetWith (targetFullId ));
441
464
442
465
// Act
443
466
Optional <Coordinator .State > state = spiedCoordinator .getState (targetFullId );
@@ -449,9 +472,9 @@ public void getState_TransactionIdForGroupCommitGivenAndOnlyParentIdMatches_Shou
449
472
Assertions .assertThat (state .get ().getState ()).isEqualTo (transactionState );
450
473
assertThat (state .get ().getCreatedAt ()).isEqualTo (ANY_TIME_1 );
451
474
verify (spiedCoordinator ).getStateForGroupCommit (targetFullId );
452
- verify (storage ).get (getArgumentCaptor .capture ());
475
+ verify (storage , times ( 2 ) ).get (getArgumentCaptor .capture ());
453
476
assertGetArgumentCaptorForGetState (
454
- getArgumentCaptor .getAllValues (), Collections . singletonList ( targetFullId ));
477
+ getArgumentCaptor .getAllValues (), Arrays . asList ( parentId , targetFullId ));
455
478
}
456
479
457
480
@ ParameterizedTest
@@ -491,7 +514,10 @@ public void getState_TransactionIdGivenButNoIdMatches_ShouldReturnEmpty(
491
514
//
492
515
// The IDs used to find the state are:
493
516
// - parentId:childIdY
494
- when (storage .get (any (Get .class ))).thenReturn (Optional .empty ());
517
+ doReturn (Optional .of (resultForGroupCommitState ))
518
+ .when (storage )
519
+ .get (coordinator .createGetWith (parentId ));
520
+ doReturn (Optional .empty ()).when (storage ).get (coordinator .createGetWith (targetFullId ));
495
521
496
522
// Act
497
523
Optional <Coordinator .State > state = spiedCoordinator .getState (targetFullId );
@@ -501,7 +527,7 @@ public void getState_TransactionIdGivenButNoIdMatches_ShouldReturnEmpty(
501
527
verify (spiedCoordinator ).getStateForGroupCommit (targetFullId );
502
528
verify (storage , times (2 )).get (getArgumentCaptor .capture ());
503
529
assertGetArgumentCaptorForGetState (
504
- getArgumentCaptor .getAllValues (), Arrays .asList (targetFullId , parentId ));
530
+ getArgumentCaptor .getAllValues (), Arrays .asList (parentId , targetFullId ));
505
531
}
506
532
507
533
@ Test
0 commit comments