ProxyRetrieval implements InvocationHandler { public void close() throws IOException { } ProxyRetrieval(String url, Parameters parameters); void close(); @Override Object invoke(Object caller, Method method, Object[] args); Object invoke(String methodName, Object[] args); void setRetrieval(Retrieval retrieval);  }
@Test public void testProxyRet() throws Exception { final int vocab = 1000; final int docCount = 1000; final int docLen = 100; final int port = 1111; File index = null; AtomicBoolean started = new AtomicBoolean(false); try { index = makeIndex(docCount, docLen, vocab); final Parameters retParams = Parameters.create(); retParams.set("index", index.getAbsolutePath()); retParams.set("port", port); final List<Exception> exceptions = Collections.synchronizedList(new ArrayList<Exception>()); Thread remoteRetThread = new Thread(new Runnable() { @Override public void run() { try { System.out.println("remoteRetThread.start()"); started.set(true); App.run("search", retParams, System.err); } catch (InterruptedException i) { System.err.println("INTERRUPTED!"); } catch (Exception e) { exceptions.add(e); } } }); remoteRetThread.start(); while(!started.get()) { Thread.sleep(20); } String url = "http: boolean success = false; for (int i = 0; i < 30; i++) { if(checkReadyURL(url)) { success = true; } Thread.sleep(100); } if (!success) { remoteRetThread.interrupt(); throw new RuntimeException("FAILED! could not find local proxy..."); } Parameters proxyParams = Parameters.create(); proxyParams.set("index", url); Retrieval instance = RetrievalFactory.create(proxyParams); try { instance.getAvailableParts(); instance.getCollectionStatistics(StructuredQuery.parse("#lengths:document:part=lengths()")); instance.getCollectionStatistics("#lengths:document:part=lengths()"); Document d = instance.getDocument("doc-" + 2, new DocumentComponents(true, false, false)); assertNotNull(d.text); assertNull(d.terms); assertNull(d.tags); assertTrue(d.metadata.isEmpty()); instance.getDocumentLength("doc-" + 2); instance.getDocumentLength(1L); instance.getDocumentName(1L); ArrayList<String> names = new ArrayList<String>(); names.add("doc-" + 1); names.add("doc-" + 2); instance.getDocuments(names, new DocumentComponents()); instance.getGlobalParameters(); instance.getIndexPartStatistics("postings"); instance.getNodeStatistics(StructuredQuery.parse("#counts:@/1/:part=postings()")); instance.getNodeStatistics("#counts:@/1/:part=postings()"); instance.getNodeType(StructuredQuery.parse("#counts:@/1/:part=postings()")); instance.getQueryType(StructuredQuery.parse("#counts:@/1/:part=postings()")); Node trans = instance.transformQuery(StructuredQuery.parse("#combine(1 2 3)"), Parameters.create()); instance.executeQuery(trans); instance.executeQuery(trans, Parameters.create()); instance.close(); } catch (Exception e) { exceptions.add(e); } remoteRetThread.interrupt(); for (Exception e : exceptions) { System.err.println(e.getMessage()); e.printStackTrace(); } if (!exceptions.isEmpty()) { throw new RuntimeException("FAILED THREADING TEST."); } } finally { if (index != null) { FSUtil.deleteDirectory(index); } } }