/**
   * Test to make sure that dynamic querying sends a query with TTL=1 and other properties when a
   * neighboring Ultrapeer has a hit in its QRP table for that query.
   */
  public void testDynamicQueryingWithQRPHit() throws Exception {
    assertTrue("should be connected", connectionServices.isConnected());

    searchServices.query(searchServices.newQueryGUID(), match);
    Thread.sleep(4000);

    QueryRequest qSent =
        BlockingConnectionUtils.getFirstInstanceOfMessageType(ULTRAPEER[0], QueryRequest.class);

    // The TTL on the sent query should be 1 because the other Ultrapeer
    // should have a "hit" in its QRP table.  When there's a hit, we
    // send with TTL 1 simply because it's likely that it's popular.
    if (qSent.getTTL() != 1) {
      // see if qrp got exchanged properly
      int num = connectionManager.getInitializedConnections().size();
      double totalQrp = 0;
      for (RoutedConnection rc : connectionManager.getInitializedClientConnections())
        totalQrp += rc.getRoutedConnectionStatistics().getQueryRouteTablePercentFull();
      fail(
          "ttl was not 1 but "
              + qSent.getTTL()
              + " there were "
              + num
              + " connections with qrp total "
              + totalQrp);
    }
    assertEquals("wrong hops", 0, qSent.getHops());
  }
 /**
  * Test to make sure we will never send with a TTL of 1 to a Ultrapeer that doesn't have a hit.
  */
 public void testSentQueryIsNotTTL1() throws Exception {
   assertTrue("should be connected", connectionServices.isConnected());
   searchServices.query(searchServices.newQueryGUID(), noMatch);
   Thread.sleep(2000);
   // we will send the query, but with a TTL of 2, not 1, because
   // the ultrapeer doesn't have this query in its qrp table.
   QueryRequest qSent =
       BlockingConnectionUtils.getFirstInstanceOfMessageType(ULTRAPEER[0], QueryRequest.class);
   assertEquals("wrong ttl", 2, qSent.getTTL());
   assertEquals("wrong hops", 0, qSent.getHops());
 }