/**
  * todo: Move the GenericClass creation into a utility/factory class.
  *
  * @return
  */
 public GenericClass initGenericClass() {
   GenericReflector reflector =
       new GenericReflector(null, Platform4.reflectorForType(GenericObjectsTest.class));
   GenericClass _objectIClass = (GenericClass) reflector.forClass(Object.class);
   GenericClass result = new GenericClass(reflector, null, PERSON_CLASSNAME, _objectIClass);
   result.initFields(fields(result, reflector));
   return result;
 }
 private Configuration baseConfig(boolean useLogFile) {
   Config4Impl config = (Config4Impl) Db4o.newConfiguration();
   config.objectClass(CrashData.class).objectField("_name").indexed(true);
   config.reflectWith(Platform4.reflectorForType(CrashSimulatingTestCase.class));
   config.bTreeNodeSize(4);
   config.lockDatabaseFile(false);
   config.fileBasedTransactionLog(useLogFile);
   ID_SYSTEM.value().configure(config);
   FREESPACE_MANAGER.value().configure(config);
   return config;
 }
 private byte[] readName(LatinStringIO sio, ByteArrayBuffer reader) {
   if (Deploy.debug) {
     reader.readBegin(Const4.YAPCLASS);
   }
   int len = reader.readInt();
   len = len * sio.bytesPerChar();
   byte[] nameBytes = new byte[len];
   System.arraycopy(reader._buffer, reader._offset, nameBytes, 0, len);
   nameBytes = Platform4.updateClassName(nameBytes);
   reader.incrementOffset(len);
   return nameBytes;
 }
示例#4
0
 protected void setSodaTestOn(STClass[] classes) {
   for (int i = 0; i < classes.length; i++) {
     try {
       Field field = classes[i].getClass().getDeclaredField("st");
       try {
         Platform4.setAccessible(field);
       } catch (Throwable t) {
         // JDK 1.x has no setAccessible
       }
       field.set(classes[i], this);
     } catch (Exception e) {
       System.err.println("Add the following line to Class " + classes[i].getClass().getName());
       System.err.println("public static transient SodaTest st;");
     }
   }
 }
示例#5
0
  /**
   * Search for slot that corresponds to class. <br>
   * If not found add it. <br>
   * Constrain it. <br>
   */
  public Constraint constrain(Object example) {
    synchronized (streamLock()) {
      ReflectClass claxx = reflectClassForClass(example);
      if (claxx != null) {
        return addClassConstraint(claxx);
      }

      QConEvaluation eval = Platform4.evaluationCreate(_trans, example);
      if (eval != null) {
        return addEvaluationToAllConstraints(eval);
      }

      Collection4 constraints = new Collection4();
      addConstraint(constraints, example);
      return toConstraint(constraints);
    }
  }
  public static ReflectConstructorSpec createConstructor(
      final ConstructorAwareReflectClass claxx,
      Class clazz,
      ReflectorConfiguration config,
      ReflectConstructor[] constructors) {

    if (claxx == null) {
      return ReflectConstructorSpec.INVALID_CONSTRUCTOR;
    }

    if (claxx.isAbstract() || claxx.isInterface()) {
      return ReflectConstructorSpec.INVALID_CONSTRUCTOR;
    }

    if (!Platform4.callConstructor()) {
      boolean skipConstructor = !config.callConstructor(claxx);
      if (!claxx.isCollection()) {
        ReflectConstructor serializableConstructor =
            skipConstructor(claxx, skipConstructor, config.testConstructors());
        if (serializableConstructor != null) {
          return new ReflectConstructorSpec(serializableConstructor, null);
        }
      }
    }

    if (!config.testConstructors()) {
      return new ReflectConstructorSpec(new PlatformReflectConstructor(clazz), null);
    }

    if (ReflectPlatform.createInstance(clazz) != null) {
      return new ReflectConstructorSpec(new PlatformReflectConstructor(clazz), null);
    }

    Tree sortedConstructors = sortConstructorsByParamsCount(constructors);
    return findConstructor(claxx, sortedConstructors);
  }
 public boolean isConnected() {
   return Platform4.isConnected(_socket);
 }
