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);
}
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());
}
}
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());
}
}
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);
}
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);
}
Aggregations