use of com.yelp.nrtsearch.server.luceneserver.state.PersistentGlobalState 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 in project nrtsearch by Yelp.
the class RemoteStateBackendTest method getS3State.
private PersistentGlobalState getS3State() throws IOException {
long currentVersion = versionManager.getLatestVersionNumber(TEST_SERVICE_NAME, RemoteStateBackend.GLOBAL_STATE_RESOURCE);
if (currentVersion < 0) {
return null;
}
String versionHash = versionManager.getVersionString(TEST_SERVICE_NAME, RemoteStateBackend.GLOBAL_STATE_RESOURCE, String.valueOf(currentVersion));
Path s3FilePath = getS3FilePath(versionHash);
assertTrue(s3FilePath.toFile().exists());
assertTrue(s3FilePath.toFile().isFile());
TarArchiveInputStream tarArchiveInputStream = new TarArchiveInputStream(new LZ4FrameInputStream(new FileInputStream(s3FilePath.toFile())));
PersistentGlobalState stateFromTar = null;
for (TarArchiveEntry tarArchiveEntry = tarArchiveInputStream.getNextTarEntry(); tarArchiveEntry != null; tarArchiveEntry = tarArchiveInputStream.getNextTarEntry()) {
if (tarArchiveEntry.getName().endsWith(StateUtils.GLOBAL_STATE_FILE)) {
String stateStr;
try (DataInputStream dataInputStream = new DataInputStream(tarArchiveInputStream)) {
stateStr = dataInputStream.readUTF();
}
stateFromTar = StateUtils.MAPPER.readValue(stateStr, PersistentGlobalState.class);
break;
}
}
return stateFromTar;
}
use of com.yelp.nrtsearch.server.luceneserver.state.PersistentGlobalState 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 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 in project nrtsearch by Yelp.
the class RemoteStateBackendTest method testCreatesDefaultState.
@Test
public void testCreatesDefaultState() throws IOException {
StateBackend stateBackend = new RemoteStateBackend(getMockGlobalState(false));
Path localFilePath = getLocalStateFilePath();
assertFalse(localFilePath.toFile().exists());
assertNull(getS3State());
PersistentGlobalState globalState = stateBackend.loadOrCreateGlobalState();
assertEquals(globalState, new PersistentGlobalState());
assertTrue(localFilePath.toFile().exists());
assertTrue(localFilePath.toFile().isFile());
PersistentGlobalState loadedLocalState = StateUtils.readStateFromFile(localFilePath);
assertEquals(globalState, loadedLocalState);
PersistentGlobalState stateFromTar = getS3State();
assertNotNull(stateFromTar);
assertEquals(globalState, stateFromTar);
}
Aggregations