Search in sources :

Example 1 with SolrClient

use of org.codice.solr.client.solrj.SolrClient in project ddf by codice.

the class RemoteSolrCatalogProviderTest method testAvailabilitySourceMonitor.

@Test
public void testAvailabilitySourceMonitor() throws Exception {
    final SolrClient client = givenSolrClient(false);
    CatalogProvider provider = new MockedRemoteSolrCatalogProvider(client);
    final SourceMonitor monitor = mock(SourceMonitor.class);
    assertThat(provider.isAvailable(monitor), is(false));
    final ArgumentCaptor<Listener> listener = ArgumentCaptor.forClass(Listener.class);
    verify(client).isAvailable(listener.capture());
    verify(client).ping();
    // when the underlying listener is called with not available
    listener.getValue().changed(client, false);
    // so should our monitor
    verify(monitor).setUnavailable();
    // when the underlying listener is called with available
    listener.getValue().changed(client, true);
    // so should our monitor
    verify(monitor).setAvailable();
}
Also used : Listener(org.codice.solr.client.solrj.SolrClient.Listener) SolrClient(org.codice.solr.client.solrj.SolrClient) CatalogProvider(ddf.catalog.source.CatalogProvider) SourceMonitor(ddf.catalog.source.SourceMonitor) Test(org.junit.Test)

Example 2 with SolrClient

use of org.codice.solr.client.solrj.SolrClient in project ddf by codice.

the class RemoteSolrCatalogProviderTest method givenSolrClient.

/**
 * @return
 * @throws IOException
 * @throws SolrServerException
 */
private SolrClient givenSolrClient(boolean ok) throws SolrServerException, IOException {
    SolrClient client = mock(SolrClient.class);
    SolrPingResponse pingResponse = mock(SolrPingResponse.class);
    NamedList<Object> namedList = new NamedList<>();
    if (ok) {
        namedList.add("status", "OK");
    } else {
        namedList.add("status", "NOT_OK");
    }
    when(pingResponse.getResponse()).thenReturn(namedList);
    when(client.ping()).thenReturn(pingResponse);
    return client;
}
Also used : SolrPingResponse(org.apache.solr.client.solrj.response.SolrPingResponse) SolrClient(org.codice.solr.client.solrj.SolrClient) NamedList(org.apache.solr.common.util.NamedList)

Example 3 with SolrClient

use of org.codice.solr.client.solrj.SolrClient in project ddf by codice.

the class RemoteSolrCatalogProviderTest method testShutdown.

@Test
public void testShutdown() throws SolrServerException, IOException {
    SolrClient givenClient = mock(SolrClient.class);
    RemoteSolrCatalogProvider provider = new MockedRemoteSolrCatalogProvider(givenClient);
    provider.shutdown();
    verify(givenClient, times(1)).close();
}
Also used : SolrClient(org.codice.solr.client.solrj.SolrClient) Test(org.junit.Test)

Example 4 with SolrClient

use of org.codice.solr.client.solrj.SolrClient in project ddf by codice.

the class RemoteSolrCatalogProviderTest method testIsAvailableWhenSolrClientStatusNotOk.

@Test
public void testIsAvailableWhenSolrClientStatusNotOk() throws Exception {
    final SolrClient client = givenSolrClient(false);
    CatalogProvider provider = new MockedRemoteSolrCatalogProvider(client);
    assertThat(provider.isAvailable(), is(false));
    verify(client).ping();
}
Also used : SolrClient(org.codice.solr.client.solrj.SolrClient) CatalogProvider(ddf.catalog.source.CatalogProvider) Test(org.junit.Test)

Example 5 with SolrClient

use of org.codice.solr.client.solrj.SolrClient in project ddf by codice.

the class CacheCommandTest method testCacheClear.

@Test
public void testCacheClear() throws Exception {
    SolrClient cloudClient = mock(SolrClient.class);
    NamedList<Object> pingStatus = new NamedList<>();
    pingStatus.add("status", "OK");
    when(cloudClient.isAvailable()).thenReturn(true);
    UpdateResponse mockUpdateResponse = mock(UpdateResponse.class);
    when(cloudClient.deleteByQuery(any(String.class), any(String.class))).thenReturn(mockUpdateResponse);
    when(mockUpdateResponse.getStatus()).thenReturn(0);
    CacheCommand command = new CacheCommand();
    command.setClient(cloudClient);
    command.force = true;
    command.clear = true;
    Object result = command.execute();
    assertThat(result, is(Boolean.TRUE));
}
Also used : UpdateResponse(org.apache.solr.client.solrj.response.UpdateResponse) SolrClient(org.codice.solr.client.solrj.SolrClient) NamedList(org.apache.solr.common.util.NamedList) Test(org.junit.Test)

Aggregations

SolrClient (org.codice.solr.client.solrj.SolrClient)12 Test (org.junit.Test)7 IOException (java.io.IOException)4 SolrServerException (org.apache.solr.client.solrj.SolrServerException)4 SolrException (org.apache.solr.common.SolrException)3 NamedList (org.apache.solr.common.util.NamedList)3 PersistenceException (org.codice.ddf.persistence.PersistenceException)3 CatalogProvider (ddf.catalog.source.CatalogProvider)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 SolrQuery (org.apache.solr.client.solrj.SolrQuery)2 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)2 UpdateResponse (org.apache.solr.client.solrj.response.UpdateResponse)2 SolrDocumentList (org.apache.solr.common.SolrDocumentList)2 CatalogFramework (ddf.catalog.CatalogFramework)1 CreateRequest (ddf.catalog.operation.CreateRequest)1 CreateResponse (ddf.catalog.operation.CreateResponse)1 SourceMonitor (ddf.catalog.source.SourceMonitor)1 SolrMetacardClientImpl (ddf.catalog.source.solr.SolrMetacardClientImpl)1