示例#8
0
  public boolean isEqual(Object a_compare, Object a_with, String a_path, Stack a_stack) {
    if (a_path == null || a_path.length() < 1) {
      if (a_compare != null) {
        a_path = a_compare.getClass().getName() + ":";
      } else {
        if (a_with != null) {
          a_path = a_with.getClass().getName() + ":";
        }
      }
    }

    String path = a_path;

    if (a_compare == null) {
      return a_with == null;
    }
    if (a_with == null) {
      return false;
    }
    Class clazz = a_compare.getClass();
    if (clazz != a_with.getClass()) {
      return false;
    }

    if (isSimple(clazz)) {
      return a_compare.equals(a_with);
    }

    if (a_stack == null) {
      a_stack = new Stack();
    }

    // takes care of repeating calls to the same object
    if (a_stack.contains(a_compare)) {
      return true;
    }
    a_stack.push(a_compare);

    Field fields[] = clazz.getDeclaredFields();
    for (int i = 0; i < fields.length; i++) {
      if (storeableField(clazz, fields[i])) {
        Platform4.setAccessible(fields[i]);
        try {
          path = a_path + fields[i].getName() + ":";
          Object compare = fields[i].get(a_compare);
          Object with = fields[i].get(a_with);
          if (compare == null) {
            if (with != null) {
              return false;
            }
          } else if (with == null) {
            return false;
          } else {
            if (compare.getClass().isArray()) {
              if (!with.getClass().isArray()) {
                return false;
              } else {
                compare = normalizeNArray(compare);
                with = normalizeNArray(with);
                int len = Array.getLength(compare);
                if (len != Array.getLength(with)) {
                  return false;
                } else {
                  for (int j = 0; j < len; j++) {
                    Object elementCompare = Array.get(compare, j);
                    Object elementWith = Array.get(with, j);
                    //										if (l_persistentArray)
                    if (!isEqual(elementCompare, elementWith, path, a_stack)) {
                      return false;
                    } else if (elementCompare == null) {
                      if (elementWith != null) {
                        return false;
                      }
                    } else if (elementWith == null) {
                      return false;
                    } else {
                      Class elementCompareClass = elementCompare.getClass();
                      if (elementCompareClass != elementWith.getClass()) {
                        return false;
                      }
                      if (hasPublicConstructor(elementCompareClass)) {
                        if (!isEqual(elementCompare, elementWith, path, a_stack)) {
                          return false;
                        }
                      } else if (!elementCompare.equals(elementWith)) {
                        return false;
                      }
                    }
                  }
                }
              }
            } else if (hasPublicConstructor(fields[i].getType())) {
              if (!isEqual(compare, with, path, a_stack)) {
                return false;
              }
            } else {
              if (!compare.equals(with)) {
                return false;
              }
            }
          }
        } catch (IllegalAccessException ex) {
          // probably JDK 1
          // never mind this field
          return true;
        } catch (Exception e) {
          System.err.println("STCompare failure executing path:" + path);
          e.printStackTrace();
          return false;
        }
      }
    }
    return true;
  }
示例#9
0
 protected static boolean jdkOK(Object obj) {
   return Platform4.jdk().ver() >= 2 || STClass1.class.isAssignableFrom(obj.getClass());
 }
    /** @sharpen.remove */
    public void test() throws IOException {

      boolean cached = USE_CACHE.value().booleanValue();
      boolean useLogFile = USE_LOGFILE.value().booleanValue();
      boolean writeTrash = WRITE_TRASH.value().booleanValue();

      if (cached && writeTrash) {
        System.err.println(
            "DISABLED CrashSimulatingTestCase: combination of write trash and cache");
        // The cache may touch more bytes than the ones we modified.
        // We should be safe even if we don't get this test to pass.
        return;
      }

      if (useLogFile && writeTrash) {
        System.err.println(
            "DISABLED CrashSimulatingTestCase: combination of write trash and use log file");

        // The log file is not a public API yet anyway.
        // It's only needed for the PointerBasedIdSystem
        // With the new BTreeIdSystem it's not likely to become important
        // so we can safely ignore the failing write trash case.
        return;
      }

      if (Platform4.needsLockFileThread()) {
        System.out.println(
            "CrashSimulatingTestCase is ignored on platforms with lock file thread.");
        return;
      }

      String path = Path4.combine(Path4.getTempPath(), "crashSimulate");
      String fileName = Path4.combine(path, "cs");

      File4.delete(fileName);
      File4.mkdirs(path);

      createFile(baseConfig(useLogFile), fileName);

      CrashSimulatingStorage crashSimulatingStorage =
          new CrashSimulatingStorage(new FileStorage(), fileName);
      Storage storage =
          cached ? (Storage) new CachingStorage(crashSimulatingStorage) : crashSimulatingStorage;

      Configuration recordConfig = baseConfig(useLogFile);
      recordConfig.storage(storage);

      ObjectContainer oc = Db4o.openFile(recordConfig, fileName);

      ObjectSet objectSet = oc.queryByExample(new CrashData(null, "three"));
      oc.delete(objectSet.next());

      oc.store(new CrashData(null, "four"));
      oc.store(new CrashData(null, "five"));
      oc.store(new CrashData(null, "six"));
      oc.store(new CrashData(null, "seven"));
      oc.store(new CrashData(null, "eight"));
      oc.store(new CrashData(null, "nine"));
      oc.store(new CrashData(null, "10"));
      oc.store(new CrashData(null, "11"));
      oc.store(new CrashData(null, "12"));
      oc.store(new CrashData(null, "13"));
      oc.store(new CrashData(null, "14"));

      oc.commit();

      Query q = oc.query();
      q.constrain(CrashData.class);
      objectSet = q.execute();
      while (objectSet.hasNext()) {
        CrashData cData = (CrashData) objectSet.next();
        if (!(cData._name.equals("10") || cData._name.equals("13"))) {
          oc.delete(cData);
        }
      }

      oc.commit();

      oc.close();

      int count = crashSimulatingStorage._batch.writeVersions(fileName, writeTrash);

      checkFiles(useLogFile, fileName, "R", crashSimulatingStorage._batch.numSyncs());
      checkFiles(useLogFile, fileName, "W", count);
      if (VERBOSE) {
        System.out.println("Total versions: " + count);
      }
    }