Пример #1
0
  public void testStopsDHTWhenDisabled() throws Exception {
    ConnectionSettings.EVER_ACCEPTED_INCOMING.setValue(true);
    long startTime =
        System.currentTimeMillis() - DHTSettings.MIN_ACTIVE_DHT_INITIAL_UPTIME.getValue();
    PrivilegedAccessor.setValue(nodeAssigner, "startTime", new Long(startTime));

    mockery.checking(buildBandwdithExpectations(true));
    mockery.checking(
        buildDHTExpectations(
            DHTMode.ACTIVE,
            false,
            true,
            true,
            DHTSettings.MIN_ACTIVE_DHT_AVERAGE_UPTIME.getValue() + 1,
            false,
            false));

    mockery.checking(
        new Expectations() {
          {
            one(dhtManager).stop();
          }
        });

    assignerRunnable.run();
    mockery.assertIsSatisfied();
  }
Пример #2
0
  public void testDoesNotAssignLowAverageUptime() throws Exception {
    ConnectionSettings.EVER_ACCEPTED_INCOMING.setValue(true);
    long startTime =
        System.currentTimeMillis() - DHTSettings.MIN_ACTIVE_DHT_INITIAL_UPTIME.getValue();
    PrivilegedAccessor.setValue(nodeAssigner, "startTime", new Long(startTime));

    mockery.checking(buildBandwdithExpectations(true));
    mockery.checking(
        buildDHTExpectations(
            DHTMode.INACTIVE,
            true,
            true,
            true,
            0, // no average uptime
            false,
            false));

    mockery.checking(
        new Expectations() {
          {
            never(dhtManager).start(with(Matchers.any(DHTMode.class)));
          }
        });

    assignerRunnable.run();
    mockery.assertIsSatisfied();
  }
Пример #3
0
  public void testDoesNotAssignActiveIfNotHardcore() throws Exception {
    // not accepted incoming previously therefore not hardcore
    long startTime =
        System.currentTimeMillis() - DHTSettings.MIN_ACTIVE_DHT_INITIAL_UPTIME.getValue();
    PrivilegedAccessor.setValue(nodeAssigner, "startTime", new Long(startTime));

    mockery.checking(buildBandwdithExpectations(true));
    mockery.checking(
        buildDHTExpectations(
            DHTMode.INACTIVE,
            true,
            true,
            true,
            DHTSettings.MIN_ACTIVE_DHT_AVERAGE_UPTIME.getValue() + 1,
            false,
            false));

    mockery.checking(
        new Expectations() {
          {
            one(dhtManager).start(DHTMode.PASSIVE_LEAF);
          }
        });

    assignerRunnable.run();
    mockery.assertIsSatisfied();
  }
Пример #4
0
  public void testPromotesFromActiveDHTIfAllowed() throws Exception {
    // disallow switch to ultrapeer
    DHTSettings.SWITCH_TO_ULTRAPEER_PROBABILITY.setValue(1f);
    ConnectionSettings.EVER_ACCEPTED_INCOMING.setValue(true);
    ApplicationSettings.AVERAGE_UPTIME.setValue(UltrapeerSettings.MIN_AVG_UPTIME.getValue() + 1);
    assertFalse(UltrapeerSettings.EVER_ULTRAPEER_CAPABLE.getValue());

    // pretend some time passed - the uptime counter in NodeAssigner is very hacky
    long startTime =
        System.currentTimeMillis() - DHTSettings.MIN_ACTIVE_DHT_INITIAL_UPTIME.getValue();
    PrivilegedAccessor.setValue(nodeAssigner, "startTime", new Long(startTime));

    mockery.checking(buildBandwdithExpectations(true));
    // enabled and active DHT
    mockery.checking(buildUltrapeerExpectations(true, true, 0l, true, DHTMode.ACTIVE, false));

    // but we're not an active ultrapeer and can receive solicited
    // but we've been up long enough tob e active in the DHT
    mockery.checking(
        new Expectations() {
          {
            one(connectionServices).isActiveSuperNode();
            will(returnValue(false));
            one(networkManager).canReceiveSolicited();
            will(returnValue(true));
            atLeast(1).of(cManager).getCurrentAverageUptime();
            will(returnValue(DHTSettings.MIN_ACTIVE_DHT_AVERAGE_UPTIME.getValue() + 1));
          }
        });

    // will get promoted
    mockery.checking(buildPromotionExpectations(true));

    assignerRunnable.run();

    assertTrue(UltrapeerSettings.EVER_ULTRAPEER_CAPABLE.getValue());
    mockery.assertIsSatisfied();
  }