Search in sources :

Example 1 with Discovery

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

the class BaseAsyncTest method testFetchKeysPaginateStatefulPreviousPage.

public void testFetchKeysPaginateStatefulPreviousPage() {
    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<List<Discovery>> future = query.fetchKeys();
    List<Discovery> res = future.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());
    }
    future = query.nextPage().fetchKeys();
    res = future.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());
    }
    future = query.previousPage().fetchKeys();
    res = future.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());
    }
}
Also used : Discovery(siena.base.test.model.Discovery) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with Discovery

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

the class BaseAsyncTest method testIterPaginateStatelessNextPage.

public void testIterPaginateStatelessNextPage() {
    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");
    try {
        SienaFuture<Iterable<Discovery>> res = query.iter();
        Iterator<Discovery> it = res.get().iterator();
        int i = 0;
        while (it.hasNext()) {
            assertEquals(discs[i++], it.next());
        }
        assertEquals(5, i);
        res = query.nextPage().iter();
        it = res.get().iterator();
        while (it.hasNext()) {
            assertEquals(discs[i++], it.next());
        }
        assertEquals(10, i);
    } finally {
        query.release();
    }
}
Also used : Discovery(siena.base.test.model.Discovery)

Example 3 with Discovery

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

the class BaseAsyncTest method testFetchIterLotsOfEntitiesStatefulMixed2.

public void testFetchIterLotsOfEntitiesStatefulMixed2() {
    Discovery[] discs = new Discovery[200];
    for (int i = 0; i < 200; 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.fetch(50);
    List<Discovery> res = future.get();
    assertEquals(50, res.size());
    for (int i = 0; i < 50; i++) {
        assertEquals(discs[i], res.get(i));
    }
    SienaFuture<Iterable<Discovery>> future2 = query.iter(50);
    Iterator<Discovery> it = future2.get().iterator();
    int i = 50;
    while (it.hasNext()) {
        Discovery disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(100, i);
    future = query.fetch(50);
    res = future.get();
    assertEquals(50, res.size());
    for (i = 0; i < 50; i++) {
        assertEquals(discs[i + 100], res.get(i));
    }
    future2 = query.iter(50);
    it = future2.get().iterator();
    i = 150;
    while (it.hasNext()) {
        Discovery disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(200, i);
}
Also used : Discovery(siena.base.test.model.Discovery) ArrayList(java.util.ArrayList) List(java.util.List)

Example 4 with Discovery

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

the class BaseAsyncTest method testIterPerPageStateless.

public void testIterPerPageStateless() {
    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).order("id");
    SienaFuture<Iterable<Discovery>> iter = query.iterPerPage(50);
    int i = 0;
    for (Discovery disc : iter.get()) {
        assertEquals(discs[i++], disc);
    }
    assertEquals(500, i);
}
Also used : Discovery(siena.base.test.model.Discovery)

Example 5 with Discovery

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

the class BaseAsyncTest method testFetchLotsOfEntitiesStatefulMixed2.

public void testFetchLotsOfEntitiesStatefulMixed2() {
    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.fetch(50);
    List<Discovery> res = future.get();
    assertEquals(50, res.size());
    for (int i = 0; i < 50; i++) {
        assertEquals(discs[i], res.get(i));
    }
    future = query.paginate(50).fetch(50);
    res = future.get();
    assertEquals(50, res.size());
    for (int i = 0; i < 50; i++) {
        assertEquals(discs[i + 50], res.get(i));
    }
    future = query.nextPage().fetch();
    res = future.get();
    assertEquals(50, res.size());
    for (int i = 0; i < 50; i++) {
        assertEquals(discs[i + 100], res.get(i));
    }
    future = query.fetch(50);
    res = future.get();
    assertEquals(50, res.size());
    for (int i = 0; i < 50; i++) {
        assertEquals(discs[i + 100], 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