/** @throws Exception If failed. */
  public void testObjectArgument() throws Exception {
    IgniteCache<TestKey, Person> cache = ignite(0).cache(null);

    for (int i = 0; i < 100; i++) cache.put(new TestKey(i), new Person("name-" + i));

    SqlQuery<TestKey, Person> qry = new SqlQuery<>(Person.class, "where _key=?");

    IgniteBinary binary = ignite(0).binary();

    for (int i = 0; i < 100; i++) {
      Object key = new TestKey(i);

      if (i % 2 == 0) key = binary.toBinary(key);

      qry.setArgs(key);

      List<Cache.Entry<TestKey, Person>> res = cache.query(qry).getAll();

      assertEquals(1, res.size());

      Person p = res.get(0).getValue();

      assertEquals("name-" + i, p.name);
    }
  }
  /** @throws Exception If failed. */
  public void testQueryReconnect() throws Exception {
    Ignite cln = grid(serverCount());

    assertTrue(cln.cluster().localNode().isClient());

    final Ignite srv = clientRouter(cln);

    final IgniteCache<Integer, Person> clnCache = cln.getOrCreateCache(QUERY_CACHE);

    final IgniteCache<Integer, Person> srvCache = srv.getOrCreateCache(QUERY_CACHE);

    clnCache.put(1, new Person(1, "name1", "surname1"));
    clnCache.put(2, new Person(2, "name2", "surname2"));
    clnCache.put(3, new Person(3, "name3", "surname3"));

    final SqlQuery<Integer, Person> qry = new SqlQuery<>(Person.class, "_key <> 0");

    qry.setPageSize(1);

    QueryCursor<Cache.Entry<Integer, Person>> cur = clnCache.query(qry);

    reconnectClientNode(
        cln,
        srv,
        new Runnable() {
          @Override
          public void run() {
            srvCache.put(4, new Person(4, "name4", "surname4"));

            try {
              clnCache.query(qry);

              fail();
            } catch (CacheException e) {
              check(e);
            }
          }
        });

    List<Cache.Entry<Integer, Person>> res = cur.getAll();

    assertNotNull(res);
    assertEquals(4, res.size());
  }
  /** @throws Exception If failed. */
  public void testReconnectQueryInProgress() throws Exception {
    Ignite cln = grid(serverCount());

    assertTrue(cln.cluster().localNode().isClient());

    final Ignite srv = clientRouter(cln);

    final IgniteCache<Integer, Person> clnCache = cln.getOrCreateCache(QUERY_CACHE);

    clnCache.put(1, new Person(1, "name1", "surname1"));
    clnCache.put(2, new Person(2, "name2", "surname2"));
    clnCache.put(3, new Person(3, "name3", "surname3"));

    blockMessage(GridQueryNextPageResponse.class);

    final SqlQuery<Integer, Person> qry = new SqlQuery<>(Person.class, "_key <> 0");

    qry.setPageSize(1);

    final QueryCursor<Cache.Entry<Integer, Person>> cur1 = clnCache.query(qry);

    final IgniteInternalFuture<Object> fut =
        GridTestUtils.runAsync(
            new Callable<Object>() {
              @Override
              public Object call() throws Exception {
                try {
                  cur1.getAll();
                } catch (CacheException e) {
                  checkAndWait(e);

                  return true;
                }

                return false;
              }
            });

    // Check that client waiting operation.
    GridTestUtils.assertThrows(
        log,
        new Callable<Object>() {
          @Override
          public Object call() throws Exception {
            return fut.get(200);
          }
        },
        IgniteFutureTimeoutCheckedException.class,
        null);

    assertNotDone(fut);

    unblockMessage();

    reconnectClientNode(cln, srv, null);

    assertTrue((Boolean) fut.get(2, SECONDS));

    QueryCursor<Cache.Entry<Integer, Person>> cur2 = clnCache.query(qry);

    assertEquals(3, cur2.getAll().size());
  }