Search in sources :

Example 26 with Discovery

use of siena.base.test.model.Discovery in project siena by mandubian.

the class BaseAsyncTest method testOffsetStatefulKeys.

public void testOffsetStatefulKeys() {
    Discovery[] discs = new Discovery[150];
    for (int i = 0; i < 150; i++) {
        discs[i] = new Discovery("Disc_" + i, LongAutoID_CURIE);
    }
    pm.insert((Object[]) discs).get();
    QueryAsync<Discovery> query = pm.createQuery(Discovery.class).stateful().order("id");
    SienaFuture<List<Discovery>> future = query.offset(50).fetchKeys();
    List<Discovery> res = future.get();
    assertEquals(100, res.size());
    for (int i = 0; i < 100; i++) {
        assertEquals(discs[i + 50].id, res.get(i).id);
        assertTrue(res.get(i).isOnlyIdFilled());
    }
}
Also used : Discovery(siena.base.test.model.Discovery) ArrayList(java.util.ArrayList) List(java.util.List)

Example 27 with Discovery

use of siena.base.test.model.Discovery in project siena by mandubian.

the class BaseAsyncTest method testIterPerPageStatefull3.

public void testIterPerPageStatefull3() {
    Discovery[] discs = new Discovery[500];
    for (int i = 0; i < 500; i++) {
        discs[i] = new Discovery("Disc_" + i, LongAutoID_CURIE);
    }
    pm.insert((Object[]) discs).get();
    QueryAsync<Discovery> query = pm.createQuery(Discovery.class).stateful().order("id");
    SienaFuture<Iterable<Discovery>> iter = query.offset(25).iterPerPage(50);
    Iterator<Discovery> it = iter.get().iterator();
    int i = 25;
    while (it.hasNext()) {
        assertEquals(discs[i++], it.next());
    }
    assertEquals(500, i);
}
Also used : Discovery(siena.base.test.model.Discovery)

Example 28 with Discovery

use of siena.base.test.model.Discovery in project siena by mandubian.

the class BaseAsyncTest method testFetchKeysPaginateStatelessNextPageRealAsync.

public void testFetchKeysPaginateStatelessNextPageRealAsync() {
    Discovery[] discs = new Discovery[10];
    for (int i = 0; i < 10; i++) {
        discs[i] = new Discovery("Disc_" + i, LongAutoID_CURIE);
    }
    pm.insert((Object[]) discs).get();
    QueryAsync<Discovery> query = pm.createQuery(Discovery.class).paginate(5).order("name");
    SienaFuture<List<Discovery>> future1 = query.fetchKeys();
    SienaFuture<List<Discovery>> future2 = query.nextPage().fetchKeys();
    List<Discovery> res = future1.get();
    assertEquals(5, res.size());
    for (int i = 0; i < 5; i++) {
        assertEquals(discs[i].id, res.get(i).id);
        assertTrue(res.get(i).isOnlyIdFilled());
    }
    res = future2.get();
    assertEquals(5, res.size());
    for (int i = 0; i < 5; i++) {
        assertEquals(discs[i + 5].id, res.get(i).id);
        assertTrue(res.get(i).isOnlyIdFilled());
    }
}
Also used : Discovery(siena.base.test.model.Discovery) ArrayList(java.util.ArrayList) List(java.util.List)

Example 29 with Discovery

use of siena.base.test.model.Discovery in project siena by mandubian.

the class BaseAsyncTest method testIterPaginateStatefulPreviousPageAsync.

public void testIterPaginateStatefulPreviousPageAsync() {
    Discovery[] discs = new Discovery[10];
    for (int i = 0; i < 10; i++) {
        discs[i] = new Discovery("Disc_" + i, LongAutoID_CURIE);
    }
    pm.insert((Object[]) discs).get();
    QueryAsync<Discovery> query = pm.createQuery(Discovery.class).paginate(5).stateful().order("name");
    SienaFuture<Iterable<Discovery>> future1 = query.iter();
    SienaFuture<Iterable<Discovery>> future2 = query.nextPage().iter();
    SienaFuture<Iterable<Discovery>> future3 = query.previousPage().iter();
    Iterator<Discovery> it = future1.get().iterator();
    int i = 0;
    while (it.hasNext()) {
        Discovery disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(5, i);
    it = future2.get().iterator();
    while (it.hasNext()) {
        Discovery disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(10, i);
    it = future3.get().iterator();
    i = 0;
    while (it.hasNext()) {
        Discovery disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(5, i);
}
Also used : Discovery(siena.base.test.model.Discovery)

Example 30 with Discovery

use of siena.base.test.model.Discovery in project siena by mandubian.

the class BaseAsyncTest method testFetchPaginateStatefulPreviouPageSeveralTimes.

public void testFetchPaginateStatefulPreviouPageSeveralTimes() {
    Discovery[] discs = new Discovery[15];
    for (int i = 0; i < 15; i++) {
        discs[i] = new Discovery("Disc_" + i, LongAutoID_CURIE);
    }
    pm.insert((Object[]) discs).get();
    QueryAsync<Discovery> query = pm.createQuery(Discovery.class).paginate(5).stateful().order("id");
    SienaFuture<List<Discovery>> future = query.fetch();
    List<Discovery> res = future.get();
    assertEquals(5, res.size());
    for (int i = 0; i < 5; i++) {
        assertEquals(discs[i], res.get(i));
    }
    future = query.nextPage().fetch();
    res = future.get();
    assertEquals(5, res.size());
    for (int i = 0; i < 5; i++) {
        assertEquals(discs[i + 5], res.get(i));
    }
    future = query.nextPage().fetch();
    res = future.get();
    assertEquals(5, res.size());
    for (int i = 0; i < 5; i++) {
        assertEquals(discs[i + 10], res.get(i));
    }
    future = query.previousPage().fetch();
    res = future.get();
    assertEquals(5, res.size());
    for (int i = 0; i < 5; i++) {
        assertEquals(discs[i + 5], res.get(i));
    }
    future = query.previousPage().fetch();
    res = future.get();
    assertEquals(5, res.size());
    for (int i = 0; i < 5; i++) {
        assertEquals(discs[i], res.get(i));
    }
}
Also used : Discovery(siena.base.test.model.Discovery) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

Discovery (siena.base.test.model.Discovery)212 ArrayList (java.util.ArrayList)71 List (java.util.List)68 SienaException (siena.SienaException)18 QueryOptionGaeContext (siena.gae.QueryOptionGaeContext)10 EnumLong (siena.base.test.model.DataTypes.EnumLong)2 QueryJoin (siena.QueryJoin)1