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);
 }
예제 #2
0
 public void run() {
   Assert.areEqual(_idx, _counter.value);
   _counter.value++;
   if (_fail) {
     Assert.fail();
   }
 }
예제 #3
0
 public void testAllThere() throws Exception {
   for (int i = 0; i < FOOS.length; i++) {
     Query q = createQuery(FOOS[i]);
     ObjectSet objectSet = q.execute();
     Assert.areEqual(1, objectSet.size());
     FieldIndexItem fii = (FieldIndexItem) objectSet.next();
     Assert.areEqual(FOOS[i], fii.foo);
   }
 }
예제 #4
0
 public static void areEqual(Iterator expected, Iterator actual) {
   if (null == expected) {
     Assert.isNull(actual);
     return;
   }
   Assert.isNotNull(actual);
   while (expected.hasNext()) {
     Assert.isTrue(actual.hasNext());
     Assert.areEqual(expected.next(), actual.next());
   }
   Assert.isFalse(actual.hasNext());
 }
예제 #5
0
  public void testGetStoredFields() {
    assertStoredField(Item.class, FIELD_NAME, ITEM_NAME, String.class, true, false);
    assertStoredField(ItemParent.class, "_array", null, String.class, false, true);

    StoredClass itemStoredClass = itemStoredClass();
    StoredField storedField = itemStoredClass.storedField(FIELD_NAME, null);
    StoredField sameStoredField = itemStoredClass.getStoredFields()[0];
    StoredField otherStoredField = storedClass(ItemParent.class).getStoredFields()[0];
    Assert.equalsAndHashcode(storedField, sameStoredField, otherStoredField);

    Assert.isNull(itemStoredClass.storedField("", null));
  }
예제 #6
0
 public static void runTestAndExpect(
     final Iterable4 tests, int expFailures, boolean checkException) {
   final TestResult result = new TestResult();
   new TestRunner(tests).run(result);
   if (expFailures != result.failures().size()) {
     Assert.fail(result.failures().toString());
   }
   if (checkException) {
     for (Iterator4 iter = result.failures().iterator(); iter.moveNext(); ) {
       TestFailure failure = (TestFailure) iter.current();
       Assert.areEqual(EXCEPTION, failure.reason());
     }
   }
 }
예제 #7
0
 private void assertTestRuns(int... failingIndices) {
   IntByRef counter = new IntByRef();
   TestResult result =
       new TestResult() {
         @Override
         public void testStarted(Test test) {
           super.testStarted(test);
           Assert.isInstanceOf(CountingTest.class, test);
         }
       };
   new TestRunner(Iterators.iterable(new SimpleTestSuite(counter, NUM_TESTS, failingIndices)))
       .run(result);
   Assert.areEqual(NUM_TESTS, result.testCount());
   Assert.areEqual(failingIndices.length, result.failures().size());
   Assert.areEqual(NUM_TESTS + 2, counter.value);
 }
 private void checkConsistency() {
   ConsistencyReport report =
       new ConsistencyChecker((LocalObjectContainer) container()).checkSlotConsistency();
   if (!report.consistent()) {
     Assert.fail(report.toString());
   }
 }
예제 #9
0
  private void assertStoredField(
      Class objectClass,
      String fieldName,
      final Object expectedFieldValue,
      Class expectedFieldType,
      boolean hasIndex,
      boolean isArray) {
    StoredClass storedClass = storedClass(objectClass);
    StoredField[] storedFields = storedClass.getStoredFields();
    Assert.areEqual(1, storedFields.length);
    final StoredField storedField = storedFields[0];
    Assert.areEqual(fieldName, storedField.getName());
    StoredField storedFieldByName = storedClass.storedField(fieldName, expectedFieldType);
    Assert.areEqual(storedField, storedFieldByName);

    Object item = retrieveOnlyInstance(objectClass);
    Assert.areEqual(expectedFieldValue, storedField.get(item));
    ReflectClass fieldType = storedField.getStoredType();
    Assert.areEqual(reflector().forClass(expectedFieldType), fieldType);
    Assert.areEqual(isArray, storedField.isArray());

    if (isMultiSession()) {
      return;
    }

    Assert.areEqual(hasIndex, storedField.hasIndex());

    // FIXME: test rename

    if (!hasIndex) {
      Assert.expect(
          RuntimeException.class,
          new CodeBlock() {
            public void run() throws Throwable {
              storedField.traverseValues(
                  new Visitor4() {
                    public void visit(Object obj) {}
                  });
            }
          });
    } else {
      final IntByRef count = new IntByRef();
      storedField.traverseValues(
          new Visitor4() {
            public void visit(Object obj) {
              count.value++;
              Assert.areEqual(expectedFieldValue, obj);
            }
          });
      Assert.areEqual(1, count.value);
    }
  }
