-
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathTest.java
More file actions
168 lines (156 loc) · 5.97 KB
/
Test.java
File metadata and controls
168 lines (156 loc) · 5.97 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
package com.rethinkdb.gen;
import com.rethinkdb.RethinkDB;
import com.rethinkdb.gen.exc.*;
import com.rethinkdb.gen.ast.*;
import com.rethinkdb.ast.ReqlAst;
import com.rethinkdb.model.MapObject;
import com.rethinkdb.model.OptArgs;
import com.rethinkdb.net.Connection;
import com.rethinkdb.net.Cursor;
import junit.framework.TestCase;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertArrayEquals;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.junit.*;
import org.junit.rules.ExpectedException;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.time.Instant;
import java.util.stream.LongStream;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.concurrent.TimeoutException;
import java.util.regex.Pattern;
import java.util.Collections;
import java.nio.charset.StandardCharsets;
import static com.rethinkdb.TestingCommon.*;
import com.rethinkdb.TestingFramework;
public class ${module_name} {
// ${description}
Logger logger = LoggerFactory.getLogger(${module_name}.class);
public static final RethinkDB r = RethinkDB.r;
%for var_name in table_var_names:
public static final Table ${var_name} = r.db("test").table("${var_name}");
%endfor
Connection conn;
@Before
public void setUp() throws Exception {
logger.info("Setting up.");
conn = TestingFramework.createConnection();
try {
r.dbCreate("test").run(conn);
r.db("test").wait_().run(conn);
}catch (Exception e){}
%for var_name in table_var_names:
try {
r.db("test").tableCreate("${var_name}").run(conn);
r.db("test").table(${var_name}).wait_().run(conn);
}catch (Exception e){}
%endfor
}
@After
public void tearDown() throws Exception {
logger.info("Tearing down.");
r.db("rethinkdb").table("_debug_scratch").delete().run(conn);
if(!conn.isOpen()){
conn.close();
conn = TestingFramework.createConnection();
}
%for var_name in table_var_names:
r.db("test").tableDrop("${var_name}").run(conn);
%endfor
r.dbDrop("test").run(conn);
conn.close(false);
}
// Matches Python's str() function, which we use.
// TODO: We might want to handle this in a visit_Call in convert_tests.py instead.
private static String str(long i) {
return String.valueOf(i);
}
// A hack to concatenate two Lists -- see is_array_add in convert_tests.py.
private static List concatList(List x, List y) {
List ret = new ArrayList<Long>(x);
ret.addAll(y);
return ret;
}
// Autogenerated tests below
<%rendered_vars = set() %>\
@Test(timeout=120000)
public void test() throws Exception {
<%rendered_something = False %>\
%for item in defs_and_test:
%if type(item) == JavaDef:
<%rendered_something = True %>
// ${item.testfile} line #${item.line_num}
// ${item.line.original}
logger.info("Possibly executing: ${item.line.java.replace('\\', '\\\\').replace('"', "'")}");
%if item.varname in rendered_vars:
${item.varname} = ${"maybeRun" if item.run_if_query else ""}(${item.value});
%elif item.run_if_query:
%if item.runopts:
Object ${item.varname} = maybeRun(${item.value}, conn, new OptArgs()
%for key, val in item.runopts.items():
.with("${key}", ${val})
%endfor
);
%else:
Object ${item.varname} = maybeRun(${item.value}, conn);
<%rendered_vars.add(item.varname)%>\
%endif
%else:
${item.vartype} ${item.varname} = ${item.value};
<%rendered_vars.add(item.varname)%>\
%endif
%elif type(item) == JavaQuery:
<%rendered_something = True %>
{
// ${item.testfile} line #${item.line_num}
/* ${item.expected_line.original} */
${item.expected_type} expected_ = ${item.expected_line.java};
/* ${item.line.original} */
%if item.testfile == "mutation/write_hook.yaml":
logger.info("About to run line #${item.line_num}: ${item.line.java.replace('"', "'").replace('\\', '\\\\').replace('\n', '\\n').replace("(ReqlExpr)", "(ReqlFunction3)")}");
Object obtained = runOrCatch(${item.line.java.replace("(ReqlExpr)", "(ReqlFunction3)")},
%else:
logger.info("About to run line #${item.line_num}: ${item.line.java.replace('"', "'").replace('\\', '\\\\').replace('\n', '\\n')}");
Object obtained = runOrCatch(${item.line.java},
%endif
new OptArgs()
%if item.runopts:
%for key, val in item.runopts.items():
.with("${key}", ${val})
%endfor
%endif
,conn);
try {
%if item.expected_type.endswith('[]'):
assertArrayEquals(expected_, (${item.expected_type}) obtained);
%elif item.expected_type == 'Double':
assertEquals((double) expected_,
((Number) obtained).doubleValue(),
0.00000000001);
%else:
assertEquals(expected_, obtained);
%endif
logger.info("Finished running line #${item.line_num}");
} catch (Throwable ae) {
logger.error("Whoops, got exception on line #${item.line_num}:" + ae.toString());
if(obtained instanceof Throwable) {
ae.addSuppressed((Throwable) obtained);
}
throw ae;
}
}
%endif
%endfor
%if not rendered_something:
<% raise EmptyTemplate() %>\
%endif
}
}