use of org.cometd.bayeux.server.BayeuxServer in project ddf by codice.
the class SearchControllerTest method testMetacardTypeValuesCacheDisabled.
@Test
public void testMetacardTypeValuesCacheDisabled() throws Exception {
final String ID = "id";
Set<String> srcIds = new HashSet<String>();
srcIds.add(ID);
BayeuxServer bayeuxServer = mock(BayeuxServer.class);
ServerChannel channel = mock(ServerChannel.class);
ArgumentCaptor<ServerMessage.Mutable> reply = ArgumentCaptor.forClass(ServerMessage.Mutable.class);
when(bayeuxServer.getChannel(any(String.class))).thenReturn(channel);
SearchRequest request = new SearchRequest(srcIds, getQueryRequest("title LIKE 'Meta*'"), ID);
searchController.setBayeuxServer(bayeuxServer);
// Disable Cache
searchController.setCacheDisabled(true);
searchController.executeQuery(request, mockServerSession, null);
verify(channel, timeout(1000).only()).publish(any(ServerSession.class), reply.capture());
List<Mutable> replies = reply.getAllValues();
assertReplies(replies);
}
use of org.cometd.bayeux.server.BayeuxServer in project ddf by codice.
the class SearchControllerTest method testMetacardTypeValuesCacheEnabled.
@Test
public void testMetacardTypeValuesCacheEnabled() throws Exception {
final String ID = "id";
Set<String> srcIds = new HashSet<>();
srcIds.add(ID);
BayeuxServer bayeuxServer = mock(BayeuxServer.class);
ServerChannel channel = mock(ServerChannel.class);
ArgumentCaptor<ServerMessage.Mutable> reply = ArgumentCaptor.forClass(ServerMessage.Mutable.class);
when(bayeuxServer.getChannel(any(String.class))).thenReturn(channel);
SearchRequest request = new SearchRequest(srcIds, getQueryRequest("title LIKE 'Meta*'"), ID);
searchController.setBayeuxServer(bayeuxServer);
searchController.setCacheDisabled(false);
searchController.executeQuery(request, mockServerSession, null);
verify(channel, timeout(1000).times(2)).publish(any(ServerSession.class), reply.capture());
List<Mutable> replies = reply.getAllValues();
assertReplies(replies);
}
use of org.cometd.bayeux.server.BayeuxServer in project ddf by codice.
the class SearchControllerTest method testFailingQuery.
@Test
public void testFailingQuery() throws Exception {
// Setup
framework = mock(CatalogFramework.class);
QueryResponse response = mock(QueryResponse.class);
when(response.getResults()).thenThrow(new RuntimeException("Getting results failed"));
when(framework.query(any(QueryRequest.class))).thenReturn(response);
searchController = new SearchController(framework, new ActionRegistryImpl(Collections.emptyList(), Collections.emptyList()), new GeotoolsFilterAdapterImpl(), new SequentialExecutorService());
final String ID = "id";
Set<String> srcIds = new HashSet<>();
srcIds.add(ID);
SearchRequest request = new SearchRequest(srcIds, getQueryRequest("anyText LIKE '*'"), "queryId");
BayeuxServer bayeuxServer = mock(BayeuxServer.class);
ServerChannel channel = mock(ServerChannel.class);
when(bayeuxServer.getChannel(any(String.class))).thenReturn(channel);
searchController.setBayeuxServer(bayeuxServer);
searchController.setCacheDisabled(true);
// Perform Test
searchController.executeQuery(request, mockServerSession, null);
// Verify
verify(channel, times(1)).publish(any(), any());
}
use of org.cometd.bayeux.server.BayeuxServer in project ddf by codice.
the class SearchControllerTest method cacheQuery.
private List<String> cacheQuery(Set<String> srcIds, int queryRequestCount) throws CQLException, UnsupportedQueryException, SourceUnavailableException, FederationException {
SearchRequest request = new SearchRequest(srcIds, getQueryRequest("anyText LIKE '*'"), "queryId");
BayeuxServer bayeuxServer = mock(BayeuxServer.class);
ServerChannel channel = mock(ServerChannel.class);
when(bayeuxServer.getChannel(any(String.class))).thenReturn(channel);
ArgumentCaptor<QueryRequest> queryRequestCaptor = ArgumentCaptor.forClass(QueryRequest.class);
searchController.setCacheDisabled(false);
searchController.setNormalizationDisabled(false);
searchController.setBayeuxServer(bayeuxServer);
// Perform Test
searchController.executeQuery(request, mockServerSession, null);
// Verify
verify(framework, times(queryRequestCount)).query(queryRequestCaptor.capture());
List<QueryRequest> capturedQueryRequests = queryRequestCaptor.getAllValues();
List<String> modes = new ArrayList<>(queryRequestCount);
for (QueryRequest queryRequest : capturedQueryRequests) {
for (String key : queryRequest.getProperties().keySet()) {
modes.add((String) queryRequest.getPropertyValue(key));
}
}
return modes;
}
use of org.cometd.bayeux.server.BayeuxServer in project ddf by codice.
the class SearchControllerTest method testExecuteQueryCacheDisabled.
/**
* Verify that the CatalogFramework does not use the cache (i.e. the CatalogFramework
* is called WITHOUT the query request property mode=cache).
*/
@Test
public void testExecuteQueryCacheDisabled() throws Exception {
// Setup
final String ID = "id";
Set<String> srcIds = new HashSet<>(1);
srcIds.add(ID);
SearchRequest request = new SearchRequest(srcIds, getQueryRequest("title LIKE 'Meta*'"), ID);
BayeuxServer bayeuxServer = mock(BayeuxServer.class);
ServerChannel channel = mock(ServerChannel.class);
when(bayeuxServer.getChannel(any(String.class))).thenReturn(channel);
ArgumentCaptor<QueryRequest> queryRequestCaptor = ArgumentCaptor.forClass(QueryRequest.class);
// Enable Cache
searchController.setCacheDisabled(true);
searchController.setBayeuxServer(bayeuxServer);
// Perform Test
searchController.executeQuery(request, mockServerSession, null);
// Verify
verify(framework).query(queryRequestCaptor.capture());
assertThat(queryRequestCaptor.getValue().getProperties().size(), is(0));
}
Aggregations