|
99 | 99 | import java.util.Locale;
|
100 | 100 | import java.util.Map;
|
101 | 101 | import java.util.Optional;
|
| 102 | +import java.util.concurrent.CountDownLatch; |
102 | 103 | import java.util.concurrent.ExecutionException;
|
103 | 104 | import java.util.concurrent.TimeUnit;
|
104 | 105 | import java.util.stream.Collectors;
|
@@ -1148,4 +1149,84 @@ private String createDataStream() throws Exception {
|
1148 | 1149 | assertAcked(client().execute(CreateDataStreamAction.INSTANCE, new CreateDataStreamAction.Request(dataStreamName)).get());
|
1149 | 1150 | return dataStreamName;
|
1150 | 1151 | }
|
| 1152 | + |
| 1153 | + public void testConcurrentRollup() throws IOException, InterruptedException { |
| 1154 | + final DownsampleConfig config = new DownsampleConfig(randomInterval()); |
| 1155 | + SourceSupplier sourceSupplier = () -> { |
| 1156 | + String ts = randomDateForInterval(config.getInterval()); |
| 1157 | + double labelDoubleValue = DATE_FORMATTER.parseMillis(ts); |
| 1158 | + int labelIntegerValue = randomInt(); |
| 1159 | + long labelLongValue = randomLong(); |
| 1160 | + String labelIpv4Address = NetworkAddress.format(randomIp(true)); |
| 1161 | + String labelIpv6Address = NetworkAddress.format(randomIp(false)); |
| 1162 | + Date labelDateValue = randomDate(); |
| 1163 | + int keywordArraySize = randomIntBetween(2, 5); |
| 1164 | + String[] keywordArray = new String[keywordArraySize]; |
| 1165 | + for (int i = 0; i < keywordArraySize; ++i) { |
| 1166 | + keywordArray[i] = randomAlphaOfLength(10); |
| 1167 | + } |
| 1168 | + int doubleArraySize = randomIntBetween(3, 10); |
| 1169 | + double[] doubleArray = new double[doubleArraySize]; |
| 1170 | + for (int i = 0; i < doubleArraySize; ++i) { |
| 1171 | + doubleArray[i] = randomDouble(); |
| 1172 | + } |
| 1173 | + return XContentFactory.jsonBuilder() |
| 1174 | + .startObject() |
| 1175 | + .field(FIELD_TIMESTAMP, ts) |
| 1176 | + .field(FIELD_DIMENSION_1, randomFrom(dimensionValues)) |
| 1177 | + .field(FIELD_DIMENSION_2, randomIntBetween(1, 10)) |
| 1178 | + .field(FIELD_NUMERIC_1, randomInt()) |
| 1179 | + .field(FIELD_NUMERIC_2, DATE_FORMATTER.parseMillis(ts)) |
| 1180 | + .startObject(FIELD_AGG_METRIC) |
| 1181 | + .field("min", randomDoubleBetween(-2000, -1001, true)) |
| 1182 | + .field("max", randomDoubleBetween(-1000, 1000, true)) |
| 1183 | + .field("sum", randomIntBetween(100, 10000)) |
| 1184 | + .field("value_count", randomIntBetween(100, 1000)) |
| 1185 | + .endObject() |
| 1186 | + .field(FIELD_LABEL_DOUBLE, labelDoubleValue) |
| 1187 | + .field(FIELD_METRIC_LABEL_DOUBLE, labelDoubleValue) |
| 1188 | + .field(FIELD_LABEL_INTEGER, labelIntegerValue) |
| 1189 | + .field(FIELD_LABEL_KEYWORD, ts) |
| 1190 | + .field(FIELD_LABEL_UNMAPPED, randomBoolean() ? labelLongValue : labelDoubleValue) |
| 1191 | + .field(FIELD_LABEL_TEXT, ts) |
| 1192 | + .field(FIELD_LABEL_BOOLEAN, randomBoolean()) |
| 1193 | + .field(FIELD_LABEL_IPv4_ADDRESS, labelIpv4Address) |
| 1194 | + .field(FIELD_LABEL_IPv6_ADDRESS, labelIpv6Address) |
| 1195 | + .field(FIELD_LABEL_DATE, labelDateValue) |
| 1196 | + .field(FIELD_LABEL_KEYWORD_ARRAY, keywordArray) |
| 1197 | + .field(FIELD_LABEL_DOUBLE_ARRAY, doubleArray) |
| 1198 | + .startObject(FIELD_LABEL_AGG_METRIC) |
| 1199 | + .field("min", randomDoubleBetween(-2000, -1001, true)) |
| 1200 | + .field("max", randomDoubleBetween(-1000, 1000, true)) |
| 1201 | + .field("sum", Double.valueOf(randomIntBetween(100, 10000))) |
| 1202 | + .field("value_count", randomIntBetween(100, 1000)) |
| 1203 | + .endObject() |
| 1204 | + .endObject(); |
| 1205 | + }; |
| 1206 | + docCount = 512; // Hard code to have 512 documents in the source index, otherwise running this test take too long. |
| 1207 | + bulkIndex(sourceIndex, sourceSupplier); |
| 1208 | + prepareSourceIndex(sourceIndex); |
| 1209 | + |
| 1210 | + int n = randomIntBetween(3, 6); |
| 1211 | + final CountDownLatch rollupComplete = new CountDownLatch(n); |
| 1212 | + final List<String> targets = new ArrayList<>(); |
| 1213 | + final List<Thread> threads = new ArrayList<>(); |
| 1214 | + for (int i = 0; i < n; i++) { |
| 1215 | + final String targetIndex = randomAlphaOfLength(10).toLowerCase(Locale.ROOT); |
| 1216 | + targets.add(targetIndex); |
| 1217 | + threads.add(new Thread(() -> { |
| 1218 | + rollup(sourceIndex, targetIndex, config); |
| 1219 | + rollupComplete.countDown(); |
| 1220 | + })); |
| 1221 | + } |
| 1222 | + for (int i = 0; i < n; i++) { |
| 1223 | + threads.get(i).start(); |
| 1224 | + } |
| 1225 | + |
| 1226 | + assertTrue(rollupComplete.await(30, TimeUnit.SECONDS)); |
| 1227 | + |
| 1228 | + for (int i = 0; i < n; i++) { |
| 1229 | + assertRollupIndex(sourceIndex, targets.get(i), config); |
| 1230 | + } |
| 1231 | + } |
1151 | 1232 | }
|
0 commit comments