Search in sources :

Example 1 with StateBackend

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());
}
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 2 with StateBackend

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());
    }
}
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 3 with StateBackend

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);
}
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 4 with StateBackend

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);
}
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 5 with StateBackend

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());
    }
}
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