use of siena.base.test.model.Discovery in project siena by mandubian.
the class BaseAsyncTest method testOffsetLimitStatefulPaginate.
public void testOffsetLimitStatefulPaginate() {
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").stateful();
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.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.limit(50).fetch();
res = future.get();
assertEquals(50, res.size());
for (int i = 0; i < 50; i++) {
assertEquals(discs[i + 50], res.get(i));
}
future = query.offset(50).fetch();
res = future.get();
assertEquals(50, res.size());
for (int i = 0; i < 50; i++) {
assertEquals(discs[i + 150], res.get(i));
}
future = query.offset(50).limit(25).fetch();
res = future.get();
assertEquals(25, res.size());
for (int i = 0; i < 25; i++) {
assertEquals(discs[i + 250], res.get(i));
}
try {
future = query.previousPage().fetch();
} catch (SienaException ex) {
return;
}
fail();
}
use of siena.base.test.model.Discovery in project siena by mandubian.
the class BaseAsyncTest method testOffsetLimitStatelessPaginateKeys.
public void testOffsetLimitStatelessPaginateKeys() {
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<List<Discovery>> future = query.paginate(50).fetchKeys();
List<Discovery> res = future.get();
assertEquals(50, res.size());
for (int i = 0; i < 50; i++) {
assertEquals(discs[i].id, res.get(i).id);
assertTrue(res.get(i).isOnlyIdFilled());
}
future = query.nextPage().fetchKeys();
res = future.get();
assertEquals(50, res.size());
for (int i = 0; i < 50; i++) {
assertEquals(discs[i + 50].id, res.get(i).id);
assertTrue(res.get(i).isOnlyIdFilled());
}
future = query.limit(50).fetchKeys();
res = future.get();
assertEquals(50, res.size());
for (int i = 0; i < 50; i++) {
assertEquals(discs[i].id, res.get(i).id);
assertTrue(res.get(i).isOnlyIdFilled());
}
future = query.offset(50).fetchKeys();
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());
}
future = query.offset(50).limit(50).fetchKeys();
res = future.get();
assertEquals(50, res.size());
for (int i = 0; i < 50; i++) {
assertEquals(discs[i + 50].id, res.get(i).id);
assertTrue(res.get(i).isOnlyIdFilled());
}
}
use of siena.base.test.model.Discovery in project siena by mandubian.
the class BaseAsyncTest method testFetchPaginateStatefulNextPageRealAsync.
public void testFetchPaginateStatefulNextPageRealAsync() {
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>> future1 = query.fetch();
SienaFuture<List<Discovery>> future2 = query.nextPage().fetch();
List<Discovery> res = future1.get();
assertEquals(5, res.size());
for (int i = 0; i < 5; i++) {
assertEquals(discs[i], res.get(i));
}
res = future2.get();
assertEquals(5, res.size());
for (int i = 0; i < 5; i++) {
assertEquals(discs[i + 5], res.get(i));
}
}
use of siena.base.test.model.Discovery in project siena by mandubian.
the class BaseAsyncTest method testFetchKeysPaginateStatelessPreviousPage.
public void testFetchKeysPaginateStatelessPreviousPage() {
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.nextPage().fetchKeys();
List<Discovery> 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());
}
}
use of siena.base.test.model.Discovery in project siena by mandubian.
the class BaseAsyncTest method testBatchGet.
public void testBatchGet() {
Discovery[] discs = new Discovery[100];
for (int i = 0; i < 100; i++) {
discs[i] = new Discovery("Disc_" + i, LongAutoID_CURIE);
}
pm.insert((Object[]) discs).get();
Discovery[] discs2Get = new Discovery[100];
for (int i = 0; i < 100; i++) {
discs2Get[i] = new Discovery();
discs2Get[i].id = discs[i].id;
}
SienaFuture<Integer> resf = pm.get((Object[]) discs2Get);
assertEquals(discs.length, (int) resf.get());
assertEquals(discs.length, discs2Get.length);
for (int i = 0; i < discs.length; i++) {
assertEquals(discs[i], discs2Get[i]);
}
}
Aggregations