22
33import com .mongodb .client .MongoCollection ;
44import java .io .IOException ;
5+ import java .lang .reflect .Parameter ;
6+ import java .util .List ;
57import java .util .concurrent .atomic .AtomicInteger ;
68import java .util .concurrent .atomic .AtomicReference ;
79import java .util .function .Function ;
2224import works .bosk .drivers .mongo .PandoFormat ;
2325import works .bosk .exceptions .FlushFailureException ;
2426import works .bosk .exceptions .InvalidTypeException ;
27+ import works .bosk .junit .InjectFrom ;
28+ import works .bosk .junit .InjectedTest ;
29+ import works .bosk .junit .ParameterInjector ;
2530import works .bosk .testing .drivers .state .TestEntity ;
26- import works .bosk .testing .junit .ParametersByName ;
2731import works .bosk .testing .junit .Slow ;
2832
2933import static ch .qos .logback .classic .Level .ERROR ;
3842 * Tests the kinds of recovery actions a human operator might take to try to get a busted service running again.
3943 */
4044@ Slow
45+ @ InjectFrom ({
46+ MongoDriverRecoveryTest .FlushOrWaitInjector .class ,
47+ MongoDriverRecoveryTest .TestParameterInjector .class
48+ })
4149public class MongoDriverRecoveryTest extends AbstractMongoDriverTest {
4250 FlushOrWait flushOrWait ;
4351
@@ -47,24 +55,31 @@ void overrideLogging() {
4755 setLogging (ERROR , MainDriver .class , ChangeReceiver .class );
4856 }
4957
50- @ ParametersByName
5158 MongoDriverRecoveryTest (FlushOrWait flushOrWait , TestParameters .ParameterSet parameters ) {
5259 super (parameters .driverSettingsBuilder ());
5360 this .flushOrWait = flushOrWait ;
5461 }
5562
56- @ SuppressWarnings ("unused" )
57- static Stream <TestParameters .ParameterSet > parameters () {
58- return TestParameters .driverSettings (
59- Stream .of (
60- MongoDriverSettings .DatabaseFormat .SEQUOIA ,
61- PandoFormat .oneBigDocument (),
62- PandoFormat .withGraftPoints ("/catalog" , "/sideTable" )
63- ),
64- Stream .of (TestParameters .EventTiming .NORMAL )
65- ).map (b -> b .applyDriverSettings (s -> s
66- .timescaleMS (SHORT_TIMESCALE ) // Note that some tests can take as long as 25x this
67- ));
63+ record TestParameterInjector () implements ParameterInjector {
64+ @ Override
65+ public boolean supportsParameter (Parameter parameter ) {
66+ return parameter .getType () == TestParameters .ParameterSet .class ;
67+ }
68+
69+ @ Override
70+ public List <Object > values () {
71+ return TestParameters .driverSettings (
72+ Stream .of (
73+ MongoDriverSettings .DatabaseFormat .SEQUOIA ,
74+ PandoFormat .oneBigDocument (),
75+ PandoFormat .withGraftPoints ("/catalog" , "/sideTable" )
76+ ),
77+ Stream .of (TestParameters .EventTiming .NORMAL )
78+ ).map (b -> b .applyDriverSettings (s -> s
79+ .timescaleMS (SHORT_TIMESCALE ) // Note that some tests can take as long as 25x this
80+ )).map (x -> (Object )x )
81+ .toList ();
82+ }
6883 }
6984
7085 enum FlushOrWait {
@@ -81,12 +96,20 @@ enum FlushOrWait {
8196 WAIT ,
8297 }
8398
84- @ SuppressWarnings ("unused" )
85- static Stream <FlushOrWait > flushOrWait () {
86- return Stream .of (FlushOrWait .values ());
99+ record FlushOrWaitInjector () implements ParameterInjector {
100+ @ Override
101+ public boolean supportsParameter (Parameter parameter ) {
102+ return parameter .getType () == FlushOrWait .class ;
103+ }
104+
105+ @ Override
106+ public List <Object > values () {
107+ return List .of (FlushOrWait .values ());
108+ }
87109 }
88110
89- @ ParametersByName
111+
112+ @ InjectedTest
90113 @ DisruptsMongoProxy
91114 void initialOutage_recovers () throws InvalidTypeException , InterruptedException , IOException {
92115 LOGGER .debug ("Set up the database contents to be different from initialRoot" );
@@ -155,7 +178,7 @@ private void waitFor(BoskDriver driver) throws IOException, InterruptedException
155178 }
156179 }
157180
158- @ ParametersByName
181+ @ InjectedTest
159182 void databaseDropped_recovers () throws InterruptedException , IOException {
160183 testRecovery (() -> {
161184 LOGGER .debug ("Drop database" );
@@ -166,7 +189,7 @@ void databaseDropped_recovers() throws InterruptedException, IOException {
166189 }, (_ ) -> initializeDatabase ("after drop" ));
167190 }
168191
169- @ ParametersByName
192+ @ InjectedTest
170193 void collectionDropped_recovers () throws InterruptedException , IOException {
171194 testRecovery (() -> {
172195 LOGGER .debug ("Drop collection" );
@@ -177,7 +200,7 @@ void collectionDropped_recovers() throws InterruptedException, IOException {
177200 }, (_ ) -> initializeDatabase ("after drop" ));
178201 }
179202
180- @ ParametersByName
203+ @ InjectedTest
181204 void documentDeleted_recovers () throws InterruptedException , IOException {
182205 testRecovery (() -> {
183206 LOGGER .debug ("Delete document" );
@@ -188,7 +211,7 @@ void documentDeleted_recovers() throws InterruptedException, IOException {
188211 }, (_ ) -> initializeDatabase ("after deletion" ));
189212 }
190213
191- @ ParametersByName
214+ @ InjectedTest
192215 void documentReappears_recovers () throws InterruptedException , IOException {
193216 MongoCollection <Document > collection = mongoService .client ()
194217 .getDatabase (driverSettings .database ())
@@ -215,7 +238,7 @@ void documentReappears_recovers() throws InterruptedException, IOException {
215238 });
216239 }
217240
218- @ ParametersByName
241+ @ InjectedTest
219242 void revisionDeleted_recovers () throws InterruptedException , IOException {
220243 // It's not clear that this is a valid test. If this test is a burden to support,
221244 // we can consider removing it.
0 commit comments