/** * 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()); }
protected BlockingConnection connect(boolean ultrapeer) throws Exception { ServerSocket ss = new ServerSocket(); ss.setReuseAddress(true); ss.bind(new InetSocketAddress(0)); connectionServices.connectToHostAsynchronously( "127.0.0.1", ss.getLocalPort(), ConnectType.PLAIN); Socket socket = ss.accept(); ss.close(); socket.setSoTimeout(3000); InputStream in = socket.getInputStream(); String word = IOUtils.readWord(in, 9); if (!word.equals("GNUTELLA")) throw new IOException("Bad word: " + word); HandshakeResponder responder; if (ultrapeer) { responder = new UltrapeerResponder(); } else { responder = new OldResponder(); } BlockingConnection con = blockingConnectionFactory.createConnection(socket); con.initialize(null, responder, 1000); replyToPing(con, ultrapeer); return con; }
/** * 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()); }
@Override public void setUp() throws Exception { final ResponseVerifier testVerifier = new TestResponseVerifier(); Injector injector = LimeTestUtils.createInjector( new AbstractModule() { @Override protected void configure() { bind(ResponseVerifier.class).toInstance(testVerifier); } }); super.setUp(injector); connectionManager = injector.getInstance(ConnectionManager.class); connectionServices = injector.getInstance(ConnectionServices.class); searchServices = injector.getInstance(SearchServices.class); int tries = 0; do { Thread.sleep(1000); if (connectionServices.isConnected() && connectionManager.getInitializedConnections().isEmpty() && connectionManager .getInitializedConnections() .get(0) .getRoutedConnectionStatistics() .getQueryRouteTablePercentFull() > 0) break; } while (tries++ < 10); assertTrue(connectionServices.isConnected()); assertFalse(connectionManager.getInitializedConnections().isEmpty()); assertGreaterThan( 0, connectionManager .getInitializedConnections() .get(0) .getRoutedConnectionStatistics() .getQueryRouteTablePercentFull()); }
protected void setUp(Injector injector) throws Exception { // calls all doSettings() for me and my parents PrivilegedAccessor.invokeAllStaticMethods(this.getClass(), "doSettings", null); this.injector = injector; // calls all doSettings() for me and my children // rs=new RouterService(callback); assertEquals("unexpected port", SERVER_PORT, NetworkSettings.PORT.getValue()); lifecycleManager = injector.getInstance(LifecycleManager.class); connectionServices = injector.getInstance(ConnectionServices.class); blockingConnectionFactory = injector.getInstance(BlockingConnectionFactory.class); pingReplyFactory = injector.getInstance(PingReplyFactory.class); headersFactory = injector.getInstance(HeadersFactory.class); lifecycleManager.start(); connectionServices.connect(); Thread.sleep(2000); assertEquals("unexpected port", SERVER_PORT, NetworkSettings.PORT.getValue()); }
/** * Implements <tt>ReplyHandler</tt> interface. Returns whether this node is a leaf or an * Ultrapeer. * * @return <tt>true</tt> if this node is a leaf node, otherwise <tt>false</tt> */ public boolean isLeafConnection() { return !connectionServices.isSupernode(); }
@Override protected void tearDown() throws Exception { if (connectionServices != null) connectionServices.disconnect(); if (lifecycleManager != null) lifecycleManager.shutdown(); }