use of com.yelp.nrtsearch.server.luceneserver.state.PersistentGlobalState.IndexInfo in project nrtsearch by Yelp.
the class LocalStateBackendTest method testLoadsSavedState.
@Test
public void testLoadsSavedState() throws IOException {
StateBackend stateBackend = new LocalStateBackend(getMockGlobalState());
Path filePath = getStateFilePath();
Map<String, IndexInfo> indicesMap = new HashMap<>();
indicesMap.put("test_index", new IndexInfo());
indicesMap.put("test_index_2", new IndexInfo());
PersistentGlobalState initialState = new PersistentGlobalState(indicesMap);
StateUtils.writeStateToFile(initialState, Paths.get(folder.getRoot().getAbsolutePath(), StateUtils.GLOBAL_STATE_FOLDER), StateUtils.GLOBAL_STATE_FILE);
assertTrue(filePath.toFile().exists());
assertTrue(filePath.toFile().isFile());
PersistentGlobalState loadedState = stateBackend.loadOrCreateGlobalState();
assertEquals(initialState, loadedState);
}
use of com.yelp.nrtsearch.server.luceneserver.state.PersistentGlobalState.IndexInfo in project nrtsearch by Yelp.
the class LocalStateBackendTest method testCommitGlobalState.
@Test
public void testCommitGlobalState() throws IOException {
StateBackend stateBackend = new LocalStateBackend(getMockGlobalState());
Path filePath = getStateFilePath();
PersistentGlobalState initialState = stateBackend.loadOrCreateGlobalState();
Map<String, IndexInfo> indicesMap = new HashMap<>();
indicesMap.put("test_index", new IndexInfo());
indicesMap.put("test_index_2", new IndexInfo());
PersistentGlobalState updatedState = new PersistentGlobalState(indicesMap);
assertNotEquals(initialState, updatedState);
stateBackend.commitGlobalState(updatedState);
PersistentGlobalState loadedState = StateUtils.readStateFromFile(filePath);
assertEquals(updatedState, loadedState);
indicesMap = new HashMap<>();
indicesMap.put("test_index_3", new IndexInfo());
PersistentGlobalState updatedState2 = new PersistentGlobalState(indicesMap);
assertNotEquals(updatedState, updatedState2);
stateBackend.commitGlobalState(updatedState2);
loadedState = StateUtils.readStateFromFile(filePath);
assertEquals(updatedState2, loadedState);
}
use of com.yelp.nrtsearch.server.luceneserver.state.PersistentGlobalState.IndexInfo in project nrtsearch by Yelp.
the class RemoteStateBackendTest method testCommitGlobalState.
@Test
public void testCommitGlobalState() throws IOException {
StateBackend stateBackend = new RemoteStateBackend(getMockGlobalState(false));
Path localFilePath = getLocalStateFilePath();
PersistentGlobalState initialState = stateBackend.loadOrCreateGlobalState();
Map<String, IndexInfo> indicesMap = new HashMap<>();
indicesMap.put("test_index", new IndexInfo());
indicesMap.put("test_index_2", new IndexInfo());
PersistentGlobalState updatedState = new PersistentGlobalState(indicesMap);
assertNotEquals(initialState, updatedState);
stateBackend.commitGlobalState(updatedState);
PersistentGlobalState loadedState = getS3State();
assertEquals(updatedState, loadedState);
PersistentGlobalState loadedLocalState = StateUtils.readStateFromFile(localFilePath);
assertEquals(updatedState, loadedLocalState);
indicesMap = new HashMap<>();
indicesMap.put("test_index_3", new IndexInfo());
PersistentGlobalState updatedState2 = new PersistentGlobalState(indicesMap);
assertNotEquals(updatedState, updatedState2);
stateBackend.commitGlobalState(updatedState2);
loadedState = getS3State();
assertEquals(updatedState2, loadedState);
loadedLocalState = StateUtils.readStateFromFile(localFilePath);
assertEquals(updatedState2, loadedLocalState);
}
use of com.yelp.nrtsearch.server.luceneserver.state.PersistentGlobalState.IndexInfo in project nrtsearch by Yelp.
the class RemoteStateBackendTest method testReadOnlyWithInitialState.
@Test
public void testReadOnlyWithInitialState() 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);
}
use of com.yelp.nrtsearch.server.luceneserver.state.PersistentGlobalState.IndexInfo in project nrtsearch by Yelp.
the class BackendGlobalState method createIndex.
@Override
public synchronized IndexState createIndex(String name) throws IOException {
Path rootDir = getIndexDir(name);
if (immutableState.persistentGlobalState.getIndices().containsKey(name)) {
throw new IllegalArgumentException("index \"" + name + "\" already exists");
}
if (Files.exists(rootDir)) {
throw new IllegalArgumentException("rootDir \"" + rootDir + "\" already exists");
}
IndexState state = new IndexState(this, name, rootDir, true, false);
Map<String, IndexInfo> updatedIndexInfoMap = new HashMap<>(immutableState.persistentGlobalState.getIndices());
updatedIndexInfoMap.put(name, new IndexInfo());
PersistentGlobalState updatedState = immutableState.persistentGlobalState.asBuilder().withIndices(updatedIndexInfoMap).build();
stateBackend.commitGlobalState(updatedState);
Map<String, IndexState> updatedIndexStateMap = new HashMap<>(immutableState.indexStateMap);
updatedIndexStateMap.put(name, state);
immutableState = new ImmutableState(updatedState, updatedIndexStateMap);
return state;
}
Aggregations