private void withCache(final Procedure4<ClientSlotCache> procedure) {
   ClientSlotCache clientSlotCache = null;
   try {
     clientSlotCache =
         (ClientSlotCache) Reflection4.getFieldValue(container(), "_clientSlotCache");
   } catch (ReflectException e) {
     Assert.fail("Can't get field _clientSlotCache on  container. " + e.toString());
   }
   procedure.apply(clientSlotCache);
 }
 private void checkListSizeAndContents(int expectedSize) throws Exception {
   ArrayList4<Integer> list = retrieveAndAssertNullArrayList4();
   Assert.areEqual(expectedSize, list.size());
   for (int i = 0; i < expectedSize; ++i) {
     Assert.areEqual(new Integer(i), list.get(i));
   }
 }
 private void checkRemove() throws Exception {
   ArrayList4<Integer> list = retrieveAndAssertNullArrayList4();
   Assert.areEqual(ArrayList4Asserter.CAPACITY - 1, list.size());
   for (int i = 0; i < ArrayList4Asserter.CAPACITY - 1; ++i) {
     Assert.areEqual(new Integer(i + 1), list.get(i));
   }
 }
  public void test() throws Exception {

    store(new Original("original"));

    db().commit();

    Assert.areEqual(1, countOccurences(Original.class));

    // Rename messages are visible at level 1
    // fixture().config().messageLevel(1);

    ObjectClass oc = fixture().config().objectClass(Original.class);

    // allways rename fields first
    oc.objectField("originalName").rename("changedName");
    // we must use ReflectPlatform here as the string must include
    // the assembly name in .net
    oc.rename(CrossPlatformServices.fullyQualifiedName(Changed.class));

    reopen();

    Assert.areEqual(0, countOccurences(Original.class));
    Assert.areEqual(1, countOccurences(Changed.class));

    Changed changed = (Changed) retrieveOnlyInstance(Changed.class);

    Assert.areEqual("original", changed.changedName);
  }
 public void testObjectReferenceCount() {
   int objectCount = 10;
   Item[] items = new Item[objectCount];
   for (int i = 0; i < objectCount; i++) {
     Assert.areEqual(referenceCountForDb4oDatabase() + i, objectReferenceCount());
     items[i] = new Item();
     store(items[i]);
   }
   db().purge(items[0]);
   Assert.areEqual(referenceCountForDb4oDatabase() + objectCount - 1, objectReferenceCount());
 }
 private void checkConsistency() {
   ConsistencyReport report =
       new ConsistencyChecker((LocalObjectContainer) container()).checkSlotConsistency();
   if (!report.consistent()) {
     Assert.fail(report.toString());
   }
 }
 private void assertDescendingRange(int startingValue, TAItem item) {
   TAItem current = item;
   while (current != null) {
     Assert.areEqual(startingValue, current.value());
     current = current.next();
     startingValue--;
   }
 }
  public void testNoItemInIndex() {

    StoredClass storedClass = db().storedClass(Item.class);
    Assert.isFalse(storedClass.hasClassIndex());

    assertNoItemFoundByQuery();

    db().commit();
    assertNoItemFoundByQuery();
  }
 protected void assertNullItem(Object obj) throws Exception {
   ReflectClass claxx = reflector().forObject(obj);
   ReflectField[] fields = claxx.getDeclaredFields();
   for (int i = 0; i < fields.length; ++i) {
     ReflectField field = fields[i];
     if (field.isStatic() || field.isTransient()) {
       continue;
     }
     ReflectClass type = field.getFieldType();
     if (container().classMetadataForReflectClass(type).isValueType()) {
       continue;
     }
     Object value = field.get(obj);
     Assert.isNull(value);
   }
 }
  public void _testKillingClients() throws InterruptedException {

    final int CLIENT_COUNT = 3;

    final StringBuffer results = new StringBuffer();

    ThreadServices.spawnAndJoin(
        "ClientProcessesTestCase.testKillingClients",
        CLIENT_COUNT,
        new CodeBlock() {
          public void run() throws Throwable {
            results.append(
                JavaServices.startAndKillJavaProcess(
                    clientRunnerCommand(), CLIENT_STARTED_OK, 10000));
          }
        });

    Assert.areEqual(1, connectedClients());
    System.out.println(results);
  }
  private void assertFileSizeConstant() throws Exception {

    long beforeUpdate = dbSize();

    for (int j = 0; j < 10; j++) {

      defragment();

      for (int i = 0; i < 15; ++i) {
        updateItem();
      }
      defragment();
      long afterUpdate = dbSize();

      /*
       * FIXME: the database file size is uncertain?
       * We met similar problem before.
       */
      Assert.isSmaller(30, afterUpdate - beforeUpdate);
    }
  }
  public void testRefresh() {
    ExtObjectContainer client1 = openNewSession();
    ExtObjectContainer client2 = openNewSession();
    TAItem item1 = (TAItem) retrieveInstance(client1);
    TAItem item2 = (TAItem) retrieveInstance(client2);

    assertDescendingRange(10, item1);

    assertDescendingRange(10, item2);

    item1.value(100);
    item1.next().value(200);
    client1.store(item1, 2);
    client1.commit();

    Assert.areEqual(100, item1.value());
    Assert.areEqual(200, item1.next().value());

    Assert.areEqual(10, item2.value());
    Assert.areEqual(9, item2.next().value());

    // refresh 0
    client2.refresh(item2, 0);
    Assert.areEqual(10, item2.value());
    Assert.areEqual(9, item2.next().value());

    // refresh 1
    client2.refresh(item2, 1);
    Assert.areEqual(100, item2.value());
    Assert.areEqual(9, item2.next().value());

    // refresh 2
    client2.refresh(item2, 2);
    Assert.areEqual(100, item2.value());
    Assert.areEqual(200, item2.next().value());

    updateAscendingWithRange(item1, 1000);
    client1.store(item1, 5);
    client1.commit();

    client2.refresh(item2, 5);
    TAItem next2 = item2;
    for (int i = 1000; i < 1005; i++) {
      Assert.areEqual(i, next2.value());
      next2 = next2.next();
    }
    client1.close();
    client2.close();
  }
 private void assertData() {
   Holder holder = (Holder) retrieveOnlyInstance(Holder.class);
   Assert.isNotNull(holder._item);
   Assert.areEqual(NAME, holder._item._name);
 }
 private void checkAddAll() throws Exception {
   ArrayList4<Integer> list = retrieveAndAssertNullArrayList4();
   for (int i = 0; i < ArrayList4Asserter.CAPACITY * 2; ++i) {
     Assert.areEqual(new Integer(i), list.get(i));
   }
 }
 private void checkClear() throws Exception {
   ArrayList4<Integer> list = retrieveAndAssertNullArrayList4();
   Assert.areEqual(0, list.size());
 }
 private void assertNoItemFoundByQuery() {
   Query q = db().query();
   q.constrain(Item.class);
   Assert.areEqual(0, q.execute().size());
 }
 public void test() {
   Assert.isNotNull(db());
   Assert.isNotNull(values);
 }
 public void operate(ArrayList4<Integer> list) {
   Assert.isFalse(list.contains(new Integer(ArrayList4Asserter.CAPACITY)));
 }
 public void testDoesNotAcceptOptOutAllButNetworkingCS() {
   Assert.isFalse(subject.accept(OptOutAllButNetworkingCSTest.class));
 }
 public void testAcceptsOptOutNetworking() {
   Assert.isTrue(subject.accept(OptOutNetworkingTest.class));
 }
 public void testAcceptsDb4oTest() {
   Assert.isTrue(subject.accept(Db4oTest.class));
 }
 public void testDoesNotAcceptOptOutCS() {
   Assert.isFalse(subject.accept(OptOutTest.class));
 }
 public void testDoesNotAcceptRegularTest() {
   Assert.isFalse(subject.accept(RegularTest.class));
 }
 private void assertInstanceOK(ABar bar) {
   Assert.areEqual("foo", bar.foo);
   Assert.areEqual("bar", bar.bar);
 }
  private void assertHandlerComparison(Comparable4 handler, Object smaller, Object greater) {
    PreparedComparison comparable = handler.prepareComparison(context(), smaller);
    Assert.isNotNull(comparable);
    Assert.areEqual(0, comparable.compareTo(smaller));
    Assert.isSmaller(0, comparable.compareTo(greater));
    Assert.isGreater(0, comparable.compareTo(null));

    comparable = handler.prepareComparison(context(), greater);
    Assert.isNotNull(comparable);
    Assert.areEqual(0, comparable.compareTo(greater));
    Assert.isGreater(0, comparable.compareTo(smaller));
    Assert.isGreater(0, comparable.compareTo(null));

    comparable = handler.prepareComparison(context(), null);
    Assert.isNotNull(comparable);
    Assert.areEqual(0, comparable.compareTo(null));
    Assert.isSmaller(0, comparable.compareTo(smaller));
  }
  public void testRefresh() {
    ExtObjectContainer client1 = openNewSession();
    ExtObjectContainer client2 = openNewSession();
    Item item1 = retrieveInstance(client1);
    Item item2 = retrieveInstance(client2);

    Item next1 = item1;
    int value = 10;
    while (next1 != null) {
      Assert.areEqual(value, next1.getValue());
      next1 = next1.next();
      value--;
    }

    Item next2 = item2;
    value = 10;
    while (next2 != null) {
      Assert.areEqual(value, next2.getValue());
      next2 = next2.next();
      value--;
    }

    item1.setValue(100);
    item1.next().setValue(200);
    client1.store(item1, 2);
    client1.commit();

    Assert.areEqual(100, item1.getValue());
    Assert.areEqual(200, item1.next().getValue());

    Assert.areEqual(10, item2.getValue());
    Assert.areEqual(9, item2.next().getValue());

    // refresh 0
    client2.refresh(item2, 0);
    Assert.areEqual(10, item2.getValue());
    Assert.areEqual(9, item2.next().getValue());

    // refresh 1
    client2.refresh(item2, 1);
    Assert.areEqual(100, item2.getValue());
    Assert.areEqual(9, item2.next().getValue());

    // refresh 2
    client2.refresh(item2, 2);
    Assert.areEqual(100, item2.getValue());
    // FIXME: maybe a bug
    // Assert.areEqual(200, item2.next().getValue());

    next1 = item1;
    value = 1000;
    while (next1 != null) {
      next1.setValue(value);
      next1 = next1.next();
      value++;
    }
    client1.store(item1, 5);
    client1.commit();

    client2.refresh(item2, 5);
    next2 = item2;
    for (int i = 1000; i < 1005; i++) {
      Assert.areEqual(i, next2.getValue());
      next2 = next2.next();
    }

    client1.close();
    client2.close();
  }
 private void asserItemCount(final int expectedCount) {
   Query query = db().query();
   query.constrain(Item.class);
   int itemCount = query.execute().size();
   Assert.areEqual(expectedCount, itemCount);
 }