|
20 | 20 |
|
21 | 21 | package com.arangodb; |
22 | 22 |
|
23 | | -import com.arangodb.entity.*; |
24 | | -import com.arangodb.model.*; |
| 23 | +import com.arangodb.entity.ArangoDBVersion; |
| 24 | +import com.arangodb.entity.DatabaseEntity; |
| 25 | +import com.arangodb.entity.License; |
| 26 | +import com.arangodb.entity.LogEntity; |
| 27 | +import com.arangodb.entity.LogEntriesEntity; |
| 28 | +import com.arangodb.entity.LogLevel; |
| 29 | +import com.arangodb.entity.LogLevelEntity; |
| 30 | +import com.arangodb.entity.Permissions; |
| 31 | +import com.arangodb.entity.ServerRole; |
| 32 | +import com.arangodb.entity.UserEntity; |
| 33 | +import com.arangodb.model.DBCreateOptions; |
| 34 | +import com.arangodb.model.DatabaseOptions; |
| 35 | +import com.arangodb.model.DatabaseUsersOptions; |
| 36 | +import com.arangodb.model.LogOptions; |
25 | 37 | import com.arangodb.model.LogOptions.SortOrder; |
| 38 | +import com.arangodb.model.UserCreateOptions; |
| 39 | +import com.arangodb.model.UserUpdateOptions; |
26 | 40 | import com.arangodb.util.TestUtils; |
27 | 41 | import com.arangodb.velocypack.exception.VPackException; |
28 | 42 | import com.arangodb.velocystream.Request; |
|
36 | 50 | import org.junit.runners.Parameterized; |
37 | 51 | import org.junit.runners.Parameterized.Parameters; |
38 | 52 |
|
39 | | -import java.util.*; |
| 53 | +import java.util.ArrayList; |
| 54 | +import java.util.Collection; |
| 55 | +import java.util.Collections; |
| 56 | +import java.util.HashMap; |
| 57 | +import java.util.List; |
| 58 | +import java.util.Map; |
| 59 | +import java.util.Optional; |
| 60 | +import java.util.UUID; |
| 61 | +import java.util.stream.Collectors; |
40 | 62 |
|
41 | 63 | import static org.hamcrest.MatcherAssert.assertThat; |
42 | 64 | import static org.hamcrest.Matchers.*; |
@@ -484,6 +506,121 @@ public void getLogsSortDesc() { |
484 | 506 | } |
485 | 507 | } |
486 | 508 |
|
| 509 | + @Test |
| 510 | + public void getLogEntries() { |
| 511 | + assumeTrue(isAtLeastVersion(3,8)); |
| 512 | + final LogEntriesEntity logs = arangoDB.getLogEntries(null); |
| 513 | + assertThat(logs, is(notNullValue())); |
| 514 | + assertThat(logs.getTotal(), greaterThan(0L)); |
| 515 | + assertThat((long) logs.getMessages().size(), is(logs.getTotal())); |
| 516 | + } |
| 517 | + |
| 518 | + @Test |
| 519 | + public void getLogEntriesUpto() { |
| 520 | + assumeTrue(isAtLeastVersion(3,8)); |
| 521 | + final LogEntriesEntity logsUpto = arangoDB.getLogEntries(new LogOptions().upto(LogLevel.WARNING)); |
| 522 | + assertThat(logsUpto, is(notNullValue())); |
| 523 | + assertThat( |
| 524 | + logsUpto.getMessages().stream() |
| 525 | + .map(LogEntriesEntity.Message::getLevel) |
| 526 | + .noneMatch("INFO"::equals), |
| 527 | + is(true) |
| 528 | + ); |
| 529 | + } |
| 530 | + |
| 531 | + @Test |
| 532 | + public void getLogEntriesLevel() { |
| 533 | + assumeTrue(isAtLeastVersion(3,8)); |
| 534 | + final LogEntriesEntity logsInfo = arangoDB.getLogEntries(new LogOptions().level(LogLevel.INFO)); |
| 535 | + assertThat(logsInfo, is(notNullValue())); |
| 536 | + assertThat( |
| 537 | + logsInfo.getMessages().stream() |
| 538 | + .map(LogEntriesEntity.Message::getLevel) |
| 539 | + .allMatch("INFO"::equals), |
| 540 | + is(true) |
| 541 | + ); |
| 542 | + } |
| 543 | + |
| 544 | + @Test |
| 545 | + public void getLogEntriesStart() { |
| 546 | + assumeTrue(isAtLeastVersion(3,8)); |
| 547 | + final LogEntriesEntity logs = arangoDB.getLogEntries(null); |
| 548 | + final Long firstId = logs.getMessages().get(0).getId(); |
| 549 | + final LogEntriesEntity logsStart = arangoDB.getLogEntries(new LogOptions().start(firstId + 1)); |
| 550 | + assertThat(logsStart, is(notNullValue())); |
| 551 | + assertThat( |
| 552 | + logsStart.getMessages().stream() |
| 553 | + .map(LogEntriesEntity.Message::getId) |
| 554 | + .filter(firstId::equals) |
| 555 | + .count(), |
| 556 | + is(0L)); |
| 557 | + } |
| 558 | + |
| 559 | + @Test |
| 560 | + public void getLogEntriesSize() { |
| 561 | + assumeTrue(isAtLeastVersion(3,8)); |
| 562 | + final LogEntriesEntity logs = arangoDB.getLogEntries(null); |
| 563 | + int count = logs.getMessages().size(); |
| 564 | + assertThat(count, greaterThan(0)); |
| 565 | + final LogEntriesEntity logsSize = arangoDB.getLogEntries(new LogOptions().size(count - 1)); |
| 566 | + assertThat(logsSize, is(notNullValue())); |
| 567 | + assertThat(logsSize.getMessages().size(), is(count - 1)); |
| 568 | + } |
| 569 | + |
| 570 | + @Test |
| 571 | + public void getLogEntriesOffset() { |
| 572 | + assumeTrue(isAtLeastVersion(3,8)); |
| 573 | + final LogEntriesEntity logs = arangoDB.getLogEntries(null); |
| 574 | + assertThat(logs.getTotal(), greaterThan(0L)); |
| 575 | + Long firstId = logs.getMessages().get(0).getId(); |
| 576 | + final LogEntriesEntity logsOffset = arangoDB.getLogEntries(new LogOptions().offset(1)); |
| 577 | + assertThat(logsOffset, is(notNullValue())); |
| 578 | + assertThat(logsOffset.getMessages().stream() |
| 579 | + .map(LogEntriesEntity.Message::getId) |
| 580 | + .filter(firstId::equals) |
| 581 | + .count() |
| 582 | + , is(0L)); |
| 583 | + } |
| 584 | + |
| 585 | + @Test |
| 586 | + public void getLogEntriesSearch() { |
| 587 | + assumeTrue(isAtLeastVersion(3,8)); |
| 588 | + final LogEntriesEntity logs = arangoDB.getLogEntries(null); |
| 589 | + final LogEntriesEntity logsSearch = arangoDB.getLogEntries(new LogOptions().search(BaseTest.TEST_DB)); |
| 590 | + assertThat(logsSearch, is(notNullValue())); |
| 591 | + assertThat(logs.getTotal(), greaterThan(logsSearch.getTotal())); |
| 592 | + } |
| 593 | + |
| 594 | + @Test |
| 595 | + public void getLogEntriesSortAsc() { |
| 596 | + assumeTrue(isAtLeastVersion(3,8)); |
| 597 | + final LogEntriesEntity logs = arangoDB.getLogEntries(new LogOptions().sort(SortOrder.asc)); |
| 598 | + assertThat(logs, is(notNullValue())); |
| 599 | + long lastId = -1; |
| 600 | + List<Long> ids = logs.getMessages().stream() |
| 601 | + .map(LogEntriesEntity.Message::getId) |
| 602 | + .collect(Collectors.toList()); |
| 603 | + for (final Long id : ids) { |
| 604 | + assertThat(id, greaterThan(lastId)); |
| 605 | + lastId = id; |
| 606 | + } |
| 607 | + } |
| 608 | + |
| 609 | + @Test |
| 610 | + public void getLogEntriesSortDesc() { |
| 611 | + assumeTrue(isAtLeastVersion(3,8)); |
| 612 | + final LogEntriesEntity logs = arangoDB.getLogEntries(new LogOptions().sort(SortOrder.desc)); |
| 613 | + assertThat(logs, is(notNullValue())); |
| 614 | + long lastId = Long.MAX_VALUE; |
| 615 | + List<Long> ids = logs.getMessages().stream() |
| 616 | + .map(LogEntriesEntity.Message::getId) |
| 617 | + .collect(Collectors.toList()); |
| 618 | + for (final Long id : ids) { |
| 619 | + assertThat(lastId, greaterThan(id)); |
| 620 | + lastId = id; |
| 621 | + } |
| 622 | + } |
| 623 | + |
487 | 624 | @Test |
488 | 625 | public void getLogLevel() { |
489 | 626 | assumeTrue(isAtLeastVersion(3, 7)); // it fails in 3.6 active-failover (BTS-362) |
|
0 commit comments