Ejemplo n.º 1
0
 /** @deprecated using deprecated api */
 public void test() throws Exception {
   int originalActivationDepth = ((Config4Impl) Db4o.configure()).activationDepth();
   Db4o.configure().activationDepth(0);
   ObjectServer server = Db4oClientServer.openServer(tempFile(), -1);
   try {
     server.grantAccess("db4o", "db4o");
     ObjectContainer oc =
         Db4oClientServer.openClient("localhost", server.ext().port(), "db4o", "db4o");
     oc.close();
   } finally {
     Db4o.configure().activationDepth(originalActivationDepth);
     server.close();
   }
 }
Ejemplo n.º 2
0
 private void createFile(Configuration config, String fileName) throws IOException {
   ObjectContainer oc = Db4o.openFile(config, fileName);
   try {
     populate(oc);
   } finally {
     oc.close();
   }
   File4.copy(fileName, fileName + "0");
 }
Ejemplo n.º 3
0
 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;
 }
Ejemplo n.º 4
0
 private void checkFiles(boolean useLogFile, String fileName, String infix, int count) {
   for (int i = 1; i <= count; i++) {
     String versionedFileName = fileName + infix + i;
     if (VERBOSE) {
       System.out.println("Checking " + versionedFileName);
     }
     ObjectContainer oc = Db4o.openFile(baseConfig(useLogFile), versionedFileName);
     try {
       if (!stateBeforeCommit(oc)) {
         if (!stateAfterFirstCommit(oc)) {
           Assert.isTrue(stateAfterSecondCommit(oc));
         }
       }
     } finally {
       oc.close();
     }
   }
 }
Ejemplo n.º 5
0
    /** @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);
      }
    }