@Test
public void testQueryUpdatedDocumentSince() throws Throwable {

    long futureDate = Utils.getNowMicrosUtc() + TimeUnit.DAYS.toMicros(1);
    try {
        this.queryHelper.setUpdatedSince(futureDate);
        fail("IllegalArgumentException expected when date in future.");
    } catch (IllegalArgumentException e) {
        //expected
    }
    long startTime = Utils.getNowMicrosUtc();
    this.minimalTestStates = queryDocumentUpdatedSince(startTime, "testLink");
    assertEquals(0, this.minimalTestStates.size());
    MinimalTestServiceState minimalTestState = new MinimalTestServiceState();
    minimalTestState.id = this.idValue1;
    minimalTestState = doPost(minimalTestState);
    long timeAfterPost = Utils.getNowMicrosUtc();
    // match time but invalid link
    this.minimalTestStates = queryDocumentUpdatedSince(startTime, "testLink");
    assertEquals(0, this.minimalTestStates.size());
    // match link but invalid time
    this.minimalTestStates = queryDocumentUpdatedSince(timeAfterPost,
            minimalTestState.documentSelfLink);
    assertEquals(0, this.minimalTestStates.size());
    // match link but invalid time
    this.minimalTestStates = queryDocumentUpdatedSince(startTime,
            minimalTestState.documentSelfLink);
    assertEquals(1, this.minimalTestStates.size());
    minimalTestState.id = this.idValue2;
    minimalTestState = doPatch(minimalTestState);
    assertEquals(this.idValue2, minimalTestState.id);
    long timeAfterPatch = Utils.getNowMicrosUtc();
    // the delta for the update should be retrieved
    this.minimalTestStates = queryDocumentUpdatedSince(timeAfterPost,
            minimalTestState.documentSelfLink);
    assertEquals(1, this.minimalTestStates.size());
    assertEquals(this.idValue2, this.minimalTestStates.get(0).id);
    // no updates after patch
    this.minimalTestStates = queryDocumentUpdatedSince(timeAfterPatch,
            minimalTestState.documentSelfLink);
    assertEquals(0, this.minimalTestStates.size());
    delete(minimalTestState);
    long timeAfterDelete = Utils.getNowMicrosUtc();
    this.minimalTestStates = queryDocumentUpdatedSince(timeAfterPatch,
            minimalTestState.documentSelfLink);
    assertEquals(1, this.minimalTestStates.size());
    assertTrue(ServiceDocument.isDeleted(this.minimalTestStates.get(0)));
    this.minimalTestStates = queryDocumentUpdatedSince(timeAfterDelete,
            minimalTestState.documentSelfLink);
    assertEquals(0, this.minimalTestStates.size());
}