Search in sources :

Example 1 with IndexInfo

use of com.yelp.nrtsearch.server.luceneserver.state.PersistentGlobalState.IndexInfo in project nrtsearch by Yelp.

the class RemoteStateBackendTest method testLoadsSavedState.

@Test
public void testLoadsSavedState() throws IOException {
    StateBackend stateBackend = new RemoteStateBackend(getMockGlobalState(false));
    Path localFilePath = getLocalStateFilePath();
    assertFalse(localFilePath.toFile().exists());
    Map<String, IndexInfo> indicesMap = new HashMap<>();
    indicesMap.put("test_index", new IndexInfo());
    indicesMap.put("test_index_2", new IndexInfo());
    PersistentGlobalState initialState = new PersistentGlobalState(indicesMap);
    writeStateToS3(initialState);
    PersistentGlobalState loadedState = stateBackend.loadOrCreateGlobalState();
    assertEquals(initialState, loadedState);
    assertTrue(localFilePath.toFile().exists());
    assertTrue(localFilePath.toFile().isFile());
    PersistentGlobalState loadedLocalState = StateUtils.readStateFromFile(localFilePath);
    assertEquals(initialState, loadedLocalState);
}
Also used : Path(java.nio.file.Path) HashMap(java.util.HashMap) PersistentGlobalState(com.yelp.nrtsearch.server.luceneserver.state.PersistentGlobalState) IndexInfo(com.yelp.nrtsearch.server.luceneserver.state.PersistentGlobalState.IndexInfo) Test(org.junit.Test)

Example 2 with IndexInfo

use of com.yelp.nrtsearch.server.luceneserver.state.PersistentGlobalState.IndexInfo in project nrtsearch by Yelp.

the class RemoteStateBackendTest method testReadOnlyCommit.

@Test
public void testReadOnlyCommit() throws IOException {
    StateBackend stateBackend = new RemoteStateBackend(getMockGlobalState(true));
    Map<String, IndexInfo> indicesMap = new HashMap<>();
    indicesMap.put("test_index", new IndexInfo());
    indicesMap.put("test_index_2", new IndexInfo());
    PersistentGlobalState initialState = new PersistentGlobalState(indicesMap);
    writeStateToS3(initialState);
    PersistentGlobalState loadedState = stateBackend.loadOrCreateGlobalState();
    assertEquals(initialState, loadedState);
    indicesMap = new HashMap<>();
    indicesMap.put("test_index_3", new IndexInfo());
    indicesMap.put("test_index_4", new IndexInfo());
    indicesMap.put("test_index_5", new IndexInfo());
    PersistentGlobalState updatedState = new PersistentGlobalState(indicesMap);
    try {
        stateBackend.commitGlobalState(updatedState);
        fail();
    } catch (IllegalStateException e) {
        assertEquals("Cannot update remote state when configured as read only", e.getMessage());
    }
}
Also used : HashMap(java.util.HashMap) PersistentGlobalState(com.yelp.nrtsearch.server.luceneserver.state.PersistentGlobalState) IndexInfo(com.yelp.nrtsearch.server.luceneserver.state.PersistentGlobalState.IndexInfo) Test(org.junit.Test)

Example 3 with IndexInfo

use of com.yelp.nrtsearch.server.luceneserver.state.PersistentGlobalState.IndexInfo in project nrtsearch by Yelp.

the class BackendGlobalStateTest method testCreateIndexFailsFromLoadedState.

@Test
public void testCreateIndexFailsFromLoadedState() throws IOException {
    StateBackend mockBackend = mock(StateBackend.class);
    Map<String, IndexInfo> initialIndices = new HashMap<>();
    initialIndices.put("test_index", new IndexInfo());
    PersistentGlobalState initialState = new PersistentGlobalState(initialIndices);
    when(mockBackend.loadOrCreateGlobalState()).thenReturn(initialState);
    MockBackendGlobalState.stateBackend = mockBackend;
    BackendGlobalState backendGlobalState = new MockBackendGlobalState(getConfig(), null);
    try {
        backendGlobalState.createIndex("test_index");
        fail();
    } catch (IllegalArgumentException e) {
        assertEquals("index \"test_index\" already exists", e.getMessage());
    }
}
Also used : HashMap(java.util.HashMap) IndexInfo(com.yelp.nrtsearch.server.luceneserver.state.PersistentGlobalState.IndexInfo) StateBackend(com.yelp.nrtsearch.server.luceneserver.state.backend.StateBackend) RemoteStateBackend(com.yelp.nrtsearch.server.luceneserver.state.backend.RemoteStateBackend) LocalStateBackend(com.yelp.nrtsearch.server.luceneserver.state.backend.LocalStateBackend) Test(org.junit.Test)

