36
36
import com .mongodb .client .MongoCollection ;
37
37
import com .mongodb .client .MongoCursor ;
38
38
import com .mongodb .client .model .Sorts ;
39
+ import com .mongodb .client .result .InsertManyResult ;
39
40
import lombok .extern .slf4j .Slf4j ;
40
41
41
42
import java .time .Duration ;
@@ -60,6 +61,9 @@ public abstract class AbstractMongodbIT extends TestSuiteBase implements TestRes
60
61
61
62
protected static final List <Document > TEST_NULL_DATASET = generateTestDataSetWithNull (10 );
62
63
64
+ protected static final List <Document > TEST_DOUBLE_DATASET =
65
+ generateTestDataSetWithPresets (5 , Arrays .asList (44.0d , 44.1d , 44.2d , 44.3d , 44.4d ));
66
+
63
67
protected static final String MONGODB_IMAGE = "mongo:latest" ;
64
68
65
69
protected static final String MONGODB_CONTAINER_HOST = "e2e_mongodb" ;
@@ -76,6 +80,10 @@ public abstract class AbstractMongodbIT extends TestSuiteBase implements TestRes
76
80
77
81
protected static final String MONGODB_NULL_TABLE_RESULT = "test_null_op_db_result" ;
78
82
83
+ protected static final String MONGODB_DOUBLE_TABLE = "test_double_op_db" ;
84
+
85
+ protected static final String MONGODB_DOUBLE_TABLE_RESULT = "test_double_op_db_result" ;
86
+
79
87
protected static final String MONGODB_MATCH_RESULT_TABLE = "test_match_op_result_db" ;
80
88
81
89
protected static final String MONGODB_SPLIT_RESULT_TABLE = "test_split_op_result_db" ;
@@ -105,20 +113,10 @@ public void initConnection() {
105
113
}
106
114
107
115
protected void initSourceData () {
108
- MongoCollection <Document > sourceMatchTable =
109
- client .getDatabase (MONGODB_DATABASE ).getCollection (MONGODB_MATCH_TABLE );
110
- sourceMatchTable .deleteMany (new Document ());
111
- sourceMatchTable .insertMany (TEST_MATCH_DATASET );
112
-
113
- MongoCollection <Document > sourceSplitTable =
114
- client .getDatabase (MONGODB_DATABASE ).getCollection (MONGODB_SPLIT_TABLE );
115
- sourceSplitTable .deleteMany (new Document ());
116
- sourceSplitTable .insertMany (TEST_SPLIT_DATASET );
117
-
118
- MongoCollection <Document > sourceNullTable =
119
- client .getDatabase (MONGODB_DATABASE ).getCollection (MONGODB_NULL_TABLE );
120
- sourceNullTable .deleteMany (new Document ());
121
- sourceNullTable .insertMany (TEST_NULL_DATASET );
116
+ prepareInitDataInCollection (MONGODB_MATCH_TABLE , TEST_MATCH_DATASET );
117
+ prepareInitDataInCollection (MONGODB_SPLIT_TABLE , TEST_SPLIT_DATASET );
118
+ prepareInitDataInCollection (MONGODB_NULL_TABLE , TEST_NULL_DATASET );
119
+ prepareInitDataInCollection (MONGODB_DOUBLE_TABLE , TEST_DOUBLE_DATASET );
122
120
}
123
121
124
122
protected void clearDate (String table ) {
@@ -129,51 +127,7 @@ public static List<Document> generateTestDataSet(int count) {
129
127
List <Document > dataSet = new ArrayList <>();
130
128
131
129
for (int i = 0 ; i < count ; i ++) {
132
- dataSet .add (
133
- new Document (
134
- "c_map" ,
135
- new Document ("OQBqH" , randomString ())
136
- .append ("rkvlO" , randomString ())
137
- .append ("pCMEX" , randomString ())
138
- .append ("DAgdj" , randomString ())
139
- .append ("dsJag" , randomString ()))
140
- .append (
141
- "c_array" ,
142
- Arrays .asList (
143
- RANDOM .nextInt (),
144
- RANDOM .nextInt (),
145
- RANDOM .nextInt (),
146
- RANDOM .nextInt (),
147
- RANDOM .nextInt ()))
148
- .append ("c_string" , randomString ())
149
- .append ("c_boolean" , RANDOM .nextBoolean ())
150
- .append ("c_int" , i )
151
- .append ("c_bigint" , RANDOM .nextLong ())
152
- .append ("c_double" , RANDOM .nextDouble () * Double .MAX_VALUE )
153
- .append (
154
- "c_row" ,
155
- new Document (
156
- "c_map" ,
157
- new Document ("OQBqH" , randomString ())
158
- .append ("rkvlO" , randomString ())
159
- .append ("pCMEX" , randomString ())
160
- .append ("DAgdj" , randomString ())
161
- .append ("dsJag" , randomString ()))
162
- .append (
163
- "c_array" ,
164
- Arrays .asList (
165
- RANDOM .nextInt (),
166
- RANDOM .nextInt (),
167
- RANDOM .nextInt (),
168
- RANDOM .nextInt (),
169
- RANDOM .nextInt ()))
170
- .append ("c_string" , randomString ())
171
- .append ("c_boolean" , RANDOM .nextBoolean ())
172
- .append ("c_int" , RANDOM .nextInt ())
173
- .append ("c_bigint" , RANDOM .nextLong ())
174
- .append (
175
- "c_double" ,
176
- RANDOM .nextDouble () * Double .MAX_VALUE )));
130
+ dataSet .add (generateData (i , RANDOM .nextDouble () * Double .MAX_VALUE ));
177
131
}
178
132
return dataSet ;
179
133
}
@@ -195,6 +149,17 @@ public static List<Document> generateTestDataSetWithNull(int count) {
195
149
return dataSet ;
196
150
}
197
151
152
+ public static List <Document > generateTestDataSetWithPresets (
153
+ int count , List <Double > doublePresets ) {
154
+ List <Document > dataSet = new ArrayList <>(count );
155
+
156
+ for (int i = 0 ; i < count ; i ++) {
157
+ dataSet .add (generateData (i , doublePresets .get (i )));
158
+ }
159
+
160
+ return dataSet ;
161
+ }
162
+
198
163
protected static String randomString () {
199
164
int length = RANDOM .nextInt (10 ) + 1 ;
200
165
StringBuilder sb = new StringBuilder (length );
@@ -205,6 +170,63 @@ protected static String randomString() {
205
170
return sb .toString ();
206
171
}
207
172
173
+ private static Document generateData (int intPreset , Double doublePreset ) {
174
+ return new Document (
175
+ "c_map" ,
176
+ new Document ("OQBqH" , randomString ())
177
+ .append ("rkvlO" , randomString ())
178
+ .append ("pCMEX" , randomString ())
179
+ .append ("DAgdj" , randomString ())
180
+ .append ("dsJag" , randomString ()))
181
+ .append (
182
+ "c_array" ,
183
+ Arrays .asList (
184
+ RANDOM .nextInt (),
185
+ RANDOM .nextInt (),
186
+ RANDOM .nextInt (),
187
+ RANDOM .nextInt (),
188
+ RANDOM .nextInt ()))
189
+ .append ("c_string" , randomString ())
190
+ .append ("c_boolean" , RANDOM .nextBoolean ())
191
+ .append ("c_int" , intPreset )
192
+ .append ("c_bigint" , RANDOM .nextLong ())
193
+ .append ("c_double" , doublePreset )
194
+ .append (
195
+ "c_row" ,
196
+ new Document (
197
+ "c_map" ,
198
+ new Document ("OQBqH" , randomString ())
199
+ .append ("rkvlO" , randomString ())
200
+ .append ("pCMEX" , randomString ())
201
+ .append ("DAgdj" , randomString ())
202
+ .append ("dsJag" , randomString ()))
203
+ .append (
204
+ "c_array" ,
205
+ Arrays .asList (
206
+ RANDOM .nextInt (),
207
+ RANDOM .nextInt (),
208
+ RANDOM .nextInt (),
209
+ RANDOM .nextInt (),
210
+ RANDOM .nextInt ()))
211
+ .append ("c_string" , randomString ())
212
+ .append ("c_boolean" , RANDOM .nextBoolean ())
213
+ .append ("c_int" , RANDOM .nextInt ())
214
+ .append ("c_bigint" , RANDOM .nextLong ())
215
+ .append ("c_double" , RANDOM .nextDouble () * Double .MAX_VALUE ));
216
+ }
217
+
218
+ private void prepareInitDataInCollection (String collection , List <Document > dataSet ) {
219
+ MongoCollection <Document > source =
220
+ client .getDatabase (MONGODB_DATABASE ).getCollection (collection );
221
+ source .deleteMany (new Document ());
222
+
223
+ InsertManyResult result = source .insertMany (dataSet );
224
+
225
+ if (result .getInsertedIds ().size () != dataSet .size ()) {
226
+ throw new IllegalStateException ("Insertion count mismatch" );
227
+ }
228
+ }
229
+
208
230
protected List <Document > readMongodbData (String collection ) {
209
231
MongoCollection <Document > sinkTable =
210
232
client .getDatabase (MONGODB_DATABASE ).getCollection (collection );
0 commit comments