Search in sources :

Example 16 with Writer

use of org.opensearch.gateway.PersistedClusterStateService.Writer in project OpenSearch by opensearch-project.

the class PersistedClusterStateServiceTests method testPersistsAndReloadsTerm.

public void testPersistsAndReloadsTerm() throws IOException {
    try (NodeEnvironment nodeEnvironment = newNodeEnvironment(createDataPaths())) {
        final PersistedClusterStateService persistedClusterStateService = newPersistedClusterStateService(nodeEnvironment);
        final long newTerm = randomNonNegativeLong();
        assertThat(persistedClusterStateService.loadBestOnDiskState().currentTerm, equalTo(0L));
        try (Writer writer = persistedClusterStateService.createWriter()) {
            writer.writeFullStateAndCommit(newTerm, ClusterState.EMPTY_STATE);
            assertThat(persistedClusterStateService.loadBestOnDiskState().currentTerm, equalTo(newTerm));
        }
        assertThat(persistedClusterStateService.loadBestOnDiskState().currentTerm, equalTo(newTerm));
    }
}
Also used : NodeEnvironment(org.opensearch.env.NodeEnvironment) IndexWriter(org.apache.lucene.index.IndexWriter) Writer(org.opensearch.gateway.PersistedClusterStateService.Writer)

Aggregations

IndexWriter (org.apache.lucene.index.IndexWriter)16 NodeEnvironment (org.opensearch.env.NodeEnvironment)16 Writer (org.opensearch.gateway.PersistedClusterStateService.Writer)16 ClusterState (org.opensearch.cluster.ClusterState)15 Matchers.containsString (org.hamcrest.Matchers.containsString)11 Path (java.nio.file.Path)10 FilterDirectory (org.apache.lucene.store.FilterDirectory)9 ClusterSettings (org.opensearch.common.settings.ClusterSettings)7 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 IndexWriterConfig (org.apache.lucene.index.IndexWriterConfig)6 Directory (org.apache.lucene.store.Directory)6 NIOFSDirectory (org.apache.lucene.store.NIOFSDirectory)6 IOException (java.io.IOException)5 IndexMetadata (org.opensearch.cluster.metadata.IndexMetadata)5 ArrayList (java.util.ArrayList)4 Collection (java.util.Collection)4 AtomicLong (java.util.concurrent.atomic.AtomicLong)4 Term (org.apache.lucene.index.Term)4 IOContext (org.apache.lucene.store.IOContext)4 DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)4