Example 4 with IndexInfo

use of com.yelp.nrtsearch.server.luceneserver.state.PersistentGlobalState.IndexInfo in project nrtsearch by Yelp.

the class BackendGlobalStateTest method testGetRestoredStateIndex.

@Test
public void testGetRestoredStateIndex() throws IOException {
    StateBackend mockBackend = mock(StateBackend.class);
    Map<String, IndexInfo> initialIndices = new HashMap<>();
    initialIndices.put("test_index", new IndexInfo());
    PersistentGlobalState initialState = new PersistentGlobalState(initialIndices);
    when(mockBackend.loadOrCreateGlobalState()).thenReturn(initialState);
    MockBackendGlobalState.stateBackend = mockBackend;
    BackendGlobalState backendGlobalState = new MockBackendGlobalState(getConfig(), null);
    assertNotNull(backendGlobalState.getIndex("test_index"));
    verify(mockBackend, times(1)).loadOrCreateGlobalState();
    verifyNoMoreInteractions(mockBackend);
}
Also used : HashMap(java.util.HashMap) IndexInfo(com.yelp.nrtsearch.server.luceneserver.state.PersistentGlobalState.IndexInfo) StateBackend(com.yelp.nrtsearch.server.luceneserver.state.backend.StateBackend) RemoteStateBackend(com.yelp.nrtsearch.server.luceneserver.state.backend.RemoteStateBackend) LocalStateBackend(com.yelp.nrtsearch.server.luceneserver.state.backend.LocalStateBackend) Test(org.junit.Test)

Example 5 with IndexInfo

use of com.yelp.nrtsearch.server.luceneserver.state.PersistentGlobalState.IndexInfo in project nrtsearch by Yelp.

the class BackendGlobalStateTest method testDeleteRestoredStateIndex.

@Test
public void testDeleteRestoredStateIndex() throws IOException {
    StateBackend mockBackend = mock(StateBackend.class);
    Map<String, IndexInfo> initialIndices = new HashMap<>();
    initialIndices.put("test_index", new IndexInfo());
    initialIndices.put("test_index_2", new IndexInfo());
    PersistentGlobalState initialState = new PersistentGlobalState(initialIndices);
    when(mockBackend.loadOrCreateGlobalState()).thenReturn(initialState);
    MockBackendGlobalState.stateBackend = mockBackend;
    BackendGlobalState backendGlobalState = new MockBackendGlobalState(getConfig(), null);
    backendGlobalState.deleteIndex("test_index_2");
    assertEquals(Set.of("test_index"), backendGlobalState.getIndexNames());
    verify(mockBackend, times(1)).loadOrCreateGlobalState();
    ArgumentCaptor<PersistentGlobalState> stateArgumentCaptor = ArgumentCaptor.forClass(PersistentGlobalState.class);
    verify(mockBackend, times(1)).commitGlobalState(stateArgumentCaptor.capture());
    PersistentGlobalState committedState = stateArgumentCaptor.getValue();
    assertEquals(1, committedState.getIndices().size());
    assertNotNull(committedState.getIndices().get("test_index"));
    verifyNoMoreInteractions(mockBackend);
}
Also used : HashMap(java.util.HashMap) IndexInfo(com.yelp.nrtsearch.server.luceneserver.state.PersistentGlobalState.IndexInfo) StateBackend(com.yelp.nrtsearch.server.luceneserver.state.backend.StateBackend) RemoteStateBackend(com.yelp.nrtsearch.server.luceneserver.state.backend.RemoteStateBackend) LocalStateBackend(com.yelp.nrtsearch.server.luceneserver.state.backend.LocalStateBackend) Test(org.junit.Test)

Aggregations

IndexInfo (com.yelp.nrtsearch.server.luceneserver.state.PersistentGlobalState.IndexInfo)15 HashMap (java.util.HashMap)14 Test (org.junit.Test)14 Path (java.nio.file.Path)7 PersistentGlobalState (com.yelp.nrtsearch.server.luceneserver.state.PersistentGlobalState)6 LocalStateBackend (com.yelp.nrtsearch.server.luceneserver.state.backend.LocalStateBackend)3 RemoteStateBackend (com.yelp.nrtsearch.server.luceneserver.state.backend.RemoteStateBackend)3 StateBackend (com.yelp.nrtsearch.server.luceneserver.state.backend.StateBackend)3 IndexState (com.yelp.nrtsearch.server.luceneserver.IndexState)1