예제 #10
0
 public static void sameContent(Iterator expected, Iterator actual) {
   final Collection4 allExpected = new Collection4();
   while (expected.hasNext()) {
     allExpected.add(expected.next());
   }
   while (actual.hasNext()) {
     final Object current = actual.next();
     final boolean removed = allExpected.remove(current);
     if (!removed) {
       unexpected(current);
     }
   }
   Assert.isTrue(allExpected.isEmpty(), allExpected.toString());
 }
  public void test() {

    final Collection4 expected =
        new Collection4(new Object[] {"PING", Boolean.TRUE, new Integer(42)});
    final MessageCollector recipient = new MessageCollector();
    final ObjectServer server = openServerWith(recipient);
    try {
      final ObjectContainer client = openClient("client", server);
      try {
        final MessageSender sender = messageSender(client);
        sendAll(expected, sender);
      } finally {
        client.close();
      }
    } finally {
      server.close();
    }

    Assert.areEqual(expected.toString(), recipient.messages.toString());
  }
예제 #12
0
 public void testRunsRed() {
   TestResult result = new TestResult();
   new TestRunner(Iterators.singletonIterable(new RunsRed(EXCEPTION))).run(result);
   Assert.isTrue(result.failures().size() == 1, "not red");
 }
예제 #13
0
 public void testRunsGreen() {
   TestResult result = new TestResult();
   new TestRunner(Iterators.singletonIterable(new RunsGreen())).run(result);
   Assert.isTrue(result.failures().size() == 0, "not green");
 }
 public void test() {
   Assert.isNotNull(db());
   Assert.isNotNull(values);
 }
예제 #15
0
 private static void unexpected(Object element) {
   Assert.fail("Unexpected element: " + element);
 }
예제 #16
0
 public void testUnknownStoredClass() {
   Assert.isNull(storedClass(this.getClass()));
 }
예제 #17
0
 @Override
 protected void suiteTearDown() throws Exception {
   Assert.areEqual(_numTests + 1, _counter.value);
   _counter.value++;
 }
예제 #18
0
 @Override
 protected void suiteSetUp() throws Exception {
   Assert.areEqual(0, _counter.value);
   _counter.value++;
 }
예제 #19
0
 public void testEqualsAndHashCode() {
   StoredClass clazz = itemStoredClass();
   StoredClass same = itemStoredClass();
   StoredClass other = db().storedClass(ItemParent.class);
   Assert.equalsAndHashcode(clazz, same, other);
 }
예제 #20
0
 public void testStoredClassImpl() {
   Assert.isInstanceOf(StoredClassImpl.class, itemStoredClass());
 }
예제 #21
0
 public void testGetIds() {
   StoredClass itemClass = itemStoredClass();
   long[] ids = itemClass.getIDs();
   Assert.areEqual(1, ids.length);
   Assert.areEqual(_id, ids[0]);
 }
예제 #22
0
 public void testGetParentStoredClass() {
   StoredClass itemClass = itemStoredClass();
   StoredClass parentStoredClass = itemClass.getParentStoredClass();
   Assert.areEqual(reflector().forClass(ItemParent.class).getName(), parentStoredClass.getName());
   Assert.areEqual(parentStoredClass, db().storedClass(ItemParent.class));
 }
예제 #23
0
 public void testGetName() {
   StoredClass itemClass = itemStoredClass();
   Assert.areEqual(reflector().forClass(Item.class).getName(), itemClass.getName());
 }
예제 #24
0
  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));
  }
예제 #25
0
 public void testAccessingBTree() throws Exception {
   BTree bTree = storedField().getIndex(trans());
   Assert.isNotNull(bTree);
   expectKeysSearch(bTree, FOOS);
 }