@@ -70,10 +70,18 @@ protected MockFlowFile runTest(TestSetupRead setup) throws Exception {
70
70
return runTestWithProperty (setup , null , null , null , false );
71
71
}
72
72
73
+ protected List <MockFlowFile > runTestParallel (TestSetupRead setup , int parallel ) throws Exception {
74
+ return runTestParallelWithProperty (setup , null , null , null , false , parallel );
75
+ }
76
+
73
77
protected MockFlowFile runTest (TestSetupRead setup , String content ) throws Exception {
74
78
return runTestWithProperty (setup , content , null , null , false );
75
79
}
76
80
81
+ protected List <MockFlowFile > runTestParallel (TestSetupRead setup , String content , int parallel ) throws Exception {
82
+ return runTestParallelWithProperty (setup , content , null , null , false , parallel );
83
+ }
84
+
77
85
protected MockFlowFile runTest (TestSetupRead setup , String content , boolean validate ) throws Exception {
78
86
return runTestWithProperty (setup , content , null , null , validate );
79
87
}
@@ -96,6 +104,63 @@ protected MockFlowFile runTestWithProperty(TestSetupRead setup, String content,
96
104
return result ;
97
105
}
98
106
107
+ protected List <MockFlowFile > runTestParallelWithProperty (TestSetupRead setup , String content , PropertyDescriptor property , String propertyValue , boolean validate , int parallel ) throws Exception {
108
+ List <MockFlowFile > results ;
109
+
110
+ if (content !=null )
111
+ for (int i =0 ;i <parallel ;i ++)
112
+ testRunner .enqueue (content );
113
+ setup .setProperty (testRunner , testService );
114
+ if (property != null )
115
+ setup .setProperty (testRunner , property , propertyValue );
116
+ testRunner .enableControllerService (testService );
117
+ if (parallel >1 )
118
+ testRunner .setThreadCount (parallel );
119
+ results = coreTestParallel (setup , content , validate , parallel );
120
+ testRunner .disableControllerService (testService );
121
+ return results ;
122
+ }
123
+
124
+ private void printResult (MockFlowFile result , TestSetupRead setup , long start , long finish ){
125
+ long countWrite ;
126
+
127
+ countWrite = Long .parseLong (result .getAttribute (CQLAttributes .READ_COUNT ));
128
+ System .out .printf ("Source: '%s'; READ; '%s': %s (%d ms); Items: %d; Perf: %.1f [calls/sec]%s" ,
129
+ setup .name ,
130
+ "FlowFile" ,
131
+ ReadableValue .fromMillisecond (finish - start ),
132
+ finish - start ,
133
+ countWrite ,
134
+ countWrite / ((finish - start ) / 1000.0 ),
135
+ System .lineSeparator ());
136
+ }
137
+
138
+ private List <MockFlowFile > coreTestParallel (TestSetupRead setup , String content , boolean validate , int parallel ) throws Exception {
139
+ try {
140
+ long finish , start , countWrite ;
141
+ List <MockFlowFile > results ;
142
+ boolean ok ;
143
+
144
+ start = System .currentTimeMillis ();
145
+ testRunner .run (parallel );
146
+ if (!testRunner .getFlowFilesForRelationship (PutCQL .REL_SUCCESS ).isEmpty ()) {
147
+ results = testRunner .getFlowFilesForRelationship (PutCQL .REL_SUCCESS );
148
+ ok = testRunner .getFlowFilesForRelationship (PutCQL .REL_FAILURE ).isEmpty ();
149
+ finish = System .currentTimeMillis ();
150
+
151
+ if (ok ) {
152
+ for (MockFlowFile result : results )
153
+ printResult (result , setup , start , finish );
154
+ return results ;
155
+ }
156
+ }
157
+ }
158
+ catch (Exception ex ) {
159
+ throw new Exception ("Error in PROCESSOR" );
160
+ }
161
+ return null ;
162
+ }
163
+
99
164
private MockFlowFile coreTest (TestSetupRead setup , String content , boolean validate ) throws Exception {
100
165
try {
101
166
long finish , start , countWrite ;
@@ -110,15 +175,7 @@ private MockFlowFile coreTest(TestSetupRead setup, String content, boolean valid
110
175
finish = System .currentTimeMillis ();
111
176
112
177
if (ok ) {
113
- countWrite = Long .parseLong (result .getAttribute (CQLAttributes .READ_COUNT ));
114
- System .out .printf ("Source: '%s'; READ; '%s': %s (%d ms); Items: %d; Perf: %.1f [calls/sec]%s" ,
115
- setup .name ,
116
- "FlowFile" ,
117
- ReadableValue .fromMillisecond (finish - start ),
118
- finish - start ,
119
- countWrite ,
120
- countWrite / ((finish - start ) / 1000.0 ),
121
- System .lineSeparator ());
178
+ printResult (result , setup , start , finish );
122
179
return result ;
123
180
}
124
181
}
0 commit comments