SearchServlet extends HttpServlet { @Override public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { PrintWriter out = resp.getWriter(); Document doc = Document.newBuilder() .setId("theOnlyPiano") .addField(Field.newBuilder().setName("product").setText("piano")) .addField(Field.newBuilder().setName("maker").setText("Yamaha")) .addField(Field.newBuilder().setName("price").setNumber(4000)) .build(); try { Utils.indexADocument(SEARCH_INDEX, doc); } catch (InterruptedException e) { } final int maxRetry = 3; int attempts = 0; int delay = 2; while (true) { try { String queryString = "product = piano AND price < 5000"; Results<ScoredDocument> results = getIndex().search(queryString); for (ScoredDocument document : results) { out.print("maker: " + document.getOnlyField("maker").getText()); out.println(", price: " + document.getOnlyField("price").getNumber()); } } catch (SearchException e) { if (StatusCode.TRANSIENT_ERROR.equals(e.getOperationResult().getCode()) && ++attempts < maxRetry) { try { Thread.sleep(delay * 1000); } catch (InterruptedException e1) { } delay *= 2; continue; } else { throw e; } } break; } out.println("Search performed"); Index index = getIndex(); index.search("rose water"); index.search("1776-07-04"); index.search("product = piano AND price < 5000"); }  @Override void doGet(HttpServletRequest req, HttpServletResponse resp);  }
@Test public void doGet_successfulyInvoked() throws Exception { servletUnderTest.doGet(mockRequest, mockResponse); String content = responseWriter.toString(); assertWithMessage("SearchServlet response").that(content).contains("maker: Yamaha"); assertWithMessage("SearchServlet response").that(content).contains("price: 4000.0"); }