/** * Does any additional processing after the patch operation has been completed. * * @param current */ private void processPatch(final State current) { try { Type stateType = Class.forName(current.triggerStateClassName); ServiceDocument postState = Utils.fromJson(current.serializedTriggerState, stateType); postState.documentExpirationTimeMicros = ServiceUtils.computeExpirationTime(current.taskExpirationAgeMillis); Operation post = Operation.createPost(UriUtils.buildUri(getHost(), current.factoryServiceLink)) .setBody(postState); this.sendRequest(post); } catch (ClassNotFoundException ex) { logFailure(ex); } }
@Test public void testWaitForQuery() throws Throwable { ExampleService exampleService = new ExampleService(); final ExampleService.ExampleServiceState exampleServiceState = new ExampleService.ExampleServiceState(); exampleServiceState.name = UUID.randomUUID().toString(); QueryTask.Query kindClause = new QueryTask.Query() .setTermPropertyName(ServiceDocument.FIELD_NAME_KIND) .setTermMatchValue(Utils.buildKind(ExampleService.ExampleServiceState.class)); QueryTask.Query nameClause = new QueryTask.Query() .setTermPropertyName("name") .setTermMatchValue(exampleServiceState.name); QueryTask.QuerySpecification spec = new QueryTask.QuerySpecification(); spec.query.addBooleanClause(kindClause); spec.query.addBooleanClause(nameClause); spec.options = EnumSet.of(QueryTask.QuerySpecification.QueryOption.EXPAND_CONTENT); QueryTask query = QueryTask.create(spec).setDirect(true); try { host.waitForQuery( query, new Predicate<QueryTask>() { @Override public boolean test(QueryTask queryTask) { return queryTask.results.documentLinks.size() > 0; } }); Assert.fail("waitForQuery should not have succeeded before documents are created"); } catch (RuntimeException runtimeException) { assertThat( runtimeException.getMessage(), is(equalToIgnoringCase("timeout waiting for query result."))); } Operation post = host.startServiceSynchronously(exampleService, exampleServiceState); assertThat(post.getStatusCode(), is(200)); ExampleService.ExampleServiceState result = host.getServiceState(ExampleService.ExampleServiceState.class); assertThat(result.name, is(exampleServiceState.name)); QueryTask response = host.waitForQuery( query, new Predicate<QueryTask>() { @Override public boolean test(QueryTask queryTask) { return queryTask.results.documentLinks.size() > 0; } }); assertThat(response.results.documentLinks.size(), is(1)); // verify fields are passed down correctly for (Map.Entry<String, Object> document : response.results.documents.entrySet()) { ExampleService.ExampleServiceState docState = Utils.fromJson(document.getValue(), ExampleService.ExampleServiceState.class); assertThat(docState.name, is(equalTo(exampleServiceState.name))); } }