public void testDoesNotAssignPassiveLeafIfDisabled() throws Exception {
    ConnectionSettings.EVER_ACCEPTED_INCOMING.setValue(true);
    DHTSettings.ENABLE_PASSIVE_LEAF_DHT_MODE.setValue(false);
    long startTime =
        System.currentTimeMillis() - DHTSettings.MIN_PASSIVE_LEAF_DHT_INITIAL_UPTIME.getValue();
    PrivilegedAccessor.setValue(nodeAssigner, "startTime", new Long(startTime));

    mockery.checking(buildBandwdithExpectations(true));
    mockery.checking(
        buildDHTExpectations(
            DHTMode.INACTIVE,
            true,
            true,
            false, // can't receive unsolicited
            DHTSettings.MIN_PASSIVE_LEAF_DHT_AVERAGE_UPTIME.getValue() + 1,
            false,
            false));

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

    assignerRunnable.run();
    mockery.assertIsSatisfied();
  }
  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();
  }
  public void testPassiveLeafDoesNotNeedHardCore() throws Exception {
    // not accepted incoming previously therefore not hardcore
    long startTime =
        System.currentTimeMillis() - DHTSettings.MIN_PASSIVE_LEAF_DHT_INITIAL_UPTIME.getValue();
    PrivilegedAccessor.setValue(nodeAssigner, "startTime", new Long(startTime));

    mockery.checking(buildBandwdithExpectations(true));
    mockery.checking(
        buildDHTExpectations(
            DHTMode.INACTIVE,
            true,
            true,
            false, // can't receive unsolicited
            DHTSettings.MIN_PASSIVE_LEAF_DHT_AVERAGE_UPTIME.getValue() + 1,
            false,
            false));

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

    assignerRunnable.run();
    mockery.assertIsSatisfied();
  }
  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();
  }
 @Override
 public void setSettings() throws Exception {
   // TODO change this, by either introducing a setter or overriding FileManagerController
   PrivilegedAccessor.setValue(QRPUpdater.class, "QRP_DELAY", 1000);
   SearchSettings.LIME_QRP_ENTRIES.set(new String[] {"badger"});
   SearchSettings.LIME_SEARCH_TERMS.set(new String[] {"badger"});
   SearchSettings.SEND_LIME_RESPONSES.setValue(1f);
 }
  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();
  }