@Test public void shouldReturnNoErrors() { QueryResponse r = createResponse(new String[] {"Foo"}, new JsonArray()); Assert.assertEquals(r.getErrors().length, 1, "Error length correct"); Assert.assertEquals(r.getErrors()[0], "Foo"); Assert.assertFalse(r.wasSuccessful()); Assert.assertEquals(r.getTotalResultCount(), 0); Assert.assertEquals(r.getResults().size(), 0); }
private int doXQuery(String qry) throws RemoteException { QueryResponse rsp = query.xquery(sessionId, qry.getBytes()); int noHits = rsp.getHits(); if (noHits > 0) { String[] rsps = query.retrieve(sessionId, 1, noHits, true, false, "none"); for (int i = 0; i < rsps.length; i++) { System.out.println(rsps[i]); } assertEquals(noHits, rsps.length); } else { System.out.println("No hits"); } return noHits; }
public Object makeObject() throws Exception { QueryResponse object = new QueryResponse(); MessageHandlerRunner runner = messageHandlerRunner.newInstance(); ParameterMapping.mappingObject(runner, runnerParameters, null); if (runner instanceof Initialisable) { ((Initialisable) runner).init(); } object.setMessageHandlerRunner(runner); if (object instanceof Initialisable) { ((Initialisable) object).init(); } return object; }
@Override public int getResultSize() { int accumulator; if (resultSize == null) { ClusteredQueryCommand command = ClusteredQueryCommand.getResultSize(hSearchQuery, cache); ClusteredQueryInvoker invoker = new ClusteredQueryInvoker(cache, asyncExecutor); List<QueryResponse> responses = invoker.broadcast(command); accumulator = 0; for (QueryResponse response : responses) { accumulator += response.getResultSize(); } resultSize = Integer.valueOf(accumulator); } else { accumulator = resultSize.intValue(); } return accumulator; }
private Response getResponse(MissionInfo info) { QueryResponse response = new QueryResponse(); Snapshot snapshot = info.getSnapshot(); response.setTime(snapshot.getTimestamp()); response.setVersion(snapshot.getVersion()); response.setMinVersion(snapshot.getMinVersion()); response.setMaxVersion(snapshot.getMaxVersion()); Report report = snapshot.getReport(); response.setRunning(info.getState().equals(LAUNCHED)); response.setReport(Arrays.asList(report.getAllMetrics())); return response; }
@Test public void shouldReturnResults() { JsonArray results = new JsonArray(); JsonObject r1 = new JsonObject(); r1.addProperty("Foo", 7); results.add(r1); JsonObject r2 = new JsonObject(); r2.addProperty("Foo", 1); results.add(r2); QueryResponse r = createResponse(new String[] {}, results); Assert.assertEquals(r.getErrors().length, 0, "Error length correct"); Assert.assertEquals(r.getTotalResultCount(), 2, "Total result count correct"); Assert.assertEquals(r.getResults().size(), 2, "Result length correct"); Assert.assertEquals( r.getResults().get(0).getAsJsonObject().get("Foo").getAsInt(), 7, "First error correct"); Assert.assertEquals( r.getResults().get(1).getAsJsonObject().get("Foo").getAsInt(), 1, "First error correct"); Assert.assertTrue(r.wasSuccessful()); Assert.assertEquals(r.getPageSize(), 20); Assert.assertEquals(r.getStart(), 1); }
private HashMap<UUID, ClusteredTopDocs> broadcastQuery(ClusteredQueryCommand command) { ClusteredQueryInvoker invoker = new ClusteredQueryInvoker(cache, asyncExecutor); HashMap<UUID, ClusteredTopDocs> topDocsResponses = new HashMap<UUID, ClusteredTopDocs>(); int resultSize = 0; List<QueryResponse> responses = invoker.broadcast(command); for (Object response : responses) { QueryResponse queryResponse = (QueryResponse) response; ClusteredTopDocs topDocs = new ClusteredTopDocs(queryResponse.getTopDocs(), queryResponse.getNodeUUID()); resultSize += queryResponse.getResultSize(); topDocs.setNodeAddress(queryResponse.getAddress()); topDocsResponses.put(queryResponse.getNodeUUID(), topDocs); } this.resultSize = resultSize; return topDocsResponses; }
public void passivateObject(Object obj) throws Exception { QueryResponse object = (QueryResponse) obj; object.getRunner().reset(); }