public void testDataAllocate() throws Exception {
final long allocateNum = 5;
// Range default namespace
Future<KeyRange> futureRange = asyncService.allocateIds(ASYNC_ENTITY, allocateNum);
KeyRange range = futureRange.get();
assertTaskIsDoneAndNotCancelled(futureRange);
Entity noParent = createTestEntity(ASYNC_ENTITY);
assertEntityNotInRange(noParent, range);
// Range with specified parent
Entity parent = new Entity(ASYNC_ENTITY);
parent.setProperty("name", "parent" + new Date());
Key parentKey = service.put(parent);
Future<KeyRange> futureRange2 = asyncService.allocateIds(parentKey, ASYNC_ENTITY, allocateNum);
KeyRange range2 = futureRange2.get();
assertTaskIsDoneAndNotCancelled(futureRange2);
Entity noParent2 = createTestEntity(ASYNC_ENTITY, parentKey);
assertEntityNotInRange(noParent2, range2);
// In Range entity should have same parent
Entity child = new Entity(range2.getStart());
child.setProperty("name", "second" + new Date());
Key childKey = service.put(child);
// child with allocated key should have correct parent.
assertEquals(parentKey, childKey.getParent());
}