use of com.yelp.nrtsearch.server.luceneserver.state.backend.StateBackend in project nrtsearch by Yelp.
the class BackendGlobalStateTest method testSetStateDir.
@Test(expected = UnsupportedOperationException.class)
public void testSetStateDir() throws IOException {
StateBackend mockBackend = mock(StateBackend.class);
PersistentGlobalState initialState = new PersistentGlobalState();
when(mockBackend.loadOrCreateGlobalState()).thenReturn(initialState);
MockBackendGlobalState.stateBackend = mockBackend;
BackendGlobalState backendGlobalState = new MockBackendGlobalState(getConfig(), null);
backendGlobalState.setStateDir(folder.getRoot().toPath());
}
use of com.yelp.nrtsearch.server.luceneserver.state.backend.StateBackend in project nrtsearch by Yelp.
the class BackendGlobalStateTest method testGetIndexNotExists.
@Test
public void testGetIndexNotExists() throws IOException {
StateBackend mockBackend = mock(StateBackend.class);
PersistentGlobalState initialState = new PersistentGlobalState();
when(mockBackend.loadOrCreateGlobalState()).thenReturn(initialState);
MockBackendGlobalState.stateBackend = mockBackend;
BackendGlobalState backendGlobalState = new MockBackendGlobalState(getConfig(), null);
try {
backendGlobalState.getIndex("test_index");
fail();
} catch (IllegalArgumentException e) {
assertEquals("index \"test_index\" was not saved or committed", e.getMessage());
}
}
use of com.yelp.nrtsearch.server.luceneserver.state.backend.StateBackend in project nrtsearch by Yelp.
the class BackendGlobalStateTest method testGetCreatedIndex.
@Test
public void testGetCreatedIndex() throws IOException {
StateBackend mockBackend = mock(StateBackend.class);
PersistentGlobalState initialState = new PersistentGlobalState();
when(mockBackend.loadOrCreateGlobalState()).thenReturn(initialState);
MockBackendGlobalState.stateBackend = mockBackend;
BackendGlobalState backendGlobalState = new MockBackendGlobalState(getConfig(), null);
backendGlobalState.createIndex("test_index");
assertEquals(1, backendGlobalState.getIndexNames().size());
assertTrue(backendGlobalState.getIndexNames().contains("test_index"));
IndexState createdState = backendGlobalState.getIndex("test_index");
assertNotNull(createdState);
IndexState getIndexState = backendGlobalState.getIndex("test_index");
assertSame(createdState, getIndexState);
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);
}
use of com.yelp.nrtsearch.server.luceneserver.state.backend.StateBackend in project nrtsearch by Yelp.
the class BackendGlobalStateTest method testCreateNewIndex.
@Test
public void testCreateNewIndex() throws IOException {
StateBackend mockBackend = mock(StateBackend.class);
PersistentGlobalState initialState = new PersistentGlobalState();
when(mockBackend.loadOrCreateGlobalState()).thenReturn(initialState);
MockBackendGlobalState.stateBackend = mockBackend;
BackendGlobalState backendGlobalState = new MockBackendGlobalState(getConfig(), null);
backendGlobalState.createIndex("test_index");
assertEquals(1, backendGlobalState.getIndexNames().size());
assertTrue(backendGlobalState.getIndexNames().contains("test_index"));
assertNotNull(backendGlobalState.getIndex("test_index"));
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);
}
use of com.yelp.nrtsearch.server.luceneserver.state.backend.StateBackend 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());
}
}
Aggregations