Utils { @SuppressWarnings("checkstyle:AbbreviationAsWordInName") public static void indexADocument(String indexName, Document document) throws InterruptedException { IndexSpec indexSpec = IndexSpec.newBuilder().setName(indexName).build(); Index index = SearchServiceFactory.getSearchService().getIndex(indexSpec); final int maxRetry = 3; int attempts = 0; int delay = 2; while (true) { try { index.put(document); } catch (PutException e) { if (StatusCode.TRANSIENT_ERROR.equals(e.getOperationResult().getCode()) && ++attempts < maxRetry) { Thread.sleep(delay * 1000); delay *= 2; continue; } else { throw e; } } break; } }  @SuppressWarnings("checkstyle:AbbreviationAsWordInName") static void indexADocument(String indexName, Document document);  }
@Test @SuppressWarnings("checkstyle:AbbreviationAsWordInName") public void indexADocument_successfullyInvoked() throws Exception { String id = "test"; Document doc = Document.newBuilder() .setId(id) .addField(Field.newBuilder().setName("f").setText("v")) .build(); Utils.indexADocument(INDEX, doc); IndexSpec indexSpec = IndexSpec.newBuilder().setName(INDEX).build(); Index index = SearchServiceFactory.getSearchService().getIndex(indexSpec); Document fetched = index.get(id); assertWithMessage("A value of the fetched document") .that(fetched.getOnlyField("f").getText()) .isEqualTo("v"); }