/** @throws Exception If failed. */
  public void testNodeLeave() throws Exception {
    try {
      cache = true;

      for (int i = 0; i < 2; i++) {
        nearOnly = i == 0;

        startGrid(i);
      }

      for (int i = 0; i < 10; i++) grid(1).cache(null).put(i, i);

      final GridCache<Object, Object> nearOnly = grid(0).cache(null);

      // Populate near cache.
      for (int i = 0; i < 10; i++) {
        assertEquals(i, nearOnly.get(i));
        assertEquals(i, nearOnly.peek(i));
      }

      // Stop the only dht node.
      stopGrid(1);

      for (int i = 0; i < 10; i++) {
        assertNull(nearOnly.peek(i));

        final int key = i;

        GridTestUtils.assertThrows(
            log,
            new Callable<Object>() {
              @Override
              public Object call() throws Exception {
                return nearOnly.get(key);
              }
            },
            GridTopologyException.class,
            null);
      }

      // Test optimistic transaction.
      GridTestUtils.assertThrows(
          log,
          new Callable<Object>() {
            @Override
            public Object call() throws Exception {
              try (GridCacheTx tx = nearOnly.txStart(OPTIMISTIC, REPEATABLE_READ)) {
                nearOnly.putx("key", "val");

                tx.commit();
              }

              return null;
            }
          },
          GridTopologyException.class,
          null);

      // Test pessimistic transaction.
      GridTestUtils.assertThrows(
          log,
          new Callable<Object>() {
            @Override
            public Object call() throws Exception {
              try (GridCacheTx tx = nearOnly.txStart(PESSIMISTIC, REPEATABLE_READ)) {
                nearOnly.put("key", "val");

                tx.commit();
              }

              return null;
            }
          },
          GridTopologyException.class,
          null);

    } finally {
      stopAllGrids();
    }
  }
  /**
   * JUnit.
   *
   * @throws Exception In case of error.
   */
  @SuppressWarnings({"TooBroadScope"})
  public void testH2Text() throws Exception {
    int duration = 60 * 1000;
    final int keyCnt = 5000;
    final int logFreq = 50;
    final String txt = "Value";

    final GridCache<Integer, H2TextValue> c = grid(0).cache(null);

    GridFuture<?> fut1 =
        multithreadedAsync(
            new Callable() {
              @Override
              public Object call() throws Exception {
                for (int i = 0; i < keyCnt; i++) {
                  c.putx(i, new H2TextValue(txt));

                  if (i % logFreq == 0) X.println("Stored values: " + i);
                }

                return null;
              }
            },
            1);

    // Create query.
    final GridCacheQuery<Map.Entry<Integer, H2TextValue>> qry =
        c.queries().createFullTextQuery(H2TextValue.class, txt);

    qry.enableDedup(false);
    qry.includeBackups(false);
    qry.timeout(TEST_TIMEOUT);

    final AtomicBoolean stop = new AtomicBoolean();

    GridFuture<?> fut2 =
        multithreadedAsync(
            new Callable() {
              @Override
              public Object call() throws Exception {
                int cnt = 0;

                while (!stop.get()) {
                  Collection<Map.Entry<Integer, H2TextValue>> res = qry.execute().get();

                  cnt++;

                  if (cnt % logFreq == 0) {
                    X.println("Result set: " + res.size());
                    X.println("Executed queries: " + cnt);
                  }
                }

                return null;
              }
            },
            1);

    Thread.sleep(duration);

    fut1.get();

    stop.set(true);

    fut2.get();
  }