-
Notifications
You must be signed in to change notification settings - Fork 397
Expand file tree
/
Copy pathStateToReproduce.java
More file actions
135 lines (103 loc) · 3.47 KB
/
StateToReproduce.java
File metadata and controls
135 lines (103 loc) · 3.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package sqlancer;
import java.io.Closeable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import sqlancer.common.query.Query;
public class StateToReproduce {
private List<Query<?>> statements = new ArrayList<>();
private final String databaseName;
private final DatabaseProvider<?, ?, ?> databaseProvider;
public String databaseVersion;
protected long seedValue;
String exception;
public OracleRunReproductionState localState;
public StateToReproduce(String databaseName, DatabaseProvider<?, ?, ?> databaseProvider) {
this.databaseName = databaseName;
this.databaseProvider = databaseProvider;
}
public String getException() {
return exception;
}
public String getDatabaseName() {
return databaseName;
}
public String getDatabaseVersion() {
return databaseVersion;
}
/**
* Logs the statement string without executing the corresponding statement.
*
* @param queryString
* the query string to be logged
*/
public void logStatement(String queryString) {
if (queryString == null) {
throw new IllegalArgumentException();
}
logStatement(databaseProvider.getLoggableFactory().getQueryForStateToReproduce(queryString));
}
/**
* Logs the statement without executing it.
*
* @param query
* the query to be logged
*/
public void logStatement(Query<?> query) {
if (query == null) {
throw new IllegalArgumentException();
}
statements.add(query);
}
public List<Query<?>> getStatements() {
return Collections.unmodifiableList(statements);
}
@Deprecated
public void commentStatements() {
for (int i = 0; i < statements.size(); i++) {
Query<?> statement = statements.get(i);
Query<?> newQuery = databaseProvider.getLoggableFactory().commentOutQuery(statement);
statements.set(i, newQuery);
}
}
public long getSeedValue() {
return seedValue;
}
/**
* Returns a local state in which a test oracle can save useful information about a single run. If the local state
* is closed without indicating access to it, the local statements will be added to the global state.
*
* @return the local state for logging
*/
public OracleRunReproductionState getLocalState() {
return localState;
}
/**
* State information that is logged if the test oracle finds a bug or if an exception is thrown.
*/
public class OracleRunReproductionState implements Closeable {
private final List<Query<?>> statements = new ArrayList<>();
public boolean success;
public OracleRunReproductionState() {
StateToReproduce.this.localState = this;
}
public void executedWithoutError() {
this.success = true;
}
public void log(String s) {
statements.add(databaseProvider.getLoggableFactory().getQueryForStateToReproduce(s));
}
@Override
public void close() {
if (!success) {
StateToReproduce.this.statements.addAll(statements);
}
}
}
public OracleRunReproductionState createLocalState() {
return new OracleRunReproductionState();
}
public void setStatements(List<Query<?>> statements) {
this.statements = statements;
}
}