Search in sources :

Example 16 with Discovery

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

the class BaseAsyncTest method testOffsetLimitStatelessIter.

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

Example 17 with Discovery

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

the class BaseAsyncTest method testIterPaginateStatefulPreviouPageSeveralTimes.

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

Example 18 with Discovery

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

the class BaseAsyncTest method testBatchInsertList.

public void testBatchInsertList() {
    List<Discovery> discs = new ArrayList<Discovery>();
    for (int i = 0; i < 100; i++) {
        discs.add(new Discovery("Disc_" + i, LongAutoID_CURIE));
    }
    SienaFuture<Integer> resf = pm.insert(discs);
    assertEquals(discs.size(), (int) resf.get());
    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);
    }
}
Also used : Discovery(siena.base.test.model.Discovery) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 19 with Discovery

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

the class BaseAsyncTest method testBatchUpdateList.

public void testBatchUpdateList() {
    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);
    List<Discovery> res = pm.createQuery(Discovery.class).fetch().get();
    assertEquals(discs.size(), res.size());
    for (Discovery d : discs) {
        d.discoverer = LongAutoID_EINSTEIN;
    }
    nb = pm.update(discs).get();
    assertEquals(discs.size(), nb);
    res = pm.createQuery(Discovery.class).fetch().get();
    int i = 0;
    for (Discovery disc : res) {
        assertEquals(discs.get(i++), disc);
    }
}
Also used : Discovery(siena.base.test.model.Discovery) ArrayList(java.util.ArrayList)

Example 20 with Discovery

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

the class BaseAsyncTest method testFetchKeysPaginateStatefulPreviouPageSeveralTimes.

public void testFetchKeysPaginateStatefulPreviouPageSeveralTimes() {
    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.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);
    }
    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);
    }
    future = query.nextPage().fetchKeys();
    res = future.get();
    assertEquals(5, res.size());
    for (int i = 0; i < 5; i++) {
        assertEquals(discs[i + 10].id, res.get(i).id);
    }
    future = query.previousPage().fetchKeys();
    res = future.get();
    assertEquals(5, res.size());
    for (int i = 0; i < 5; i++) {
        assertEquals(discs[i + 5].id, res.get(i).id);
    }
    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);
    }
}
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