public void test_lbs_host_policy(){
  final String H1="H1";
  final HostScore hostScore1=new HostScore("H1",1d);
  assertEquals(1d,hostScore1.getAvailability());
  final HostScore[] hostScores=new HostScore[]{hostScore1};
{
    final HostScore actualHost=AbstractHostLBSPolicy.getHost(.0,hostScores);
    assertSameRef(hostScore1,actualHost);
  }
{
    final HostScore actualHost=AbstractHostLBSPolicy.getHost(.1,hostScores);
    assertSameRef(hostScore1,actualHost);
  }
{
    final HostScore actualHost=AbstractHostLBSPolicy.getHost(.5,hostScores);
    assertSameRef(hostScore1,actualHost);
  }
{
    final HostScore actualHost=AbstractHostLBSPolicy.getHost(.9,hostScores);
    assertSameRef(hostScore1,actualHost);
  }
{
    try {
      AbstractHostLBSPolicy.getHost(1d,hostScores);
    }
 catch (    IllegalArgumentException ex) {
      if (log.isInfoEnabled())       log.info(ex);
    }
  }
{
    try {
      AbstractHostLBSPolicy.getHost(-.00001d,hostScores);
    }
 catch (    IllegalArgumentException ex) {
      if (log.isInfoEnabled())       log.info(ex);
    }
  }
  final UUID A=UUID.randomUUID();
  final UUID B=UUID.randomUUID();
  final UUID C=UUID.randomUUID();
  final ServiceScore serviceA=new ServiceScore(A,H1,toRequestURI(H1));
  final ServiceScore serviceB=new ServiceScore(B,H1,toRequestURI(H1));
  final ServiceScore serviceC=new ServiceScore(C,H1,toRequestURI(H1));
{
{
      final Random rand=new Random(1L);
      final ServiceScore[] serviceScores=new ServiceScore[]{serviceA};
      final ServiceScore actualService=AbstractHostLBSPolicy.getService(rand,hostScore1,serviceScores);
      assertTrue(actualService == serviceA);
    }
{
      final Random rand=new Random(1L);
      final ServiceScore[] serviceScores=new ServiceScore[]{serviceA,serviceB,serviceC};
      final ServiceScore actualService=AbstractHostLBSPolicy.getService(rand,hostScore1,serviceScores);
      assertTrue(actualService == serviceA);
    }
  }
}

public void test_lbs_host_policy ( ) { final String H1 = "H1" ; final HostScore hostScore1 = new HostScore ( "H1" , 1d ) ; assertEquals ( 1d , hostScore1 . getAvailability ( ) ) ; final HostScore [ ] hostScores = new HostScore [ ] { hostScore1 } ; { final HostScore actualHost = AbstractHostLBSPolicy . getHost ( .0 , hostScores ) ; assertSameRef ( hostScore1 , actualHost ) ; } { final HostScore actualHost = AbstractHostLBSPolicy . getHost ( .1 , hostScores ) ; assertSameRef ( hostScore1 , actualHost ) ; } { final HostScore actualHost = AbstractHostLBSPolicy . getHost ( .5 , hostScores ) ; assertSameRef ( hostScore1 , actualHost ) ; } { final HostScore actualHost = AbstractHostLBSPolicy . getHost ( .9 , hostScores ) ; assertSameRef ( hostScore1 , actualHost ) ; } { try { AbstractHostLBSPolicy . getHost ( 1d , hostScores ) ; } catch ( IllegalArgumentException ex ) { if ( log . isInfoEnabled ( ) ) log . info ( ex ) ; } } { try { AbstractHostLBSPolicy . getHost ( - .00001d , hostScores ) ; } catch ( IllegalArgumentException ex ) { if ( log . isInfoEnabled ( ) ) log . info ( ex ) ; } } final UUID A = UUID . randomUUID ( ) ; final UUID B = UUID . randomUUID ( ) ; final UUID C = UUID . randomUUID ( ) ; final ServiceScore serviceA = new ServiceScore ( A , H1 , toRequestURI ( H1 ) ) ; final ServiceScore serviceB = new ServiceScore ( B , H1 , toRequestURI ( H1 ) ) ; final ServiceScore serviceC = new ServiceScore ( C , H1 , toRequestURI ( H1 ) ) ; { { final Random rand = new Random ( 1L ) ; final ServiceScore [ ] serviceScores = new ServiceScore [ ] { serviceA } ; final ServiceScore actualService = AbstractHostLBSPolicy . getService ( rand , hostScore1 , serviceScores ) ; assertTrue ( actualService == serviceA ) ; } { final Random rand = new Random ( 1L ) ; final ServiceScore [ ] serviceScores = new ServiceScore [ ] { serviceA , serviceB , serviceC } ; final ServiceScore actualService = AbstractHostLBSPolicy . getService ( rand , hostScore1 , serviceScores ) ; assertTrue ( actualService == serviceA ) ; } } }
this test covers the case where there is only one host and it is running one or more services .
