40
40
import io .spine .environment .Tests ;
41
41
import io .spine .server .BoundedContext ;
42
42
import io .spine .server .BoundedContextBuilder ;
43
- import io .spine .server .ContextSpec ;
44
43
import io .spine .server .ServerEnvironment ;
45
44
import io .spine .server .aggregate .given .Given ;
46
45
import io .spine .server .aggregate .given .aggregate .AggregateWithMissingApplier ;
54
53
import io .spine .server .aggregate .given .salary .Employee ;
55
54
import io .spine .server .aggregate .given .salary .EmployeeAgg ;
56
55
import io .spine .server .aggregate .given .salary .PreparedInboxStorage ;
56
+ import io .spine .server .aggregate .given .salary .PreparedStorageFactory ;
57
57
import io .spine .server .aggregate .given .salary .event .NewEmployed ;
58
58
import io .spine .server .aggregate .given .thermometer .SafeThermometer ;
59
59
import io .spine .server .aggregate .given .thermometer .SafeThermometerRepo ;
60
60
import io .spine .server .aggregate .given .thermometer .Thermometer ;
61
61
import io .spine .server .aggregate .given .thermometer .ThermometerId ;
62
62
import io .spine .server .aggregate .given .thermometer .event .TemperatureChanged ;
63
63
import io .spine .server .delivery .DeliveryStrategy ;
64
- import io .spine .server .delivery .InboxStorage ;
65
64
import io .spine .server .delivery .MessageEndpoint ;
66
65
import io .spine .server .model .ModelError ;
67
- import io .spine .server .storage .RecordSpec ;
68
- import io .spine .server .storage .RecordStorage ;
69
- import io .spine .server .storage .StorageFactory ;
70
- import io .spine .server .storage .memory .InMemoryStorageFactory ;
71
66
import io .spine .server .type .CommandClass ;
72
67
import io .spine .server .type .CommandEnvelope ;
73
68
import io .spine .server .type .EventClass ;
112
107
import static com .google .common .collect .Lists .newArrayList ;
113
108
import static com .google .common .truth .Truth .assertThat ;
114
109
import static com .google .common .truth .extensions .proto .ProtoTruth .assertThat ;
115
- import static io .spine .base .Identifier .newUuid ;
116
110
import static io .spine .grpc .StreamObservers .noOpObserver ;
117
111
import static io .spine .protobuf .AnyPacker .unpack ;
118
112
import static io .spine .server .aggregate .given .Given .EventMessage .projectCreated ;
@@ -464,8 +458,8 @@ void restoreSnapshot() {
464
458
}
465
459
466
460
@ Test
467
- @ DisplayName ("add events to `UncommittedHistory` only if they were successfully applied" )
468
- void addEventsToUncommittedOnlyIfApplied3 () {
461
+ @ DisplayName ("store events only if they were successfully applied" )
462
+ void storeEventsOnlyIfApplied () {
469
463
var jack = newEmployee ();
470
464
var shardIndex = DeliveryStrategy .newIndex (0 , 1 );
471
465
var inboxStorage = PreparedInboxStorage .withCommands (
@@ -477,50 +471,26 @@ void addEventsToUncommittedOnlyIfApplied3() {
477
471
command (increaseSalary (jack , 500 ))
478
472
);
479
473
480
- System .out .println ("Setting storage factory ..." );
481
- ServerEnvironment .instance ().reset ();
482
- ServerEnvironment .when (Tests .class )
483
- .use (new StorageFactory () {
484
- @ Override
485
- public <I , R extends Message > RecordStorage <I , R > createRecordStorage (
486
- ContextSpec context , RecordSpec <I , R , ?> spec ) {
487
- return InMemoryStorageFactory .newInstance ().createRecordStorage (context , spec );
488
- }
489
-
490
- @ Override
491
- public InboxStorage createInboxStorage (boolean multitenant ) {
492
- return inboxStorage ;
493
- }
494
-
495
- @ Override
496
- public void close () {
497
- // NO OP
498
- }
499
- });
474
+ var serverEnv = ServerEnvironment .instance ();
475
+ serverEnv .reset ();
476
+ ServerEnvironment .when (Tests .class ).use (PreparedStorageFactory .with (inboxStorage ));
500
477
501
478
var repository = new DefaultAggregateRepository <>(EmployeeAgg .class );
502
479
BoundedContextBuilder .assumingTests ()
503
480
.add (repository )
504
481
.build ();
505
482
506
- System .out .println (ServerEnvironment .instance ().type ());
507
- System .out .println (ServerEnvironment .instance ().storageFactory ().createInboxStorage (false ));
508
-
509
- var stats = ServerEnvironment
510
- .instance ()
511
- .delivery ()
512
- .deliverMessagesFrom (shardIndex )
513
- .orElseThrow ();
514
- System .out .println (stats .deliveredCount ());
515
- ServerEnvironment .instance ().reset ();
483
+ serverEnv .delivery ().deliverMessagesFrom (shardIndex );
484
+ serverEnv .reset ();
516
485
517
486
var storedEvents = repository .aggregateStorage ()
518
487
.read (jack )
519
488
.orElseThrow ()
520
489
.getEventList ();
490
+ var singleEvent = storedEvents .get (0 ).enclosedMessage ();
521
491
522
492
assertThat (storedEvents .size ()).isEqualTo (1 );
523
- assertThat (storedEvents . get ( 0 ). enclosedMessage () .getClass ()).isEqualTo (NewEmployed .class );
493
+ assertThat (singleEvent .getClass ()).isEqualTo (NewEmployed .class );
524
494
}
525
495
526
496
@ Nested
0 commit comments