|
46 | 46 | import stroom.test.AbstractCoreIntegrationTest;
|
47 | 47 | import stroom.test.CommonTestControl;
|
48 | 48 | import stroom.test.CommonTestScenarioCreator;
|
| 49 | +import stroom.util.io.FileUtil; |
49 | 50 | import stroom.util.shared.ResultPage;
|
50 | 51 | import stroom.util.shared.Selection;
|
51 | 52 |
|
|
57 | 58 | import java.io.IOException;
|
58 | 59 | import java.nio.file.Files;
|
59 | 60 | import java.nio.file.Path;
|
| 61 | +import java.nio.file.Paths; |
60 | 62 | import java.nio.file.attribute.PosixFilePermission;
|
| 63 | +import java.util.List; |
61 | 64 | import java.util.Set;
|
62 | 65 |
|
63 | 66 | import static org.assertj.core.api.Assertions.assertThat;
|
@@ -373,6 +376,87 @@ void testPerformance() {
|
373 | 376 | }
|
374 | 377 | }
|
375 | 378 |
|
| 379 | + @Test |
| 380 | + void testDelete() { |
| 381 | + assertThat(indexShardDao.find(FindIndexShardCriteria.matchAll()).size()).isZero(); |
| 382 | + |
| 383 | + final DocRef indexRef1 = commonTestScenarioCreator.createIndex("TEST_2010", |
| 384 | + commonTestScenarioCreator.createIndexFields(), |
| 385 | + 1000000); |
| 386 | + final LuceneIndexDoc index1 = indexStore.readDocument(indexRef1); |
| 387 | + final IndexShardKey indexShardKey1 = IndexShardKey.createKey(index1); |
| 388 | + |
| 389 | + final IndexDocument document1 = new IndexDocument(); |
| 390 | + document1.add(new FieldValue(LuceneIndexField |
| 391 | + .builder() |
| 392 | + .fldName("SourcePort") |
| 393 | + .fldType(FieldType.TEXT) |
| 394 | + .analyzerType(AnalyzerType.ALPHA_NUMERIC) |
| 395 | + .termPositions(false) |
| 396 | + .indexed(true) |
| 397 | + .stored(false) |
| 398 | + .build(), ValString.create("12345"))); |
| 399 | + |
| 400 | + final Selection<IndexShardStatus> deleted = Selection.selectNone(); |
| 401 | + deleted.add(IndexShardStatus.DELETED); |
| 402 | + final FindIndexShardCriteria findDeleted = FindIndexShardCriteria.builder() |
| 403 | + .indexShardStatusSet(deleted).build(); |
| 404 | + |
| 405 | + for (int j = 0; j < 10; j++) { |
| 406 | + // Delete every shard. |
| 407 | + indexShardManager.performAction(FindIndexShardCriteria.matchAll(), IndexShardAction.DELETE); |
| 408 | + assertThat(indexShardDao.find(FindIndexShardCriteria.matchAll()).size()).isEqualTo(j); |
| 409 | + assertThat(indexShardDao.find(findDeleted).size()).isEqualTo(j); |
| 410 | + |
| 411 | + // Now add more data. |
| 412 | + for (int i = 0; i < 10; i++) { |
| 413 | + indexer.addDocument(indexShardKey1, document1); |
| 414 | + } |
| 415 | + assertThat(indexShardDao.find(FindIndexShardCriteria.matchAll()).size()).isEqualTo(j + 1); |
| 416 | + assertThat(indexShardDao.find(findDeleted).size()).isEqualTo(j); |
| 417 | + } |
| 418 | + } |
| 419 | + |
| 420 | + @Test |
| 421 | + void testCorruption() { |
| 422 | + assertThat(indexShardDao.find(FindIndexShardCriteria.matchAll()).size()).isZero(); |
| 423 | + |
| 424 | + final DocRef indexRef1 = commonTestScenarioCreator.createIndex("TEST_2010", |
| 425 | + commonTestScenarioCreator.createIndexFields(), |
| 426 | + 1000000); |
| 427 | + final LuceneIndexDoc index1 = indexStore.readDocument(indexRef1); |
| 428 | + final IndexShardKey indexShardKey1 = IndexShardKey.createKey(index1); |
| 429 | + |
| 430 | + final IndexDocument document1 = new IndexDocument(); |
| 431 | + document1.add(new FieldValue(LuceneIndexField |
| 432 | + .builder() |
| 433 | + .fldName("SourcePort") |
| 434 | + .fldType(FieldType.TEXT) |
| 435 | + .analyzerType(AnalyzerType.ALPHA_NUMERIC) |
| 436 | + .termPositions(false) |
| 437 | + .indexed(true) |
| 438 | + .stored(false) |
| 439 | + .build(), ValString.create("12345"))); |
| 440 | + |
| 441 | + final List<IndexVolume> volumeList = indexVolumeDao.getAll(); |
| 442 | + for (int j = 0; j < 10; j++) { |
| 443 | + // Flush. |
| 444 | + indexShardManager.performAction(FindIndexShardCriteria.matchAll(), IndexShardAction.FLUSH); |
| 445 | + |
| 446 | + // Delete every shard file. |
| 447 | + for (final IndexVolume indexVolume : volumeList) { |
| 448 | + FileUtil.deleteContents(Paths.get(indexVolume.getPath())); |
| 449 | + } |
| 450 | + assertThat(indexShardDao.find(FindIndexShardCriteria.matchAll()).size()).isEqualTo(j); |
| 451 | + |
| 452 | + // Now add more data. |
| 453 | + for (int i = 0; i < 10; i++) { |
| 454 | + indexer.addDocument(indexShardKey1, document1); |
| 455 | + } |
| 456 | + assertThat(indexShardDao.find(FindIndexShardCriteria.matchAll()).size()).isEqualTo(j + 1); |
| 457 | + } |
| 458 | + } |
| 459 | + |
376 | 460 | private void checkDocCount(final int expected, final IndexShardWriter indexShardWriter) {
|
377 | 461 | assertThat(indexShardWriter.getDocumentCount()).isEqualTo(expected);
|
378 | 462 | }
|
|
0 commit comments