@Test
  public void shouldShutdownCleanly() throws Throwable {
    theDatabase.start();
    theDatabase.stop();

    assertThat(logging.toString(), containsString("Successfully stopped database"));
  }
Example #2
0
  public void runTest() throws SQLException {

    db.start(this, "Transactions");
    db.openConnection();
    processTransactions();
    db.closeConnection();
    db.end();

    db.openConnection();
    processTransactions();
    db.logMemory(this, "Memory Usage");
    db.closeConnection();
  }
  @Override
  public void runTest() throws SQLException {

    database.start(this, "Transactions");
    database.openConnection();
    processTransactions();
    database.closeConnection();
    database.end();

    database.openConnection();
    processTransactions();
    database.logMemory(this, "Memory Usage");
    database.closeConnection();
  }
  @Test
  public void shouldComplainIfDatabaseLocationIsAlreadyInUse() throws Throwable {
    deletionFailureOk = true;
    theDatabase.start();

    LifecycleManagingDatabase db = newDatabase();

    try {
      db.start();
    } catch (RuntimeException e) {
      // Wrapped in a lifecycle exception, needs to be dug out
      assertThat(e.getCause().getCause(), instanceOf(StoreLockException.class));
    }
  }
  @Override
  public void init(Database db, int size) throws SQLException {
    this.database = db;
    transactions = size * 6;

    int scale = 2;
    accounts = size * 30;
    tellers = Math.max(accounts / 10, 1);
    branches = Math.max(tellers / 10, 1);

    db.start(this, "Init");

    db.openConnection();

    db.dropTable("BRANCHES");
    db.dropTable("TELLERS");
    db.dropTable("ACCOUNTS");
    db.dropTable("HISTORY");

    String[] create = {
      "CREATE TABLE BRANCHES(BID INT NOT NULL PRIMARY KEY, "
          + "BBALANCE DECIMAL(15,2), FILLER VARCHAR(88))",
      "CREATE TABLE TELLERS(TID INT NOT NULL PRIMARY KEY, "
          + "BID INT, TBALANCE DECIMAL(15,2), FILLER VARCHAR(84))",
      "CREATE TABLE ACCOUNTS(AID INT NOT NULL PRIMARY KEY, "
          + "BID INT, ABALANCE DECIMAL(15,2), FILLER VARCHAR(84))",
      "CREATE TABLE HISTORY(TID INT, "
          + "BID INT, AID INT, DELTA DECIMAL(15,2), HTIME DATETIME, "
          + "FILLER VARCHAR(40))"
    };

    for (String sql : create) {
      db.update(sql);
    }

    PreparedStatement prep;
    db.setAutoCommit(false);
    int commitEvery = 1000;
    prep =
        db.prepare(
            "INSERT INTO BRANCHES(BID, BBALANCE, FILLER) "
                + "VALUES(?, 10000.00, '"
                + FILLER
                + "')");
    for (int i = 0; i < branches * scale; i++) {
      prep.setInt(1, i);
      db.update(prep, "insertBranches");
      if (i % commitEvery == 0) {
        db.commit();
      }
    }
    db.commit();
    prep =
        db.prepare(
            "INSERT INTO TELLERS(TID, BID, TBALANCE, FILLER) "
                + "VALUES(?, ?, 10000.00, '"
                + FILLER
                + "')");
    for (int i = 0; i < tellers * scale; i++) {
      prep.setInt(1, i);
      prep.setInt(2, i / tellers);
      db.update(prep, "insertTellers");
      if (i % commitEvery == 0) {
        db.commit();
      }
    }
    db.commit();
    int len = accounts * scale;
    prep =
        db.prepare(
            "INSERT INTO ACCOUNTS(AID, BID, ABALANCE, FILLER) "
                + "VALUES(?, ?, 10000.00, '"
                + FILLER
                + "')");
    for (int i = 0; i < len; i++) {
      prep.setInt(1, i);
      prep.setInt(2, i / accounts);
      db.update(prep, "insertAccounts");
      if (i % commitEvery == 0) {
        db.commit();
      }
    }
    db.commit();
    db.closeConnection();
    db.end();

    //        db.start(this, "Open/Close");
    //        db.openConnection();
    //        db.closeConnection();
    //        db.end();
  }
  @Test
  public void shouldLogOnSuccessfulStartup() throws Throwable {
    theDatabase.start();

    assertThat(logging.toString(), containsString("Successfully started database"));
  }
 @Test
 public void shouldBeAbleToGetLocation() throws Throwable {
   theDatabase.start();
   assertThat(theDatabase.getLocation(), is(databaseDirectory.getAbsolutePath()));
 }