Search in sources :

Example 11 with Discovery

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

the class BaseAsyncTest method testIterPerPageStateless2.

public void testIterPerPageStateless2() {
    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);
    Iterator<Discovery> it = iter.get().iterator();
    int i = 0;
    while (it.hasNext()) {
        assertEquals(discs[i++], it.next());
    }
    assertEquals(500, i);
}
Also used : Discovery(siena.base.test.model.Discovery)

Example 12 with Discovery

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

the class BaseAsyncTest method testFetchKeysPaginateStatelessNextPage.

public void testFetchKeysPaginateStatelessNextPage() {
    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>> 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());
    }
}
Also used : Discovery(siena.base.test.model.Discovery) ArrayList(java.util.ArrayList) List(java.util.List)

Example 13 with Discovery

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

the class BaseAsyncTest method testFetchIterLotsOfEntitiesStatefulMixed.

public void testFetchIterLotsOfEntitiesStatefulMixed() {
    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));
    }
    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.paginate(25).fetch();
    res = future.get();
    assertEquals(25, res.size());
    for (i = 0; i < 25; i++) {
        assertEquals(discs[i + 100], res.get(i));
    }
    future2 = query.nextPage().iter();
    it = future2.get().iterator();
    i = 125;
    while (it.hasNext()) {
        Discovery disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(150, i);
    future = query.previousPage().fetch();
    res = future.get();
    assertEquals(25, res.size());
    for (i = 0; i < 25; i++) {
        assertEquals(discs[i + 100], res.get(i));
    }
    future = query.previousPage().fetch();
    res = future.get();
    assertEquals(25, res.size());
    for (i = 0; i < 25; i++) {
        assertEquals(discs[i + 75], res.get(i));
    }
    future = query.previousPage().fetch();
    res = future.get();
    assertEquals(25, res.size());
    for (i = 0; i < 25; i++) {
        assertEquals(discs[i + 50], res.get(i));
    }
    future = query.nextPage().fetch();
    res = future.get();
    assertEquals(25, res.size());
    for (i = 0; i < 25; i++) {
        assertEquals(discs[i + 75], res.get(i));
    }
    future = query.nextPage().fetch();
    res = future.get();
    assertEquals(25, res.size());
    for (i = 0; i < 25; i++) {
        assertEquals(discs[i + 100], res.get(i));
    }
    future = query.nextPage().fetch();
    res = future.get();
    assertEquals(25, res.size());
    for (i = 0; i < 25; i++) {
        assertEquals(discs[i + 125], res.get(i));
    }
    future = query.nextPage().fetch();
    res = future.get();
    assertEquals(0, res.size());
    future = query.previousPage().fetch();
    res = future.get();
    assertEquals(25, res.size());
    for (i = 0; i < 25; i++) {
        assertEquals(discs[i + 125], res.get(i));
    }
    future = query.previousPage().fetch();
    res = future.get();
    assertEquals(25, res.size());
    for (i = 0; i < 25; i++) {
        assertEquals(discs[i + 100], res.get(i));
    }
    future = query.previousPage().fetch();
    res = future.get();
    assertEquals(25, res.size());
    for (i = 0; i < 25; i++) {
        assertEquals(discs[i + 75], res.get(i));
    }
    future = query.previousPage().fetch();
    res = future.get();
    assertEquals(25, res.size());
    for (i = 0; i < 25; i++) {
        assertEquals(discs[i + 50], res.get(i));
    }
    future = query.previousPage().fetch();
    res = future.get();
    assertEquals(25, res.size());
    for (i = 0; i < 25; i++) {
        assertEquals(discs[i + 25], res.get(i));
    }
    future = query.previousPage().fetch();
    res = future.get();
    assertEquals(25, res.size());
    for (i = 0; i < 25; i++) {
        assertEquals(discs[i], res.get(i));
    }
}
Also used : Discovery(siena.base.test.model.Discovery) ArrayList(java.util.ArrayList) List(java.util.List)

Example 14 with Discovery

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

the class BaseAsyncTest method testFetchLotsOfEntitiesStatefulMixed.

public void testFetchLotsOfEntitiesStatefulMixed() {
    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.paginate(50).fetch();
    List<Discovery> res = future.get();
    assertEquals(50, res.size());
    for (int i = 0; i < 50; i++) {
        assertEquals(discs[i], res.get(i));
    }
    future = query.fetch(50);
    res = future.get();
    assertEquals(50, res.size());
    for (int i = 0; i < 50; i++) {
        assertEquals(discs[i], res.get(i));
    }
    future = query.nextPage().fetch();
    res = future.get();
    assertEquals(50, res.size());
    for (int i = 0; i < 50; i++) {
        assertEquals(discs[i + 50], res.get(i));
    }
    future = query.fetch(50);
    res = future.get();
    assertEquals(50, res.size());
    for (int i = 0; i < 50; i++) {
        assertEquals(discs[i + 50], res.get(i));
    }
}
Also used : Discovery(siena.base.test.model.Discovery) ArrayList(java.util.ArrayList) List(java.util.List)

Example 15 with Discovery

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

the class BaseAsyncTest method testFetchLimitReal.

public void testFetchLimitReal() {
    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();
    SienaFuture<List<Discovery>> future = pm.createQuery(Discovery.class).order("name").fetch(3);
    List<Discovery> res = future.get();
    assertNotNull(res);
    assertEquals(3, res.size());
    assertEquals(discs[0], res.get(0));
    assertEquals(discs[1], res.get(1));
    assertEquals(discs[2], res.get(2));
}
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