/** {@inheritDoc} */
  @Override
  public void testEvictExpired() throws Exception {
    IgniteCache<String, Integer> cache = jcache();

    String key = primaryKeysForCache(cache, 1).get(0);

    cache.put(key, 1);

    assertEquals((Integer) 1, cache.get(key));

    long ttl = 500;

    grid(0)
        .cache(null)
        .withExpiryPolicy(new TouchedExpiryPolicy(new Duration(MILLISECONDS, ttl)))
        .put(key, 1);

    Thread.sleep(ttl + 100);

    // Expired entry should not be swapped.
    cache.localEvict(Collections.singleton(key));

    assertNull(cache.localPeek(key, CachePeekMode.ONHEAP));

    cache.localPromote(Collections.singleton(key));

    assertNull(cache.localPeek(key, CachePeekMode.ONHEAP));

    assertTrue(cache.localSize() == 0);

    load(cache, key, true);

    Affinity<String> aff = ignite(0).affinity(null);

    for (int i = 0; i < gridCount(); i++) {
      if (aff.isPrimaryOrBackup(grid(i).cluster().localNode(), key))
        assertEquals((Integer) 1, peek(jcache(i), key));
    }
  }
 /**
  * Create a new broker connection.
  *
  * <p>If <a href="http://www.rabbitmq.com/api-guide.html#recovery">automatic connection
  * recovery</a> is enabled, the connection returned by this method will be {@link Recoverable}.
  * Reconnection attempts will always use the address configured on {@link ConnectionFactory}.
  *
  * @param connectionName arbitrary sring for connection name client property
  * @return an interface to the connection
  * @throws IOException if it encounters a problem
  */
 public Connection newConnection(String connectionName) throws IOException, TimeoutException {
   return newConnection(
       this.sharedExecutor,
       Collections.singletonList(new Address(getHost(), getPort())),
       connectionName);
 }
  /** @throws Exception If failed. */
  public void testEmptyProjections() throws Exception {
    final GridClientCompute dflt = client.compute();

    Collection<? extends GridClientNode> nodes = dflt.nodes();

    assertEquals(NODES_CNT, nodes.size());

    Iterator<? extends GridClientNode> iter = nodes.iterator();

    final GridClientCompute singleNodePrj = dflt.projection(Collections.singletonList(iter.next()));

    final GridClientNode second = iter.next();

    final GridClientPredicate<GridClientNode> noneFilter =
        new GridClientPredicate<GridClientNode>() {
          @Override
          public boolean apply(GridClientNode node) {
            return false;
          }
        };

    final GridClientPredicate<GridClientNode> targetFilter =
        new GridClientPredicate<GridClientNode>() {
          @Override
          public boolean apply(GridClientNode node) {
            return node.nodeId().equals(second.nodeId());
          }
        };

    GridTestUtils.assertThrows(
        log(),
        new Callable<Object>() {
          @Override
          public Object call() throws Exception {
            return dflt.projection(noneFilter).log(-1, -1);
          }
        },
        GridServerUnreachableException.class,
        null);

    GridTestUtils.assertThrows(
        log(),
        new Callable<Object>() {
          @Override
          public Object call() throws Exception {
            return singleNodePrj.projection(second);
          }
        },
        GridClientException.class,
        null);

    GridTestUtils.assertThrows(
        log(),
        new Callable<Object>() {
          @Override
          public Object call() throws Exception {
            return singleNodePrj.projection(targetFilter);
          }
        },
        GridClientException.class,
        null);
  }
 /**
  * Create a new broker connection.
  *
  * <p>If <a href="http://www.rabbitmq.com/api-guide.html#recovery">automatic connection
  * recovery</a> is enabled, the connection returned by this method will be {@link Recoverable}.
  * Reconnection attempts will always use the address configured on {@link ConnectionFactory}.
  *
  * @param executor thread execution service for consumers on the connection
  * @return an interface to the connection
  * @throws IOException if it encounters a problem
  */
 public Connection newConnection(ExecutorService executor) throws IOException, TimeoutException {
   return newConnection(executor, Collections.singletonList(new Address(getHost(), getPort())));
 }