18
18
19
19
import org .junit .After ;
20
20
import org .junit .Before ;
21
+ import org .junit .Ignore ;
21
22
import org .junit .Test ;
22
23
23
24
import com .arangodb .ArangoConfigure ;
37
38
*/
38
39
public class ArangoDriverBatchTest extends BaseTest {
39
40
41
+ String colName = "unit_test_batchTest" ;
42
+
40
43
public ArangoDriverBatchTest (ArangoConfigure configure , ArangoDriver driver ) {
41
44
super (configure , driver );
42
45
}
@@ -45,16 +48,26 @@ public ArangoDriverBatchTest(ArangoConfigure configure, ArangoDriver driver) {
45
48
46
49
@ Before
47
50
public void before () throws ArangoException {
48
- for (String col : new String []{"blub" }) {
49
- try {
50
- driver .deleteCollection (col );
51
- } catch (ArangoException e ) {
52
- }
51
+ try {
52
+ driver .cancelBatchMode ();
53
+ } catch (ArangoException e ) {
54
+ }
55
+ try {
56
+ driver .deleteCollection (colName );
57
+ } catch (ArangoException e ) {
53
58
}
54
59
}
55
60
56
61
@ After
57
62
public void after () {
63
+ try {
64
+ driver .cancelBatchMode ();
65
+ } catch (ArangoException e ) {
66
+ }
67
+ try {
68
+ driver .deleteCollection (colName );
69
+ } catch (ArangoException e ) {
70
+ }
58
71
}
59
72
60
73
@ Test
@@ -86,14 +99,17 @@ public void test_StartCancelExecuteBatchMode() throws ArangoException {
86
99
}
87
100
assertThat (msg , is ("BatchMode is not active." ));
88
101
89
-
90
102
}
91
103
92
-
93
-
94
104
@ Test
95
105
public void test_execBatchMode () throws ArangoException {
96
106
107
+ try {
108
+ driver .truncateCollection ("_aqlfunctions" );
109
+ } catch (Exception e ) {
110
+ e .printStackTrace ();
111
+ }
112
+
97
113
driver .startBatchMode ();
98
114
99
115
BaseEntity res = driver .createAqlFunction (
@@ -116,13 +132,13 @@ public void test_execBatchMode() throws ArangoException {
116
132
117
133
for (int i = 0 ; i < 10 ; i ++) {
118
134
TestComplexEntity01 value = new TestComplexEntity01 ("user-" + i , "data:" + i , i );
119
- res = driver .createDocument ("blub" , value , true , false );
135
+ res = driver .createDocument (colName , value , true , false );
120
136
121
137
assertThat (res .getStatusCode (), is (206 ));
122
138
assertThat (res .getRequestId (), is ("request" + (4 + i )));
123
139
}
124
140
125
- List <String > r = driver .getDocuments ("blub" );
141
+ List <String > r = driver .getDocuments (colName );
126
142
127
143
DefaultEntity result = driver .executeBatch ();
128
144
DefaultEntity created = driver .getBatchResponseByRequestId ("request1" );
@@ -138,6 +154,43 @@ public void test_execBatchMode() throws ArangoException {
138
154
List <String > documents = driver .getBatchResponseByRequestId ("request14" );
139
155
assertThat (documents .size (), is (10 ));
140
156
157
+ try {
158
+ driver .truncateCollection ("_aqlfunctions" );
159
+ } catch (Exception e ) {
160
+ e .printStackTrace ();
161
+ }
162
+
163
+ }
164
+
165
+ @ Test
166
+ public void test_execBatchMode_twice () throws ArangoException {
167
+
168
+ driver .startBatchMode ();
169
+
170
+ BaseEntity res ;
171
+
172
+ for (int i = 0 ; i < 10 ; i ++) {
173
+ TestComplexEntity01 value = new TestComplexEntity01 ("user-" + i , "data:" + i , i );
174
+ res = driver .createDocument (colName , value , true , false );
175
+ assertThat (res .getRequestId (), is ("request" + (i + 1 )));
176
+ }
177
+
178
+ driver .executeBatch ();
179
+
180
+ assertThat (driver .getDocuments (colName ).size (), is (10 ));
181
+
182
+ driver .startBatchMode ();
183
+
184
+ for (int i = 20 ; i < 30 ; i ++) {
185
+ TestComplexEntity01 value = new TestComplexEntity01 ("user-" + i , "data:" + i , i );
186
+ res = driver .createDocument (colName , value , true , false );
187
+ assertThat (res .getRequestId (), is ("request" + (i + 1 - 20 )));
188
+ }
189
+
190
+ driver .executeBatch ();
191
+
192
+ assertThat (driver .getDocuments (colName ).size (), is (20 ));
193
+
141
194
}
142
195
143
196
}
0 commit comments