Exemplo n.º 1
0
    public static void main(String[] args) throws IOException {
      PersistenceObjectModel.register();

      FileStore store = new FileStore(JdbmTest.FILE);

      @SuppressWarnings("unchecked")
      final TMap<String, TSet<PersistenceClass>> map = (TMap) store.getRoot();
      Transaction.setDefaultTrunk(map.getTrunk());
      Assert.assertEquals(COUNT + 1, map.size());

      Transaction.run(
          new Runnable() {

            public void run() {
              for (int i = 0; i < COUNT + 1; i++) {
                TSet<PersistenceClass> set = map.get("set" + i);
                Assert.assertEquals(1, set.size());

                for (PersistenceClass current : set) Assert.assertTrue(current.getInt() == i);
              }
            }
          });

      if (Stats.ENABLED) {
        // 2 for log file initialization
        Assert.assertEquals(2, Stats.getInstance().FileTotalWritten.get());
      }

      TSet<PersistenceClass> set = new TSet<PersistenceClass>();
      PersistenceClass object = new PersistenceClass();
      object.setInt(COUNT + 1);
      set.add(object);
      map.put("set" + (COUNT + 1), set);

      store.flush();

      Log.write("Inserted 1 more set.");

      if (Stats.ENABLED) {
        Assert.assertTrue(
            Stats.getInstance().FileTotalWritten.get()
                < Stats.getInstance().FileTotalRead.get() / 10);
        Stats.getInstance().writeAndReset();
      }

      store.close();
      PlatformAdapter.shutdown();
    }
Exemplo n.º 2
0
    public static void main(String[] args) throws IOException {
      PersistenceObjectModel.register();

      FileStore store = new FileStore(JdbmTest.FILE);

      @SuppressWarnings("unchecked")
      final TMap<String, TSet<PersistenceClass>> map = (TMap) store.getRoot();
      Transaction.setDefaultTrunk(map.getTrunk());

      Assert.assertEquals(COUNT + 2, map.size());

      for (int i = 0; i < COUNT + 2; i++) {
        final TSet<PersistenceClass> set = map.get("set" + i);
        Assert.assertEquals(1, set.size());
        final int i_ = i;

        Transaction.run(
            new Runnable() {

              public void run() {
                for (PersistenceClass current : set) Assert.assertTrue(current.getInt() == i_);
              }
            });
      }

      Log.write("Reopened and read all.");

      if (Stats.ENABLED) {
        // 2 for log file initialization
        Assert.assertEquals(2, Stats.getInstance().FileTotalWritten.get());
        Stats.getInstance().writeAndReset();
      }

      store.close();
      PlatformAdapter.shutdown();
    }
Exemplo n.º 3
0
  public void run(
      final Load load, final int threadCount, final int txPerThread, final int writeRatio) {
    if (Stats.ENABLED) Log.write("!! STATS ENABLED !!");

    if (Debug.ENABLED) Log.write("!! DEBUG ENABLED !!");

    load.reset();

    ArrayList<Thread> threads = new ArrayList<Thread>();

    // Listen for commits

    Log.write("Starting " + threadCount + " threads, " + txPerThread + " tx per thread");

    _changeCallbackLast.set(0);

    _barrier = new CyclicBarrier(threadCount);

    for (int i = 0; i < threadCount; i++) {
      final int _i = i;

      Thread thread =
          new Thread("Thread " + i) {

            @Override
            public void run() {
              try {
                try {
                  _barrier.await();
                } catch (BrokenBarrierException e) {
                  throw new RuntimeException(e);
                }

                load.run(_i, txPerThread, writeRatio);
              } catch (java.lang.InterruptedException ex) {
                throw new RuntimeException(ex);
              }
            }
          };

      threads.add(thread);
      thread.start();
    }

    long start = System.nanoTime();
    Concurrent.joinThreads(threads);
    long end = System.nanoTime();

    long tx = threadCount * txPerThread;
    long ops = (long) threadCount * txPerThread * load.getOpsPerTx();
    long success = load.getSuccessfulOps() / 1000;
    double txPerSec = tx * 1e9 / (end - start);
    double opsPerSec = ops * 1e9 / (end - start);
    double successPerSec = success * 1e9 / (end - start);
    Log.write(
        (tx / 1000)
            + " K transaction, "
            + (ops / 1000)
            + " K ops, "
            + success
            + " K successful ops");
    Log.write(
        (int) (txPerSec / 1000)
            + " K transaction/s, "
            + (int) (opsPerSec / 1000)
            + " K ops/s, "
            + (int) successPerSec
            + " K successful ops/s");
    Log.write("Time: " + (end - start) / 1e9);

    //

    ThreadCounts.add(threadCount);
    OpsPerTxs.add(load.getOpsPerTx());
    TxPerSec.add((int) txPerSec);
    OpsPerSec.add((int) opsPerSec);
    WriteRatios.add(writeRatio);

    if (Stats.ENABLED) Stats.getInstance().writeAndReset();
  }
