Search in sources :

Example 6 with IndexInfo

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

the class PersistentGlobalStateTest method testUnmodifiableIndices.

@Test(expected = UnsupportedOperationException.class)
public void testUnmodifiableIndices() {
    PersistentGlobalState state = new PersistentGlobalState();
    state.getIndices().put("test_index", new IndexInfo());
}
Also used : IndexInfo(com.yelp.nrtsearch.server.luceneserver.state.PersistentGlobalState.IndexInfo) Test(org.junit.Test)

Example 7 with IndexInfo

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

the class PersistentGlobalStateTest method testBuilder.

@Test
public void testBuilder() {
    Map<String, IndexInfo> indicesMap = new HashMap<>();
    indicesMap.put("test_index", new IndexInfo());
    indicesMap.put("test_index_2", new IndexInfo());
    PersistentGlobalState state = new PersistentGlobalState(indicesMap);
    PersistentGlobalState rebuilt = state.asBuilder().build();
    assertNotSame(state, rebuilt);
    assertEquals(state, rebuilt);
    indicesMap = new HashMap<>();
    indicesMap.put("test_index_3", new IndexInfo());
    indicesMap.put("test_index_4", new IndexInfo());
    PersistentGlobalState updated = state.asBuilder().withIndices(indicesMap).build();
    assertNotEquals(state, updated);
    assertEquals(indicesMap, updated.getIndices());
}
Also used : HashMap(java.util.HashMap) IndexInfo(com.yelp.nrtsearch.server.luceneserver.state.PersistentGlobalState.IndexInfo) Test(org.junit.Test)

Example 8 with IndexInfo

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

the class PersistentGlobalStateTest method testGlobalState.

@Test
public void testGlobalState() {
    Map<String, IndexInfo> indicesMap = new HashMap<>();
    indicesMap.put("test_index", new IndexInfo());
    indicesMap.put("test_index_2", new IndexInfo());
    PersistentGlobalState state = new PersistentGlobalState(indicesMap);
    assertEquals(indicesMap, state.getIndices());
}
Also used : HashMap(java.util.HashMap) IndexInfo(com.yelp.nrtsearch.server.luceneserver.state.PersistentGlobalState.IndexInfo) Test(org.junit.Test)

Example 9 with IndexInfo

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

the class StateUtilsTest method testWriteNewStateFile.

@Test
public void testWriteNewStateFile() throws IOException {
    Path expectedStateFilePath = Paths.get(folder.getRoot().getAbsolutePath(), StateUtils.GLOBAL_STATE_FILE);
    assertFalse(expectedStateFilePath.toFile().exists());
    Map<String, IndexInfo> testIndices = new HashMap<>();
    testIndices.put("test_index", new IndexInfo());
    testIndices.put("test_index_2", new IndexInfo());
    PersistentGlobalState persistentGlobalState = new PersistentGlobalState(testIndices);
    StateUtils.writeStateToFile(persistentGlobalState, Paths.get(folder.getRoot().getAbsolutePath()), StateUtils.GLOBAL_STATE_FILE);
    assertTrue(expectedStateFilePath.toFile().exists());
    PersistentGlobalState readState = StateUtils.readStateFromFile(expectedStateFilePath);
    assertEquals(persistentGlobalState, readState);
}
Also used : Path(java.nio.file.Path) HashMap(java.util.HashMap) IndexInfo(com.yelp.nrtsearch.server.luceneserver.state.PersistentGlobalState.IndexInfo) Test(org.junit.Test)

Example 10 with IndexInfo

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

the class StateUtilsTest method testReWriteStateFile.

@Test
public void testReWriteStateFile() throws IOException {
    Path expectedStateFilePath = Paths.get(folder.getRoot().getAbsolutePath(), StateUtils.GLOBAL_STATE_FILE);
    assertFalse(expectedStateFilePath.toFile().exists());
    Map<String, IndexInfo> testIndices = new HashMap<>();
    testIndices.put("test_index_3", new IndexInfo());
    testIndices.put("test_index_4", new IndexInfo());
    PersistentGlobalState persistentGlobalState = new PersistentGlobalState(testIndices);
    StateUtils.writeStateToFile(persistentGlobalState, Paths.get(folder.getRoot().getAbsolutePath()), StateUtils.GLOBAL_STATE_FILE);
    assertTrue(expectedStateFilePath.toFile().exists());
    PersistentGlobalState readState = StateUtils.readStateFromFile(expectedStateFilePath);
    assertEquals(persistentGlobalState, readState);
    testIndices = new HashMap<>();
    testIndices.put("test_index_5", new IndexInfo());
    testIndices.put("test_index_6", new IndexInfo());
    testIndices.put("test_index_7", new IndexInfo());
    PersistentGlobalState persistentGlobalState2 = new PersistentGlobalState(testIndices);
    StateUtils.writeStateToFile(persistentGlobalState2, Paths.get(folder.getRoot().getAbsolutePath()), StateUtils.GLOBAL_STATE_FILE);
    assertTrue(expectedStateFilePath.toFile().exists());
    PersistentGlobalState readState2 = StateUtils.readStateFromFile(expectedStateFilePath);
    assertEquals(persistentGlobalState2, readState2);
    assertNotEquals(readState, readState2);
}
Also used : Path(java.nio.file.Path) HashMap(java.util.HashMap) IndexInfo(com.yelp.nrtsearch.server.luceneserver.state.PersistentGlobalState.IndexInfo) 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