@Override public KeyRangeState allocateIdRange(KeyRange range) { return this.ds.allocateIdRange(range); }
public KeyRangeState allocateIdRange(KeyRange keyRange) { try { return inner.allocateIdRange(keyRange); } catch (IllegalArgumentException e) { throw wrapIllegalArgumentException(e); } catch (DatastoreFailureException e) { throw wrapDatastoreFailureException(e); } }
/** * Allocates a user-specified contiguous range of unique IDs, preventing the allocator from * giving them out to entities (with autogeneration) or other calls to allocate methods. * This lets you specify a specific range to block out (for example, you are bulk-loading a * collection of pre-existing entities). If you don't care about what id is allocated, use * one of the other allocate methods. */ public <T> KeyRangeState allocateIdRange(KeyRange<T> range) { return DatastoreServiceFactory.getDatastoreService().allocateIdRange(range.getRaw()); }
@Test public void testCheckKeyRange() throws Exception { long initialValue = getInitialValue("OtherKind"); KeyRange kr1 = new KeyRange(null, "OtherKind", 1 + initialValue, 5 + initialValue); DatastoreService.KeyRangeState state1 = service.allocateIdRange(kr1); Assert.assertNotNull(state1); // imo, it could be either -- depending on the impl Assert.assertTrue(DatastoreService.KeyRangeState.CONTENTION == state1 || DatastoreService.KeyRangeState.EMPTY == state1); KeyRange kr2 = service.allocateIds("OtherKind", 6); Assert.assertNotNull(kr2); KeyRange kr3 = new KeyRange(null, "OtherKind", 2 + initialValue, 5 + initialValue); DatastoreService.KeyRangeState state2 = service.allocateIdRange(kr3); Assert.assertNotNull(state2); // can it be both, depending on the impl? Assert.assertTrue(DatastoreService.KeyRangeState.COLLISION == state2 || DatastoreService.KeyRangeState.CONTENTION == state2); }