当前位置: 首页>>代码示例>>Java>>正文


Java KeyRange类代码示例

本文整理汇总了Java中com.google.appengine.api.datastore.KeyRange的典型用法代码示例。如果您正苦于以下问题:Java KeyRange类的具体用法?Java KeyRange怎么用?Java KeyRange使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

KeyRange类属于com.google.appengine.api.datastore包,在下文中一共展示了KeyRange类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: testCheckKeyRange

import com.google.appengine.api.datastore.KeyRange; //导入依赖的package包/类
@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);
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:20,代码来源:AllocateIdsTest.java


示例2: testOutOfRangeEntity

import com.google.appengine.api.datastore.KeyRange; //导入依赖的package包/类
@Test
public void testOutOfRangeEntity() throws Exception {
    final long allocateNum = 5;

    // Range default namespace
    KeyRange range = service.allocateIds(ALLOCATE_IDS_ENTITY, allocateNum);

    Entity noParent = createTestEntity(ALLOCATE_IDS_ENTITY);
    assertEntityNotInRange(noParent, range);

    // Range with specified parent
    Entity parent = new Entity(ALLOCATE_IDS_ENTITY);
    Key parentKey = service.put(parent);
    KeyRange range2 = service.allocateIds(parentKey, ALLOCATE_IDS_ENTITY, allocateNum);

    Entity entity = createTestEntity(ALLOCATE_IDS_ENTITY, parentKey);
    assertEntityNotInRange(entity, range2);

    // In Range entity should have same parent
    Entity child = new Entity(range2.getStart());
    Key childKey = service.put(child);
    // child with allocated key should have correct parent.
    Assert.assertEquals(parentKey, childKey.getParent());
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:25,代码来源:AllocateIdsTest.java


示例3: rangeOverlap

import com.google.appengine.api.datastore.KeyRange; //导入依赖的package包/类
private boolean rangeOverlap(KeyRange kr1, KeyRange kr2) {
    long firstStart = kr1.getStart().getId();
    long firstEnd = kr1.getEnd().getId();
    long secondStart = kr2.getStart().getId();
    long secondEnd = kr2.getStart().getId();

    if ((firstStart == secondStart) || (firstEnd == secondEnd)) {
        return true;
    }
    if ((firstStart == secondEnd) || (firstEnd == secondStart)) {
        return true;
    }
    if ((firstStart < secondStart) && (firstEnd > secondStart)) {
        return true;
    }
    if ((firstStart > secondStart) && (secondEnd > firstStart)) {
        return true;
    }
    return false;
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:21,代码来源:AllocateIdsTest.java


示例4: identifiers_autoId_setsUnallocatedId

import com.google.appengine.api.datastore.KeyRange; //导入依赖的package包/类
@Test
public void identifiers_autoId_setsUnallocatedId() throws Exception {
  KeyRange keys = datastore.allocateIds("Employee", 1);
  long usedId = keys.getStart().getId();

  // [START identifiers_2]
  Entity employee = new Entity("Employee");
  // [END identifiers_2]
  datastore.put(employee);

  assertThat(employee.getKey().getId()).named("key id").isNotEqualTo(usedId);
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:13,代码来源:EntitiesTest.java


示例5: testAllocateId

import com.google.appengine.api.datastore.KeyRange; //导入依赖的package包/类
@Test
public void testAllocateId() throws Exception {
    KeyRange firstBlock = service.allocateIds(ALLOCATE_IDS_ENTITY, 10L);

    Assert.assertNotNull(firstBlock);
    Assert.assertEquals(10, firstBlock.getEnd().getId() - firstBlock.getStart().getId() + 1);
    Assert.assertEquals(10, firstBlock.getSize());

    KeyRange secondBlock = service.allocateIds(ALLOCATE_IDS_ENTITY, 10L);
    Assert.assertNotNull(secondBlock);
    Assert.assertFalse("Allocated key ranges should not overlap.", rangeOverlap(firstBlock, secondBlock));
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:13,代码来源:AllocateIdsTest.java


示例6: testAllocateChild

import com.google.appengine.api.datastore.KeyRange; //导入依赖的package包/类
@Test
public void testAllocateChild() {
    Entity parent = new Entity(ALLOCATE_IDS_ENTITY);
    parent.setProperty("name", "parent-" + System.currentTimeMillis());
    Key parentKey = service.put(parent);

    final int allocateSize = 10;
    KeyRange range = service.allocateIds(parentKey, ALLOCATE_IDS_ENTITY, allocateSize);

    Entity child = new Entity(range.getStart());
    Key key = service.put(child);

    // child with allocated key should have correct parent.
    Assert.assertEquals(parentKey, key.getParent());
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:16,代码来源:AllocateIdsTest.java


示例7: testDataAllocate

import com.google.appengine.api.datastore.KeyRange; //导入依赖的package包/类
@Test
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());
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:31,代码来源:AsyncServiceTest.java


示例8: allocateIds

import com.google.appengine.api.datastore.KeyRange; //导入依赖的package包/类
@Override
public Future<KeyRange> allocateIds(String kind, long num) {
  return delegate.allocateIds(kind, num);
}
 
开发者ID:google,项目名称:nomulus,代码行数:5,代码来源:RequestCapturingAsyncDatastoreService.java


示例9: assertEntityNotInRange

import com.google.appengine.api.datastore.KeyRange; //导入依赖的package包/类
protected void assertEntityNotInRange(Entity entity, KeyRange range) {
    // allocated key should not be re-used.
    Assert.assertTrue(entity.getKey().getId() > range.getEnd().getId() ||
        entity.getKey().getId() < range.getStart().getId());
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:6,代码来源:DatastoreHelperTestBase.java



注:本文中的com.google.appengine.api.datastore.KeyRange类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。