Exemplo n.º 4
0
    public static void main(String[] args) throws IOException {
      PersistenceObjectModel.register();

      OF.setConfig(
          new Config() {

            @Override
            public AutoCommitPolicy getAutoCommitPolicy() {
              return AutoCommitPolicy.DELAYED_MANUAL;
            }
          });

      FileStore store = new FileStore(JdbmTest.FILE);
      Transaction trunk = Site.getLocal().createTrunk(store);
      Transaction.setDefaultTrunk(trunk);

      TMap<String, TSet<PersistenceClass>> map = new TMap<String, TSet<PersistenceClass>>();
      ArrayList<TSet<PersistenceClass>> list = new ArrayList<TSet<PersistenceClass>>();

      for (int i = 0; i < COUNT; i++) {
        TSet<PersistenceClass> set = new TSet<PersistenceClass>();
        list.add(set);
        map.put("set" + i, set);
        PersistenceClass object = new PersistenceClass();
        object.setInt(i);
        set.add(object);
      }

      Assert.assertNull(store.getRoot());
      store.setRoot(map);

      OF.update();
      Assert.assertEquals(COUNT, map.size());
      Log.write("Inserted " + COUNT + " sets.");
      long mainWriteLength = 0;

      if (Stats.ENABLED) {
        mainWriteLength = Stats.getInstance().FileTotalWritten.get();
        Stats.getInstance().writeAndReset();
      }

      TSet<PersistenceClass> set = new TSet<PersistenceClass>();
      PersistenceClass object = new PersistenceClass();
      object.setInt(COUNT);
      set.add(object);
      map.put("set" + list.size(), set);

      OF.update();

      Log.write("Inserted 1 more set.");

      if (Stats.ENABLED)
        Assert.assertTrue(Stats.getInstance().FileTotalWritten.get() < mainWriteLength / 10);

      store.close();

      if (Stats.ENABLED) Stats.getInstance().reset();

      // Re open

      FileStore store2 = new FileStore(JdbmTest.FILE);

      @SuppressWarnings("unchecked")
      TMap<String, TSet<PersistenceClass>> map2 = (TMap) store2.getRoot();
      Assert.assertTrue(map2 == map);

      for (int i = 0; i < COUNT; i++) {
        TSet<PersistenceClass> set2 = map.get("set" + i);
        Assert.assertTrue(set2 == list.get(i));
        Assert.assertEquals(1, set2.size());

        for (PersistenceClass current : set2) Assert.assertTrue(current.getInt() == i);
      }

      Log.write("Reopened and read all.");

      store2.close();

      if (Stats.ENABLED) {
        // 4 for 2 log file initializations
        Assert.assertEquals(4, Stats.getInstance().FileTotalWritten.get());
        Stats.getInstance().writeAndReset();
      }

      PlatformAdapter.shutdown();
    }