Search in sources :

Example 21 with Discovery

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

the class BaseAsyncTest method testIterLotsOfEntitiesStatefulMixed2.

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

Example 22 with Discovery

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

the class BaseAsyncTest method testIterLotsOfEntitiesStatefulMixed3.

public void testIterLotsOfEntitiesStatefulMixed3() {
    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<Iterable<Discovery>> future = query.iter(50);
    Iterator<Discovery> it = future.get().iterator();
    int i = 0;
    while (it.hasNext()) {
        Discovery disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(50, i);
    future = query.paginate(50).iter();
    it = future.get().iterator();
    i = 50;
    while (it.hasNext()) {
        Discovery disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(100, i);
    future = query.iter();
    it = future.get().iterator();
    i = 50;
    while (it.hasNext()) {
        Discovery disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(100, i);
    future = query.nextPage().iter();
    it = future.get().iterator();
    while (it.hasNext()) {
        Discovery disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(150, i);
}
Also used : Discovery(siena.base.test.model.Discovery)

Example 23 with Discovery

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

the class BaseAsyncTest method testOffsetLimitStatelessPaginate2Iter.

public void testOffsetLimitStatelessPaginate2Iter() {
    Discovery[] discs = new Discovery[300];
    for (int i = 0; i < 300; 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>> future = query.limit(50).offset(12).iter();
    Iterable<Discovery> iter = future.get();
    Iterator<Discovery> it = iter.iterator();
    int i = 12;
    while (it.hasNext()) {
        Discovery disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(62, i);
    future = query.offset(13).limit(30).iter();
    iter = future.get();
    it = iter.iterator();
    i = 13;
    while (it.hasNext()) {
        Discovery disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(43, i);
    future = query.offset(10).limit(30).iter(15);
    iter = future.get();
    it = iter.iterator();
    i = 10;
    while (it.hasNext()) {
        Discovery disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(25, i);
    future = query.paginate(6).iter();
    iter = future.get();
    it = iter.iterator();
    i = 0;
    while (it.hasNext()) {
        Discovery disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(6, i);
    future = query.nextPage().iter();
    iter = future.get();
    it = iter.iterator();
    i = 6;
    while (it.hasNext()) {
        Discovery disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(12, i);
    future = query.nextPage().iter();
    iter = future.get();
    it = iter.iterator();
    i = 12;
    while (it.hasNext()) {
        Discovery disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(18, i);
    future = query.previousPage().iter();
    iter = future.get();
    it = iter.iterator();
    i = 6;
    while (it.hasNext()) {
        Discovery disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(12, i);
    future = query.offset(10).iter(10);
    iter = future.get();
    it = iter.iterator();
    i = 10;
    while (it.hasNext()) {
        Discovery disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(20, i);
    try {
        future = query.nextPage().iter();
    } catch (SienaException ex) {
        future = query.paginate(8).iter();
        iter = future.get();
        it = iter.iterator();
        i = 0;
        while (it.hasNext()) {
            Discovery disc = it.next();
            assertEquals(discs[i++], disc);
        }
        assertEquals(8, i);
        future = query.nextPage().iter();
        iter = future.get();
        it = iter.iterator();
        i = 8;
        while (it.hasNext()) {
            Discovery disc = it.next();
            assertEquals(discs[i++], disc);
        }
        assertEquals(16, i);
        return;
    }
    fail();
}
Also used : Discovery(siena.base.test.model.Discovery) SienaException(siena.SienaException)

Example 24 with Discovery

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

the class BaseAsyncTest method testFetchPaginateStatelessNextPage.

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

Example 25 with Discovery

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

the class BaseAsyncTest method testBatchSaveList.

public void testBatchSaveList() {
    List<Discovery> discs = new ArrayList<Discovery>();
    for (int i = 0; i < 100; i++) {
        discs.add(new Discovery("Disc_" + i, LongAutoID_CURIE));
    }
    int nb = pm.insert(discs).get();
    assertEquals(discs.size(), nb);
    SienaFuture<List<Discovery>> future = pm.createQuery(Discovery.class).fetch();
    List<Discovery> res = future.get();
    assertEquals(discs.size(), res.size());
    int i = 0;
    for (Discovery disc : res) {
        assertEquals(discs.get(i++), disc);
    }
    for (i = 0; i < 100; i++) {
        ((Discovery) discs.get(i)).name += "UPD";
        ((Discovery) discs.get(i)).discoverer = LongAutoID_EINSTEIN;
    }
    nb = pm.save(discs).get();
    assertEquals(discs.size(), nb);
    future = pm.createQuery(Discovery.class).fetch();
    res = future.get();
    i = 0;
    for (Discovery disc : res) {
        assertEquals(discs.get(i++), disc);
    }
}
Also used : Discovery(siena.base.test.model.Discovery) ArrayList(java.util.ArrayList) 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