11package sqlancer ;
22
3+ import java .io .Closeable ;
34import java .util .ArrayList ;
45import java .util .Collections ;
56import java .util .List ;
@@ -22,12 +23,6 @@ public class StateToReproduce {
2223
2324 private final List <Query > statements = new ArrayList <>();
2425
25- /**
26- * The string printed at the bottom of the error log file, which contains the queries that caused the test to fail
27- * and information about their results.
28- */
29- public String queryString ;
30-
3126 private final String databaseName ;
3227
3328 public String databaseVersion ;
@@ -42,6 +37,8 @@ public class StateToReproduce {
4237
4338 public String queryTargetedColumnsString ;
4439
40+ public OracleRunReproductionState localState ;
41+
4542 public StateToReproduce (String databaseName ) {
4643 this .databaseName = databaseName ;
4744 }
@@ -88,14 +85,20 @@ public List<Query> getStatements() {
8885 return Collections .unmodifiableList (statements );
8986 }
9087
91- public String getQueryString () {
92- return queryString ;
93- }
94-
9588 public long getSeedValue () {
9689 return seedValue ;
9790 }
9891
92+ /**
93+ * Returns a local state in which a test oracle can save useful information about a single run. If the local state
94+ * is closed without indicating access to it, the local statements will be added to the global state.
95+ *
96+ * @return
97+ */
98+ public OracleRunReproductionState getLocalState () {
99+ return localState ;
100+ }
101+
99102 public static class MySQLStateToReproduce extends StateToReproduce {
100103
101104 public Map <MySQLColumn , MySQLConstant > randomRowValues ;
@@ -181,4 +184,43 @@ public ClickHouseExpression getWhereClause() {
181184
182185 }
183186
187+ /**
188+ * State information that is logged if the test oracle finds a bug or if an exception is thrown.
189+ */
190+ public class OracleRunReproductionState implements Closeable {
191+
192+ private final List <Query > statements = new ArrayList <>();
193+
194+ public boolean success ;
195+
196+ public OracleRunReproductionState () {
197+ StateToReproduce .this .localState = this ;
198+ }
199+
200+ public void executedWithoutError () {
201+ this .success = true ;
202+ }
203+
204+ public void log (Query q ) {
205+ statements .add (q );
206+ }
207+
208+ public void log (String s ) {
209+ statements .add (new QueryAdapter (s ));
210+ }
211+
212+ @ Override
213+ public void close () {
214+ if (!success ) {
215+ StateToReproduce .this .statements .addAll (statements );
216+ }
217+
218+ }
219+
220+ }
221+
222+ public OracleRunReproductionState createLocalState () {
223+ return new OracleRunReproductionState ();
224+ }
225+
184226}
0 commit comments