Пример #1
0
  private void doDumpLoadTest(boolean printable, int nDumps) throws IOException, DatabaseException {

    Hashtable[] dataMaps = new Hashtable[nDumps];
    for (int i = 0; i < nDumps; i += 1) {
      dataMaps[i] = new Hashtable();
    }
    initDbs(nDumps, dataMaps);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintStream out = new PrintStream(baos);
    for (int i = 0; i < nDumps; i += 1) {
      DbDump dumper = new DbDump(env, dbName + i, out, null, printable);
      dumper.dump();
    }
    byte[] baosba = baos.toByteArray();
    BufferedReader rdr =
        new BufferedReader(new InputStreamReader(new ByteArrayInputStream(baosba)));
    for (int i = 0; i < nDumps; i += 1) {
      DbLoad loader = new DbLoad();
      loader.setEnv(env);
      loader.setInputReader(rdr);
      loader.setNoOverwrite(false);
      loader.setDbName(dbName + i);
      loader.load();
      verifyDb(dataMaps[i], i);
    }

    ByteArrayOutputStream baos2 = new ByteArrayOutputStream();
    PrintStream out2 = new PrintStream(baos2);
    for (int i = 0; i < nDumps; i += 1) {
      DbDump dumper2 = new DbDump(env, dbName + i, out2, null, printable);
      dumper2.dump();
    }
    assertEquals(0, Key.compareKeys(baosba, baos2.toByteArray(), null));

    env.close();
  }
Пример #2
0
  /** A simple test to check if JE's dump format matches Core. */
  public void testMatchCore() throws Throwable {

    try {
      /* Set up a new environment. */
      EnvironmentConfig envConfig = TestUtils.initEnvConfig();
      envConfig.setAllowCreate(true);
      env = new Environment(envHome, envConfig);

      /*
       * Make a stream holding a small dump in a format known to be
       * the same as Core DB.
       */
      ByteArrayOutputStream dumpInfo = new ByteArrayOutputStream();
      PrintStream dumpStream = new PrintStream(dumpInfo);
      dumpStream.println("VERSION=3");
      dumpStream.println("format=print");
      dumpStream.println("type=btree");
      dumpStream.println("dupsort=0");
      dumpStream.println("HEADER=END");
      dumpStream.println(" abc");
      dumpStream.println(" firstLetters");
      dumpStream.println(" xyz");
      dumpStream.println(" lastLetters");
      dumpStream.println("DATA=END");

      /* load it */
      DbLoad loader = new DbLoad();
      loader.setEnv(env);
      loader.setInputReader(
          new BufferedReader(
              new InputStreamReader(new ByteArrayInputStream(dumpInfo.toByteArray()))));
      loader.setNoOverwrite(false);
      loader.setDbName("foobar");
      loader.load();

      /* Make sure we retrieve the expected data. */
      Database checkDb = env.openDatabase(null, "foobar", null);
      Cursor cursor = checkDb.openCursor(null, null);
      DatabaseEntry key = new DatabaseEntry();
      DatabaseEntry data = new DatabaseEntry();
      assertEquals(OperationStatus.SUCCESS, cursor.getNext(key, data, LockMode.DEFAULT));
      assertEquals("abc", new String(key.getData()));
      assertEquals("firstLetters", new String(data.getData()));
      assertEquals(OperationStatus.SUCCESS, cursor.getNext(key, data, LockMode.DEFAULT));
      assertEquals("xyz", new String(key.getData()));
      assertEquals("lastLetters", new String(data.getData()));
      assertEquals(OperationStatus.NOTFOUND, cursor.getNext(key, data, LockMode.DEFAULT));
      cursor.close();
      checkDb.close();

      /* Check that a dump of the database matches the input file. */
      ByteArrayOutputStream dump2 = new ByteArrayOutputStream();
      DbDump dumper2 = new DbDump(env, "foobar", new PrintStream(dump2), null, true);
      dumper2.dump();
      assertEquals(dump2.toString(), dumpInfo.toString());

      env.close();
    } catch (Throwable t) {
      t.printStackTrace();
      throw t;
    }
  }