use of com.yelp.nrtsearch.server.luceneserver.state.backend.StateBackend in project nrtsearch by Yelp.
the class BackendGlobalStateTest method testDeleteCreatedIndex.
@Test
public void testDeleteCreatedIndex() 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");
backendGlobalState.createIndex("test_index_2");
assertEquals(2, backendGlobalState.getIndexNames().size());
assertTrue(backendGlobalState.getIndexNames().contains("test_index"));
assertTrue(backendGlobalState.getIndexNames().contains("test_index_2"));
assertNotNull(backendGlobalState.getIndex("test_index"));
assertNotNull(backendGlobalState.getIndex("test_index_2"));
backendGlobalState.deleteIndex("test_index");
assertEquals(1, backendGlobalState.getIndexNames().size());
assertNotNull(backendGlobalState.getIndex("test_index_2"));
verify(mockBackend, times(1)).loadOrCreateGlobalState();
ArgumentCaptor<PersistentGlobalState> stateArgumentCaptor = ArgumentCaptor.forClass(PersistentGlobalState.class);
verify(mockBackend, times(3)).commitGlobalState(stateArgumentCaptor.capture());
PersistentGlobalState committedState = stateArgumentCaptor.getAllValues().get(0);
assertEquals(1, committedState.getIndices().size());
assertNotNull(committedState.getIndices().get("test_index"));
committedState = stateArgumentCaptor.getAllValues().get(1);
assertEquals(2, committedState.getIndices().size());
assertNotNull(committedState.getIndices().get("test_index"));
assertNotNull(committedState.getIndices().get("test_index_2"));
committedState = stateArgumentCaptor.getAllValues().get(2);
assertEquals(1, committedState.getIndices().size());
assertNotNull(committedState.getIndices().get("test_index_2"));
verifyNoMoreInteractions(mockBackend);
}
use of com.yelp.nrtsearch.server.luceneserver.state.backend.StateBackend in project nrtsearch by Yelp.
the class BackendGlobalStateTest method testIndexClosed.
@Test
public void testIndexClosed() 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");
IndexState state1 = backendGlobalState.getIndex("test_index");
IndexState state2 = backendGlobalState.getIndex("test_index");
assertSame(state1, state2);
backendGlobalState.indexClosed("test_index");
IndexState state3 = backendGlobalState.getIndex("test_index");
assertNotSame(state1, state3);
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 testCreateIndexMultiple.
@Test
public void testCreateIndexMultiple() 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");
backendGlobalState.createIndex("test_index_2");
assertEquals(2, backendGlobalState.getIndexNames().size());
assertTrue(backendGlobalState.getIndexNames().contains("test_index"));
assertTrue(backendGlobalState.getIndexNames().contains("test_index_2"));
assertNotNull(backendGlobalState.getIndex("test_index"));
assertNotNull(backendGlobalState.getIndex("test_index_2"));
verify(mockBackend, times(1)).loadOrCreateGlobalState();
ArgumentCaptor<PersistentGlobalState> stateArgumentCaptor = ArgumentCaptor.forClass(PersistentGlobalState.class);
verify(mockBackend, times(2)).commitGlobalState(stateArgumentCaptor.capture());
PersistentGlobalState committedState = stateArgumentCaptor.getAllValues().get(0);
assertEquals(1, committedState.getIndices().size());
assertNotNull(committedState.getIndices().get("test_index"));
committedState = stateArgumentCaptor.getAllValues().get(1);
assertEquals(2, committedState.getIndices().size());
assertNotNull(committedState.getIndices().get("test_index"));
assertNotNull(committedState.getIndices().get("test_index_2"));
verifyNoMoreInteractions(mockBackend);
}
use of com.yelp.nrtsearch.server.luceneserver.state.backend.StateBackend 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.backend.StateBackend 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