-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Add index state metrics * Change metric name * Add tests for metrics * Fix test --------- (cherry picked from commit d03cc8c) Signed-off-by: Tomoyuki Morita <[email protected]> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
d6c8973
commit 8fee825
Showing
3 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
...t/java/org/opensearch/flint/core/metadata/log/DefaultOptimisticTransactionMetricTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.flint.core.metadata.log; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import org.opensearch.flint.common.metadata.log.FlintMetadataLog; | ||
import org.opensearch.flint.common.metadata.log.FlintMetadataLogEntry; | ||
|
||
import java.util.Optional; | ||
import org.opensearch.flint.common.metadata.log.FlintMetadataLogEntry.IndexState$; | ||
import org.opensearch.flint.core.metrics.MetricsTestUtil; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.*; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class DefaultOptimisticTransactionMetricTest { | ||
|
||
@Mock | ||
private FlintMetadataLog<FlintMetadataLogEntry> metadataLog; | ||
|
||
@Mock | ||
private FlintMetadataLogEntry logEntry; | ||
|
||
@InjectMocks | ||
private DefaultOptimisticTransaction<String> transaction; | ||
|
||
@Test | ||
void testCommitWithValidInitialCondition() throws Exception { | ||
MetricsTestUtil.withMetricEnv(verifier -> { | ||
when(metadataLog.getLatest()).thenReturn(Optional.of(logEntry)); | ||
when(metadataLog.add(any(FlintMetadataLogEntry.class))).thenReturn(logEntry); | ||
when(logEntry.state()).thenReturn(IndexState$.MODULE$.ACTIVE()); | ||
|
||
transaction.initialLog(entry -> true) | ||
.transientLog(entry -> logEntry) | ||
.finalLog(entry -> logEntry) | ||
.commit(entry -> "Success"); | ||
|
||
verify(metadataLog, times(2)).add(logEntry); | ||
verifier.assertHistoricGauge("indexState.updatedTo.active.count", 1); | ||
}); | ||
} | ||
|
||
@Test | ||
void testConditionCheckFailed() throws Exception { | ||
MetricsTestUtil.withMetricEnv(verifier -> { | ||
when(metadataLog.getLatest()).thenReturn(Optional.of(logEntry)); | ||
when(logEntry.state()).thenReturn(IndexState$.MODULE$.DELETED()); | ||
|
||
transaction.initialLog(entry -> false) | ||
.finalLog(entry -> logEntry); | ||
|
||
assertThrows(IllegalStateException.class, () -> { | ||
transaction.commit(entry -> "Should Fail"); | ||
}); | ||
verifier.assertHistoricGauge("initialConditionCheck.failed.deleted.count", 1); | ||
}); | ||
} | ||
} |