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