|
36 | 36 | */
|
37 | 37 | public class ArangoDriverBatchTest extends BaseTest {
|
38 | 38 |
|
39 |
| - String colName = "unit_test_batchTest"; |
40 |
| - |
41 |
| - public ArangoDriverBatchTest(ArangoConfigure configure, ArangoDriver driver) { |
42 |
| - super(configure, driver); |
43 |
| - } |
44 |
| - |
45 |
| - |
46 |
| - |
47 |
| - @Before |
48 |
| - public void before() throws ArangoException { |
49 |
| - try { |
50 |
| - driver.cancelBatchMode(); |
51 |
| - } catch (ArangoException e) { |
52 |
| - } |
53 |
| - try { |
54 |
| - driver.deleteCollection(colName); |
55 |
| - } catch (ArangoException e) { |
56 |
| - } |
57 |
| - } |
58 |
| - |
59 |
| - @After |
60 |
| - public void after() { |
61 |
| - try { |
62 |
| - driver.cancelBatchMode(); |
63 |
| - } catch (ArangoException e) { |
64 |
| - } |
65 |
| - try { |
66 |
| - driver.deleteCollection(colName); |
67 |
| - } catch (ArangoException e) { |
68 |
| - } |
69 |
| - } |
70 |
| - |
71 |
| - @Test |
72 |
| - public void test_StartCancelExecuteBatchMode() throws ArangoException { |
73 |
| - |
74 |
| - driver.startBatchMode(); |
75 |
| - String msg = ""; |
76 |
| - try { |
77 |
| - driver.startBatchMode(); |
78 |
| - } catch (ArangoException e) { |
79 |
| - msg = e.getErrorMessage(); |
80 |
| - } |
81 |
| - assertThat(msg , is("BatchMode is already active.")); |
82 |
| - |
83 |
| - driver.cancelBatchMode(); |
84 |
| - msg = ""; |
85 |
| - try { |
86 |
| - driver.cancelBatchMode(); |
87 |
| - } catch (ArangoException e) { |
88 |
| - msg = e.getErrorMessage(); |
89 |
| - } |
90 |
| - assertThat(msg , is("BatchMode is not active.")); |
91 |
| - |
92 |
| - msg = ""; |
93 |
| - try { |
94 |
| - driver.executeBatch(); |
95 |
| - } catch (ArangoException e) { |
96 |
| - msg = e.getErrorMessage(); |
97 |
| - } |
98 |
| - assertThat(msg , is("BatchMode is not active.")); |
99 |
| - |
100 |
| - } |
101 |
| - |
102 |
| - @Test |
103 |
| - public void test_execBatchMode() throws ArangoException { |
104 |
| - |
105 |
| - try { |
106 |
| - driver.truncateCollection("_aqlfunctions"); |
107 |
| - } catch (Exception e) { |
108 |
| - e.printStackTrace(); |
109 |
| - } |
110 |
| - |
111 |
| - driver.startBatchMode(); |
112 |
| - |
113 |
| - BaseEntity res = driver.createAqlFunction( |
114 |
| - "someNamespace::testCode", "function (celsius) { return celsius * 2.8 + 32; }" |
115 |
| - ); |
116 |
| - |
117 |
| - assertThat(res.getStatusCode(), is(206)); |
118 |
| - assertThat(res.getRequestId() , is("request1")); |
119 |
| - |
120 |
| - res = driver.createAqlFunction( |
121 |
| - "someNamespace::testC&&&&&&&&&&de", "function (celsius) { return celsius * 2.8 + 32; }" |
122 |
| - ); |
123 |
| - |
124 |
| - assertThat(res.getStatusCode(), is(206)); |
125 |
| - assertThat(res.getRequestId(), is("request2")); |
126 |
| - |
127 |
| - res = driver.getAqlFunctions(null); |
128 |
| - assertThat(res.getStatusCode(), is(206)); |
129 |
| - assertThat(res.getRequestId(), is("request3")); |
130 |
| - |
131 |
| - for (int i = 0; i < 10; i++) { |
132 |
| - TestComplexEntity01 value = new TestComplexEntity01("user-" + i, "data:" + i, i); |
133 |
| - res = driver.createDocument(colName, value, true, false); |
134 |
| - |
135 |
| - assertThat(res.getStatusCode(), is(206)); |
136 |
| - assertThat(res.getRequestId(), is("request" + (4 + i))); |
137 |
| - } |
138 |
| - |
139 |
| - List<String> r = driver.getDocuments(colName); |
140 |
| - |
141 |
| - DefaultEntity result = driver.executeBatch(); |
142 |
| - DefaultEntity created = driver.getBatchResponseByRequestId("request1"); |
143 |
| - assertThat(created.getStatusCode() , is(201)); |
144 |
| - AqlFunctionsEntity functions = driver.getBatchResponseByRequestId("request3"); |
145 |
| - assertThat(functions.getStatusCode() , is(200)); |
146 |
| - assertThat(String.valueOf(functions.getAqlFunctions().keySet().toArray()[0]) , is("someNamespace::testCode")); |
147 |
| - for (int i = 0; i < 10; i++) { |
148 |
| - DocumentEntity<TestComplexEntity01> resultComplex = driver.getBatchResponseByRequestId("request" + (4+i)); |
149 |
| - assertThat(resultComplex.getStatusCode() , is(202)); |
150 |
| - } |
151 |
| - |
152 |
| - List<String> documents = driver.getBatchResponseByRequestId("request14"); |
153 |
| - assertThat(documents.size(), is(10)); |
154 |
| - |
155 |
| - try { |
156 |
| - driver.truncateCollection("_aqlfunctions"); |
157 |
| - } catch (Exception e) { |
158 |
| - e.printStackTrace(); |
159 |
| - } |
160 |
| - |
161 |
| - } |
162 |
| - |
163 |
| - @Test |
164 |
| - public void test_execBatchMode_twice() throws ArangoException { |
| 39 | + String colName = "unit_test_batchTest"; |
| 40 | + |
| 41 | + public ArangoDriverBatchTest(ArangoConfigure configure, ArangoDriver driver) { |
| 42 | + super(configure, driver); |
| 43 | + } |
| 44 | + |
| 45 | + @Before |
| 46 | + public void before() throws ArangoException { |
| 47 | + try { |
| 48 | + driver.cancelBatchMode(); |
| 49 | + } catch (ArangoException e) { |
| 50 | + } |
| 51 | + try { |
| 52 | + driver.deleteCollection(colName); |
| 53 | + } catch (ArangoException e) { |
| 54 | + } |
| 55 | + } |
| 56 | + |
| 57 | + @After |
| 58 | + public void after() { |
| 59 | + try { |
| 60 | + driver.cancelBatchMode(); |
| 61 | + } catch (ArangoException e) { |
| 62 | + } |
| 63 | + try { |
| 64 | + driver.deleteCollection(colName); |
| 65 | + } catch (ArangoException e) { |
| 66 | + } |
| 67 | + } |
| 68 | + |
| 69 | + @Test |
| 70 | + public void test_StartCancelExecuteBatchMode() throws ArangoException { |
| 71 | + |
| 72 | + driver.startBatchMode(); |
| 73 | + String msg = ""; |
| 74 | + try { |
| 75 | + driver.startBatchMode(); |
| 76 | + } catch (ArangoException e) { |
| 77 | + msg = e.getErrorMessage(); |
| 78 | + } |
| 79 | + assertThat(msg, is("BatchMode is already active.")); |
| 80 | + |
| 81 | + driver.cancelBatchMode(); |
| 82 | + msg = ""; |
| 83 | + try { |
| 84 | + driver.cancelBatchMode(); |
| 85 | + } catch (ArangoException e) { |
| 86 | + msg = e.getErrorMessage(); |
| 87 | + } |
| 88 | + assertThat(msg, is("BatchMode is not active.")); |
| 89 | + |
| 90 | + msg = ""; |
| 91 | + try { |
| 92 | + driver.executeBatch(); |
| 93 | + } catch (ArangoException e) { |
| 94 | + msg = e.getErrorMessage(); |
| 95 | + } |
| 96 | + assertThat(msg, is("BatchMode is not active.")); |
| 97 | + |
| 98 | + } |
| 99 | + |
| 100 | + @Test |
| 101 | + public void test_execBatchMode() throws ArangoException { |
| 102 | + |
| 103 | + try { |
| 104 | + driver.truncateCollection("_aqlfunctions"); |
| 105 | + } catch (Exception e) { |
| 106 | + e.printStackTrace(); |
| 107 | + } |
| 108 | + |
| 109 | + driver.startBatchMode(); |
| 110 | + |
| 111 | + BaseEntity res = driver.createAqlFunction("someNamespace::testCode", |
| 112 | + "function (celsius) { return celsius * 2.8 + 32; }"); |
| 113 | + |
| 114 | + assertThat(res.getStatusCode(), is(206)); |
| 115 | + assertThat(res.getRequestId(), is("request1")); |
| 116 | + |
| 117 | + res = driver.createAqlFunction("someNamespace::testC&&&&&&&&&&de", |
| 118 | + "function (celsius) { return celsius * 2.8 + 32; }"); |
| 119 | + |
| 120 | + assertThat(res.getStatusCode(), is(206)); |
| 121 | + assertThat(res.getRequestId(), is("request2")); |
| 122 | + |
| 123 | + res = driver.getAqlFunctions(null); |
| 124 | + assertThat(res.getStatusCode(), is(206)); |
| 125 | + assertThat(res.getRequestId(), is("request3")); |
| 126 | + |
| 127 | + for (int i = 0; i < 10; i++) { |
| 128 | + TestComplexEntity01 value = new TestComplexEntity01("user-" + i, "data:" + i, i); |
| 129 | + res = driver.createDocument(colName, value, true, false); |
| 130 | + |
| 131 | + assertThat(res.getStatusCode(), is(206)); |
| 132 | + assertThat(res.getRequestId(), is("request" + (4 + i))); |
| 133 | + } |
| 134 | + |
| 135 | + driver.getDocuments(colName); |
| 136 | + |
| 137 | + driver.executeBatch(); |
| 138 | + DefaultEntity created = driver.getBatchResponseByRequestId("request1"); |
| 139 | + assertThat(created.getStatusCode(), is(201)); |
| 140 | + AqlFunctionsEntity functions = driver.getBatchResponseByRequestId("request3"); |
| 141 | + assertThat(functions.getStatusCode(), is(200)); |
| 142 | + assertThat(String.valueOf(functions.getAqlFunctions().keySet().toArray()[0]), is("someNamespace::testCode")); |
| 143 | + for (int i = 0; i < 10; i++) { |
| 144 | + DocumentEntity<TestComplexEntity01> resultComplex = driver.getBatchResponseByRequestId("request" + (4 + i)); |
| 145 | + assertThat(resultComplex.getStatusCode(), is(202)); |
| 146 | + } |
| 147 | + |
| 148 | + List<String> documents = driver.getBatchResponseByRequestId("request14"); |
| 149 | + assertThat(documents.size(), is(10)); |
| 150 | + |
| 151 | + try { |
| 152 | + driver.truncateCollection("_aqlfunctions"); |
| 153 | + } catch (Exception e) { |
| 154 | + e.printStackTrace(); |
| 155 | + } |
165 | 156 |
|
166 |
| - driver.startBatchMode(); |
| 157 | + } |
| 158 | + |
| 159 | + @Test |
| 160 | + public void test_execBatchMode_twice() throws ArangoException { |
167 | 161 |
|
168 |
| - BaseEntity res; |
| 162 | + driver.startBatchMode(); |
169 | 163 |
|
170 |
| - for (int i = 0; i < 10; i++) { |
171 |
| - TestComplexEntity01 value = new TestComplexEntity01("user-" + i, "data:" + i, i); |
172 |
| - res = driver.createDocument(colName, value, true, false); |
173 |
| - assertThat(res.getRequestId(), is("request" + (i + 1))); |
174 |
| - } |
| 164 | + BaseEntity res; |
175 | 165 |
|
176 |
| - driver.executeBatch(); |
| 166 | + for (int i = 0; i < 10; i++) { |
| 167 | + TestComplexEntity01 value = new TestComplexEntity01("user-" + i, "data:" + i, i); |
| 168 | + res = driver.createDocument(colName, value, true, false); |
| 169 | + assertThat(res.getRequestId(), is("request" + (i + 1))); |
| 170 | + } |
177 | 171 |
|
178 |
| - assertThat(driver.getDocuments(colName).size(), is(10)); |
| 172 | + driver.executeBatch(); |
179 | 173 |
|
180 |
| - driver.startBatchMode(); |
| 174 | + assertThat(driver.getDocuments(colName).size(), is(10)); |
181 | 175 |
|
182 |
| - for (int i = 20; i < 30; i++) { |
183 |
| - TestComplexEntity01 value = new TestComplexEntity01("user-" + i, "data:" + i, i); |
184 |
| - res = driver.createDocument(colName, value, true, false); |
185 |
| - assertThat(res.getRequestId(), is("request" + (i + 1 - 20))); |
186 |
| - } |
| 176 | + driver.startBatchMode(); |
187 | 177 |
|
188 |
| - driver.executeBatch(); |
| 178 | + for (int i = 20; i < 30; i++) { |
| 179 | + TestComplexEntity01 value = new TestComplexEntity01("user-" + i, "data:" + i, i); |
| 180 | + res = driver.createDocument(colName, value, true, false); |
| 181 | + assertThat(res.getRequestId(), is("request" + (i + 1 - 20))); |
| 182 | + } |
189 | 183 |
|
190 |
| - assertThat(driver.getDocuments(colName).size(), is(20)); |
| 184 | + driver.executeBatch(); |
191 | 185 |
|
192 |
| - } |
193 |
| - |
194 |
| -} |
| 186 | + assertThat(driver.getDocuments(colName).size(), is(20)); |
195 | 187 |
|
| 188 | + } |
196 | 189 |
|
| 190 | +} |
0 commit comments