@@ -43,43 +43,57 @@ public class PutCQLTest {
43
43
44
44
// Helper
45
45
// https://medium.com/@mr.sinchan.banerjee/nifi-custom-processor-series-part-3-junit-test-with-nifi-mock-a935a1a4e3e5
46
- private void addTestScope (TestRunner testRunner , CQLControllerService testService , String propertyFile ) throws IOException {
47
- TestSetup itm ;
46
+ public PutCQLTest () throws IOException , InterruptedException , InitializationException {
47
+
48
+ // create TestSetup
49
+ setups =CreateSetup ();
48
50
49
- itm = TestSetup .getInstance (testRunner , testService , propertyFile );
50
- if (itm !=null ) {
51
- setups .add (itm );
52
- testRunner .getLogger ().info ("Test scope: '{}'" , itm .name );
51
+ // build schema, if needed
52
+ TestRunner runner = TestRunners .newTestRunner (PutCQL .class );
53
+ CQLControllerService service = new CQLControllerService ();
54
+ runner .addControllerService (PutCQL .SERVICE_CONTROLLER .getName (), service );
55
+ for (TestSetup setup : setups ) {
56
+ setup .setProperty (runner , service );
57
+ runner .enableControllerService (service );
58
+ try (CqlSession session =service .getSession ()) {
59
+ CqlCreateSchema schema = new CqlCreateSchema (session , setup );
60
+ schema .Create ();
61
+ }
62
+ runner .disableControllerService (service );
53
63
}
54
64
}
55
65
66
+ private ArrayList <TestSetup > CreateSetup () throws IOException {
67
+ ArrayList <TestSetup > setup = new ArrayList <TestSetup >();
68
+
69
+ addTestScope (setup ,
70
+ TestSetup .getTestPropertyFile ("./src/test" ,
71
+ new String []{"test-cassandra.json" , "test-properties.json" }));
72
+ addTestScope (setup ,
73
+ TestSetup .getTestPropertyFile ("./src/test" ,
74
+ new String []{"test-scylla.json" , "test-properties.json" }));
75
+ addTestScope (setup ,
76
+ TestSetup .getTestPropertyFile ("./src/test" ,
77
+ new String []{"test-astra.json" , "test-properties.json" }));
78
+ return setup ;
79
+ }
80
+
81
+ private void addTestScope (List <TestSetup > setup , String propertyFile ) throws IOException {
82
+ TestSetup itm ;
83
+
84
+ itm = TestSetup .getInstance (propertyFile );
85
+ if (itm !=null ) setup .add (itm );
86
+ }
87
+
56
88
@ BeforeEach
57
89
public void init () throws IOException , InterruptedException , InitializationException {
58
90
testRunner = TestRunners .newTestRunner (PutCQL .class );
59
91
testService = new CQLControllerService ();
60
92
testRunner .addControllerService (PutCQL .SERVICE_CONTROLLER .getName (), testService );
61
93
62
- if (setups == null ) {
63
- setups = new ArrayList <TestSetup >();
64
-
65
- addTestScope (testRunner , testService ,
66
- TestSetup .getTestPropertyFile ("./src/test" ,
67
- new String []{"test-cassandra.json" , "test-properties.json" }));
68
- addTestScope (testRunner , testService ,
69
- TestSetup .getTestPropertyFile ("./src/test" ,
70
- new String []{"test-scylla.json" , "test-properties.json" }));
71
- addTestScope (testRunner , testService ,
72
- TestSetup .getTestPropertyFile ("./src/test" ,
73
- new String []{"test-astra.json" , "test-properties.json" }));
94
+ for (TestSetup setup : setups ) {
95
+ System .out .println (String .format ("Test scope: '%s'" , setup .name ));
74
96
}
75
-
76
- // // build schema
77
- // for (TestSetup setup: setups) {
78
- // CqlSession session=null;
79
- // CqlCreateSchema schema = new CqlCreateSchema(session, setup);
80
- // schema.Create();
81
- // }
82
-
83
97
}
84
98
85
99
private FlowFile coreTest (){
@@ -128,7 +142,7 @@ public void testBasic() {
128
142
attributes .put ("CQLName" , setup .name );
129
143
130
144
testRunner .enqueue (content , attributes );
131
- setup .setProperty ();
145
+ setup .setProperty (testRunner , testService );
132
146
testRunner .enableControllerService (testService );
133
147
result = coreTest ();
134
148
testRunner .disableControllerService (testService );
@@ -139,8 +153,7 @@ public void testBasic() {
139
153
}
140
154
141
155
@ Test
142
- public void testBatchTypes () {
143
-
156
+ public void testBatchLoggedTypes () {
144
157
HashMap <String , String > attributes = new HashMap <String , String >();
145
158
146
159
String content = "\" colbigint\" ,\" colint\" ,\" coltext\" ,\" colfloat\" ,\" coldouble\" ,\" coldate\" ,\" coltime\" ,\" coltimestamp\" ,\" colboolean\" ,\" coluuid\" ,\" colsmallint\" ,\" coltinyint\" ,\" coltimeuuid\" ,\" colvarchar\" \n " +
@@ -155,19 +168,35 @@ public void testBatchTypes() {
155
168
156
169
// batch type LOGGED
157
170
testRunner .enqueue (content , attributes );
158
- setup .setProperty ();
159
- setup .setProperty (PutCQL .BATCH_TYPE , PutCQL .BT_LOGGED .getValue ());
171
+ setup .setProperty (testRunner , testService );
172
+ setup .setProperty (testRunner , PutCQL .BATCH_TYPE , PutCQL .BT_LOGGED .getValue ());
160
173
testRunner .enableControllerService (testService );
161
174
result = coreTest ();
162
175
testRunner .disableControllerService (testService );
163
176
// check amount of write items
164
177
assertNotNull (result , String .format ("Issue with processing in '%s'" , setup .name ));
165
178
assertEquals (4 , Long .parseLong (result .getAttribute (PutCQL .ATTRIBUTE_COUNT )));
179
+ }
180
+ }
181
+
182
+ @ Test
183
+ public void testBatchUnLoggedTypes () {
184
+ HashMap <String , String > attributes = new HashMap <String , String >();
185
+
186
+ String content = "\" colbigint\" ,\" colint\" ,\" coltext\" ,\" colfloat\" ,\" coldouble\" ,\" coldate\" ,\" coltime\" ,\" coltimestamp\" ,\" colboolean\" ,\" coluuid\" ,\" colsmallint\" ,\" coltinyint\" ,\" coltimeuuid\" ,\" colvarchar\" \n " +
187
+ "\" 0\" ,\" 1064\" ,\" zeVOKGnORq\" ,\" 627.6811\" ,\" 395.8522407512559\" ,\" 1971-11-12\" ,\" 03:37:15\" ,\" 2000-09-25T22:18:45Z\" ,\" false\" ,\" 6080071f-4dd1-4ea5-b711-9ad0716e242a\" ,\" 8966\" ,\" 55\" ,\" f45e58f5-c3b7-11ef-8d19-97ae87be7c54\" ,\" Tzxsw\" \n " +
188
+ "\" 1\" ,\" 1709\" ,\" 7By0z5QEXh\" ,\" 652.03955\" ,\" 326.9081263857284\" ,\" 2013-12-17\" ,\" 08:43:09\" ,\" 2010-04-27T07:02:27Z\" ,\" false\" ,\" 7d511666-2f81-41c4-9d5c-a5fa87f7d1c3\" ,\" 24399\" ,\" 38\" ,\" f45e8006-c3b7-11ef-8d19-172ff8d0d752\" ,\" exAbN\" \n " +
189
+ "\" 2\" ,\" 6249\" ,\" UYI6AgkcBt\" ,\" 939.01556\" ,\" 373.48559413289485\" ,\" 1980-11-05\" ,\" 15:44:43\" ,\" 2023-11-24T05:59:12Z\" ,\" false\" ,\" dbd35d1b-38d0-49a4-8069-9efd68314dc5\" ,\" 6918\" ,\" 72\" ,\" f45e8007-c3b7-11ef-8d19-d784fa8af8e3\" ,\" IjnDb\" \n " +
190
+ "\" 3\" ,\" 6998\" ,\" lXQ69C5HOZ\" ,\" 715.1224\" ,\" 236.7994939033784\" ,\" 1992-02-01\" ,\" 08:07:34\" ,\" 2024-06-29T21:08:54.463Z\" ,\" true\" ,\" 84a7395c-94fd-43f5-84c6-4152f0407e93\" ,\" 22123\" ,\" 39\" ,\" f45e8008-c3b7-11ef-8d19-0376318d55df\" ,\" jyZo8\" \n " ;
191
+ FlowFile result ;
192
+
193
+ for (TestSetup setup : setups ) {
194
+ attributes .put ("CQLName" , setup .name );
166
195
167
196
// batch type UNLOGGED
168
197
testRunner .enqueue (content , attributes );
169
- setup .setProperty ();
170
- setup .setProperty (PutCQL .BATCH_TYPE , PutCQL .BT_UNLOGGED .getValue ());
198
+ setup .setProperty (testRunner , testService );
199
+ setup .setProperty (testRunner , PutCQL .BATCH_TYPE , PutCQL .BT_UNLOGGED .getValue ());
171
200
testRunner .enableControllerService (testService );
172
201
result = coreTest ();
173
202
testRunner .disableControllerService (testService );
@@ -200,17 +229,16 @@ public void testMoreItems() {
200
229
attributes .put ("CQLName" ,setup .name );
201
230
202
231
testRunner .enqueue (content , attributes );
203
- setup .setProperty ();
232
+ setup .setProperty (testRunner , testService );
204
233
testRunner .enableControllerService (testService );
205
234
result = coreTest ();
206
235
testRunner .disableControllerService (testService );
207
236
// check amount of write items
208
237
assertNotNull (result , String .format ("Issue with processing in '%s'" , setup .name ));
209
238
assertEquals (5 , Long .parseLong (result .getAttribute (PutCQL .ATTRIBUTE_COUNT )));
210
239
211
-
212
240
testRunner .enqueue (content2 , attributes );
213
- setup .setProperty ();
241
+ setup .setProperty (testRunner , testService );
214
242
testRunner .enableControllerService (testService );
215
243
result = coreTest ();
216
244
testRunner .disableControllerService (testService );
@@ -225,10 +253,6 @@ public void testNoQuotas() {
225
253
HashMap <String , String > attributes = new HashMap <String , String >();
226
254
227
255
String content = "colbigint,colint,coltext,colfloat,coldouble,coldate,coltime,coltimestamp,colboolean,coluuid,colsmallint,coltinyint,coltimeuuid,colvarchar\n " +
228
- "0,1064,zeVOKGnORq,627.6811,395.8522407512559,1971-11-12,03:37:15,2000-09-25T22:18:45Z,false,6080071f-4dd1-4ea5-b711-9ad0716e242a,8966,55,f45e58f5-c3b7-11ef-8d19-97ae87be7c54,Tzxsw\n " +
229
- "1,1709,7By0z5QEXh,652.03955,326.9081263857284,2013-12-17,08:43:09,2010-04-27T07:02:27Z,false,7d511666-2f81-41c4-9d5c-a5fa87f7d1c3,24399,38,f45e8006-c3b7-11ef-8d19-172ff8d0d752,exAbN\n " ;
230
-
231
- String content2 = "colbigint,colint,coltext,colfloat,coldouble,coldate,coltime,coltimestamp,colboolean,coluuid,colsmallint,coltinyint,coltimeuuid,colvarchar\n " +
232
256
"10,1064,zeVOKGnORq,627.6811,395.8522407512559,1971-11-12,03:37:15,2000-09-25T22:18:45Z,false,6080071f-4dd1-4ea5-b711-9ad0716e242a,8966,55,f45e58f5-c3b7-11ef-8d19-97ae87be7c54,Tzxsw\n " +
233
257
"11,1709,7By0z5QEXh,652.03955,326.9081263857284,2013-12-17,08:43:09,2010-04-27T07:02:27Z,false,7d511666-2f81-41c4-9d5c-a5fa87f7d1c3,24399,38,f45e8006-c3b7-11ef-8d19-172ff8d0d752,exAbN\n " +
234
258
"12,6249,UYI6AgkcBt,939.01556,373.48559413289485,1980-11-05,15:44:43,2023-11-24T05:59:12Z,false,dbd35d1b-38d0-49a4-8069-9efd68314dc5,6918,72,f45e8007-c3b7-11ef-8d19-d784fa8af8e3,IjnDb\n " +
@@ -239,25 +263,7 @@ public void testNoQuotas() {
239
263
attributes .put ("CQLName" , setup .name );
240
264
241
265
testRunner .enqueue (content , attributes );
242
- setup .setProperty ();
243
- testRunner .enableControllerService (testService );
244
- result = coreTest ();
245
- testRunner .disableControllerService (testService );
246
- // check amount of write items
247
- assertNotNull (result , String .format ("Issue with processing in '%s'" , setup .name ));
248
- assertEquals (2 , Long .parseLong (result .getAttribute (PutCQL .ATTRIBUTE_COUNT )));
249
-
250
- testRunner .enqueue (content , attributes );
251
- setup .setProperty ();
252
- testRunner .enableControllerService (testService );
253
- result = coreTest ();
254
- testRunner .disableControllerService (testService );
255
- // check amount of write items
256
- assertNotNull (result , String .format ("Issue with processing in '%s'" , setup .name ));
257
- assertEquals (2 , Long .parseLong (result .getAttribute (PutCQL .ATTRIBUTE_COUNT )));
258
-
259
- testRunner .enqueue (content2 , attributes );
260
- setup .setProperty ();
266
+ setup .setProperty (testRunner , testService );
261
267
testRunner .enableControllerService (testService );
262
268
result = coreTest ();
263
269
testRunner .disableControllerService (testService );
@@ -277,7 +283,7 @@ public void testEmptyInput() {
277
283
attributes .put ("CQLName" , setup .name );
278
284
279
285
testRunner .enqueue (content , attributes );
280
- setup .setProperty ();
286
+ setup .setProperty (testRunner , testService );
281
287
testRunner .enableControllerService (testService );
282
288
result = coreTest ();
283
289
testRunner .disableControllerService (testService );
@@ -297,7 +303,7 @@ public void testOnlyHeader() {
297
303
attributes .put ("CQLName" , setup .name );
298
304
299
305
testRunner .enqueue (content , attributes );
300
- setup .setProperty ();
306
+ setup .setProperty (testRunner , testService );
301
307
testRunner .enableControllerService (testService );
302
308
result = coreTest ();
303
309
testRunner .disableControllerService (testService );
@@ -317,7 +323,7 @@ public void testOnlyHeaderNoQuotas() {
317
323
attributes .put ("CQLName" , setup .name );
318
324
319
325
testRunner .enqueue (content , attributes );
320
- setup .setProperty ();
326
+ setup .setProperty (testRunner , testService );
321
327
testRunner .enableControllerService (testService );
322
328
result = coreTest ();
323
329
testRunner .disableControllerService (testService );
@@ -340,7 +346,7 @@ public void testBasicRepeat5() {
340
346
for (TestSetup setup : setups ) {
341
347
attributes .put ("CQLName" , setup .name );
342
348
343
- setup .setProperty ();
349
+ setup .setProperty (testRunner , testService );
344
350
testRunner .enableControllerService (testService );
345
351
for (int i = 0 ; i < 5 ; i ++) {
346
352
testRunner .enqueue (content , attributes );
@@ -367,7 +373,7 @@ public void testNoQuotas2() {
367
373
attributes .put ("CQLName" , setup .name );
368
374
369
375
testRunner .enqueue (content , attributes );
370
- setup .setProperty ();
376
+ setup .setProperty (testRunner , testService );
371
377
testRunner .enableControllerService (testService );
372
378
result = coreTest ();
373
379
testRunner .disableControllerService (testService );
0 commit comments