/**
   * @param concurrency Concurrency.
   * @param isolation Isolation.
   * @throws GridException If test failed.
   */
  private void checkTransactionTimeout(
      GridCacheTxConcurrency concurrency, GridCacheTxIsolation isolation) throws Exception {

    boolean wasEx = false;

    GridCacheTx tx = null;

    try {
      GridCache<Integer, String> cache = grid.cache(null);

      tx = cache.txStart(concurrency, isolation, 50, 0);

      cache.put(1, "1");

      Thread.sleep(100);

      cache.put(1, "2");

      tx.commit();
    } catch (GridCacheTxOptimisticException e) {
      info("Received expected optimistic exception: " + e.getMessage());

      wasEx = true;

      tx.rollback();
    } catch (GridCacheTxTimeoutException e) {
      info("Received expected timeout exception: " + e.getMessage());

      wasEx = true;

      tx.rollback();
    }

    assert wasEx;
  }
  /** {@inheritDoc} */
  @Override
  public void rollback() throws GridException {
    enter();

    try {
      tx.rollback();
    } finally {
      leave();
    }
  }
  /** Roll backs current transaction. */
  private void rollbackCurrentTx() {
    try {
      TxContext ctx = txCtx.get();

      if (ctx != null) {
        txCtx.remove();

        GridCacheTx tx = cache.tx();

        if (tx != null) tx.rollback();
      }
    } catch (GridException e) {
      log.error("Failed to rollback cache transaction.", e);
    }
  }