1818
1919import org .junit .After ;
2020import org .junit .Before ;
21+ import org .junit .Ignore ;
2122import org .junit .Test ;
2223
2324import com .arangodb .ArangoConfigure ;
3738 */
3839public class ArangoDriverBatchTest extends BaseTest {
3940
41+ String colName = "unit_test_batchTest" ;
42+
4043 public ArangoDriverBatchTest (ArangoConfigure configure , ArangoDriver driver ) {
4144 super (configure , driver );
4245 }
@@ -45,16 +48,26 @@ public ArangoDriverBatchTest(ArangoConfigure configure, ArangoDriver driver) {
4548
4649 @ Before
4750 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 ) {
5358 }
5459 }
5560
5661 @ After
5762 public void after () {
63+ try {
64+ driver .cancelBatchMode ();
65+ } catch (ArangoException e ) {
66+ }
67+ try {
68+ driver .deleteCollection (colName );
69+ } catch (ArangoException e ) {
70+ }
5871 }
5972
6073 @ Test
@@ -86,14 +99,17 @@ public void test_StartCancelExecuteBatchMode() throws ArangoException {
8699 }
87100 assertThat (msg , is ("BatchMode is not active." ));
88101
89-
90102 }
91103
92-
93-
94104 @ Test
95105 public void test_execBatchMode () throws ArangoException {
96106
107+ try {
108+ driver .truncateCollection ("_aqlfunctions" );
109+ } catch (Exception e ) {
110+ e .printStackTrace ();
111+ }
112+
97113 driver .startBatchMode ();
98114
99115 BaseEntity res = driver .createAqlFunction (
@@ -116,13 +132,13 @@ public void test_execBatchMode() throws ArangoException {
116132
117133 for (int i = 0 ; i < 10 ; i ++) {
118134 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 );
120136
121137 assertThat (res .getStatusCode (), is (206 ));
122138 assertThat (res .getRequestId (), is ("request" + (4 + i )));
123139 }
124140
125- List <String > r = driver .getDocuments ("blub" );
141+ List <String > r = driver .getDocuments (colName );
126142
127143 DefaultEntity result = driver .executeBatch ();
128144 DefaultEntity created = driver .getBatchResponseByRequestId ("request1" );
@@ -138,6 +154,43 @@ public void test_execBatchMode() throws ArangoException {
138154 List <String > documents = driver .getBatchResponseByRequestId ("request14" );
139155 assertThat (documents .size (), is (10 ));
140156
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+
141194 }
142195
143196}
0 commit comments