Beispiel #1
0
  @Test
  public void testBasicAllocation() throws Exception {
    KeyRange<Trivial> range = this.fact.allocateIds(Trivial.class, 5);

    Iterator<Key<Trivial>> it = range.iterator();

    long previousId = 0;
    for (int i = 0; i < 5; i++) {
      Key<Trivial> next = it.next();
      assert next.getId() > previousId;
      previousId = next.getId();
    }

    // Create an id with a put and verify it is > than the last
    Trivial triv = new Trivial("foo", 3);
    this.fact.begin().put(triv);

    assert triv.getId() > previousId;
  }
Beispiel #2
0
  @Test
  public void testParentAllocation() throws Exception {
    Key<Trivial> parentKey = new Key<Trivial>(Trivial.class, 123);
    KeyRange<Child> range = this.fact.allocateIds(parentKey, Child.class, 5);

    Iterator<Key<Child>> it = range.iterator();

    long previousId = 0;
    for (int i = 0; i < 5; i++) {
      Key<Child> next = it.next();
      assert next.getId() > previousId;
      previousId = next.getId();
    }

    // Create an id with a put and verify it is > than the last
    Child ch = new Child(parentKey, "foo");
    this.fact.begin().put(ch);

    assert ch.getId() > previousId;
  }