public void test() { SenseiSnappyProtoSerializer serializer = new SenseiSnappyProtoSerializer(); SenseiRequest request = new SenseiRequest(); request.setRouteParam("1"); SenseiRequest serializedRequest = serializer.requestFromBytes(serializer.requestToBytes(request)); assertEquals(request, serializedRequest); SenseiResult result = new SenseiResult(); SenseiHit[] hits = new SenseiHit[1]; hits[0] = new SenseiHit(); hits[0].setUID(5); SenseiHit[] groupHits = new SenseiHit[2]; groupHits[0] = new SenseiHit(); groupHits[1] = new SenseiHit(); hits[0].setGroupHits(groupHits); // hits[1] = new SenseiHit(); // hits[1].setUID(6); result.setHits(hits); SenseiResult serializedResult = serializer.responseFromBytes(serializer.responseToBytes(result)); assertEquals(result, serializedResult); }
@Override public SenseiResult mergeResults(SenseiRequest request, List<SenseiResult> resultList) { SenseiResult res = ResultMerger.merge(request, resultList, false); if (request.isFetchStoredFields() || request.isFetchStoredValue()) recoverSrcData(res, res.getSenseiHits(), request.isFetchStoredFields()); return res; }
private static void waitTillServerStarts() throws Exception { SenseiRequest req = new SenseiRequest(); SenseiResult res = null; int count = 0; do { Thread.sleep(500); res = broker.browse(req); System.out.println("" + res.getNumHits() + " loaded..."); ++count; } while (count < 20 && res.getNumHits() < 15000); }
@Override public SenseiResult mergeResults(SenseiRequest request, List<SenseiResult> resultList) { SenseiResult res = ResultMerger.merge(request, resultList, false); if (request.isFetchStoredFields() || request.isFetchStoredValue()) { long start = System.currentTimeMillis(); recoverSrcData(res, res.getSenseiHits(), request.isFetchStoredFields()); res.setTime(res.getTime() + (System.currentTimeMillis() - start)); } return res; }
public static void recoverSrcData( SenseiResult res, SenseiHit[] hits, boolean isFetchStoredFields) { if (hits != null) { for (SenseiHit hit : hits) { try { byte[] dataBytes = hit.getStoredValue(); if (dataBytes == null || dataBytes.length == 0) { dataBytes = hit.getFieldBinaryValue(AbstractZoieIndexable.DOCUMENT_STORE_FIELD); } if (dataBytes != null && dataBytes.length > 0) { byte[] data = null; try { // TODO need check SenseiSchema.isCompressSrcData() data = DefaultJsonSchemaInterpreter.decompress(dataBytes); } catch (Exception ex) { data = dataBytes; } hit.setSrcData(new String(data, "UTF-8")); } } catch (Exception e) { logger.error(e.getMessage(), e); res.getErrors().add(new SenseiError(e.getMessage(), ErrorType.BrokerGatherError)); } recoverSrcData(res, hit.getSenseiGroupHits(), isFetchStoredFields); // Remove stored fields since the user is not requesting: if (!isFetchStoredFields) { hit.setStoredFields((List<SerializableField>) null); } } } }
@Override public List<SenseiResult> doQuery(final SenseiRequest senseiRequest) { final List<SenseiResult> resultList = new ArrayList<SenseiResult>(); try { resultList.addAll( scatterTimer.time( new Callable<List<SenseiResult>>() { @Override public List<SenseiResult> call() throws Exception { return doCall(senseiRequest); } })); } catch (Exception e) { ErrorMeter.mark(); SenseiResult emptyResult = getEmptyResultInstance(); logger.error("Error running scatter/gather", e); emptyResult.addError( new SenseiError( "Error gathering the results" + e.getMessage(), ErrorType.BrokerGatherError)); return Arrays.asList(emptyResult); } return resultList; }
public static void recoverSrcData( SenseiResult res, SenseiHit[] hits, boolean isFetchStoredFields) { if (hits != null) { for (SenseiHit hit : hits) { try { byte[] dataBytes = hit.getStoredValue(); if (dataBytes == null || dataBytes.length == 0) { Document doc = hit.getStoredFields(); if (doc != null) { dataBytes = doc.getBinaryValue(AbstractZoieIndexable.DOCUMENT_STORE_FIELD); if (dataBytes == null || dataBytes.length == 0) { dataBytes = doc.getBinaryValue(SenseiSchema.SRC_DATA_COMPRESSED_FIELD_NAME); if (dataBytes == null || dataBytes.length == 0) { dataBytes = doc.getBinaryValue(SenseiSchema.SRC_DATA_FIELD_NAME); if (dataBytes != null && dataBytes.length > 0) { hit.setSrcData(new String(dataBytes, "UTF-8")); dataBytes = null; // set to null to avoid gunzip. } } doc.removeFields(SenseiSchema.SRC_DATA_COMPRESSED_FIELD_NAME); doc.removeFields(SenseiSchema.SRC_DATA_FIELD_NAME); } } } if (dataBytes != null && dataBytes.length > 0) { byte[] data; try { data = DefaultJsonSchemaInterpreter.decompress(dataBytes); } catch (Exception ex) { data = dataBytes; } hit.setSrcData(new String(data, "UTF-8")); } } catch (Exception e) { logger.error(e.getMessage(), e); res.getErrors().add(new SenseiError(e.getMessage(), ErrorType.BrokerGatherError)); } recoverSrcData(res, hit.getSenseiGroupHits(), isFetchStoredFields); // Remove stored fields since the user is not requesting: if (!isFetchStoredFields) hit.setStoredFields(null); } } }
public void test1() { SenseiResult result = inMemorySenseiService.doQuery(InMemoryIndexPerfTest.getRequest(), docs); assertEquals(16, result.getNumHits()); assertEquals(100, result.getTotalDocs()); }