Search in sources :

Example 6 with StateBackend

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);
}
Also used : StateBackend(com.yelp.nrtsearch.server.luceneserver.state.backend.StateBackend) RemoteStateBackend(com.yelp.nrtsearch.server.luceneserver.state.backend.RemoteStateBackend) LocalStateBackend(com.yelp.nrtsearch.server.luceneserver.state.backend.LocalStateBackend) Test(org.junit.Test)

Example 7 with StateBackend

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);
}
Also used : StateBackend(com.yelp.nrtsearch.server.luceneserver.state.backend.StateBackend) RemoteStateBackend(com.yelp.nrtsearch.server.luceneserver.state.backend.RemoteStateBackend) LocalStateBackend(com.yelp.nrtsearch.server.luceneserver.state.backend.LocalStateBackend) IndexState(com.yelp.nrtsearch.server.luceneserver.IndexState) Test(org.junit.Test)

Example 8 with StateBackend

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);
}
Also used : StateBackend(com.yelp.nrtsearch.server.luceneserver.state.backend.StateBackend) RemoteStateBackend(com.yelp.nrtsearch.server.luceneserver.state.backend.RemoteStateBackend) LocalStateBackend(com.yelp.nrtsearch.server.luceneserver.state.backend.LocalStateBackend) Test(org.junit.Test)

Example 9 with StateBackend

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);
}
Also used : HashMap(java.util.HashMap) IndexInfo(com.yelp.nrtsearch.server.luceneserver.state.PersistentGlobalState.IndexInfo) StateBackend(com.yelp.nrtsearch.server.luceneserver.state.backend.StateBackend) RemoteStateBackend(com.yelp.nrtsearch.server.luceneserver.state.backend.RemoteStateBackend) LocalStateBackend(com.yelp.nrtsearch.server.luceneserver.state.backend.LocalStateBackend) Test(org.junit.Test)

Example 10 with StateBackend

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);
}
Also used : HashMap(java.util.HashMap) IndexInfo(com.yelp.nrtsearch.server.luceneserver.state.PersistentGlobalState.IndexInfo) StateBackend(com.yelp.nrtsearch.server.luceneserver.state.backend.StateBackend) RemoteStateBackend(com.yelp.nrtsearch.server.luceneserver.state.backend.RemoteStateBackend) LocalStateBackend(com.yelp.nrtsearch.server.luceneserver.state.backend.LocalStateBackend) Test(org.junit.Test)

Aggregations

LocalStateBackend (com.yelp.nrtsearch.server.luceneserver.state.backend.LocalStateBackend)11 RemoteStateBackend (com.yelp.nrtsearch.server.luceneserver.state.backend.RemoteStateBackend)11 StateBackend (com.yelp.nrtsearch.server.luceneserver.state.backend.StateBackend)11 Test (org.junit.Test)11 IndexInfo (com.yelp.nrtsearch.server.luceneserver.state.PersistentGlobalState.IndexInfo)3 HashMap (java.util.HashMap)3 IndexState (com.yelp.nrtsearch.server.luceneserver.IndexState)2