예제 #1
0
 public void testSync()
     throws SecurityException, NoSuchMethodException, InterruptedException, ExecutionException {
   assert syncClient.getImageServices() != null;
   assert syncClient.getIpServices() != null;
   assert syncClient.getJobServices() != null;
   assert syncClient.getLoadBalancerServices() != null;
   assert syncClient.getServerServices() != null;
 }
예제 #2
0
 /** In case anything went wrong during the tests, removes the objects created in the tests. */
 @AfterTest
 public void cleanup() {
   for (String serverName : serversToDeleteAfterTheTests) {
     try {
       client.getServerServices().deleteByName(serverName);
     } catch (Exception e) {
       // it's already been deleted - proceed
     }
   }
   for (String loadBalancerName : loadBalancersToDeleteAfterTest) {
     try {
       client.getLoadBalancerServices().deleteByName(loadBalancerName);
     } catch (Exception e) {
       // it's already been deleted - proceed
     }
   }
 }
예제 #3
0
  /** Tests common load balancer operations. Also verifies IP services and job services. */
  @Test(enabled = true)
  public void testLoadBalancerLifecycle() {
    int lbCountBeforeTest = client.getLoadBalancerServices().getLoadBalancerList().size();

    final String nameOfLoadBalancer =
        "LoadBalancer" + String.valueOf(new Date().getTime()).substring(6);
    loadBalancersToDeleteAfterTest.add(nameOfLoadBalancer);

    Set<Ip> availableIps = client.getIpServices().getUnassignedPublicIpList();

    if (availableIps.size() < 4)
      throw new SkipException("Not enough available IPs (4 needed) to run the test");
    Iterator<Ip> ipIterator = availableIps.iterator();
    Ip vip = ipIterator.next();
    Ip realIp1 = ipIterator.next();
    Ip realIp2 = ipIterator.next();
    Ip realIp3 = ipIterator.next();

    AddLoadBalancerOptions options =
        new AddLoadBalancerOptions.Builder()
            .create(LoadBalancerType.LEAST_CONNECTED, LoadBalancerPersistenceType.SOURCE_ADDRESS);
    LoadBalancer createdLoadBalancer =
        client
            .getLoadBalancerServices()
            .addLoadBalancer(
                nameOfLoadBalancer,
                IpPortPair.builder().ip(vip).port(80).build(),
                Arrays.asList(
                    IpPortPair.builder().ip(realIp1).port(80).build(),
                    IpPortPair.builder().ip(realIp2).port(80).build()),
                options);
    assertNotNull(createdLoadBalancer);
    assert loadBalancerLatestJobCompleted.apply(createdLoadBalancer);

    // get load balancer by name
    Set<LoadBalancer> response =
        client.getLoadBalancerServices().getLoadBalancersByName(nameOfLoadBalancer);
    assert (response.size() == 1);
    createdLoadBalancer = Iterables.getOnlyElement(response);
    assertNotNull(createdLoadBalancer.getRealIpList());
    assertEquals(createdLoadBalancer.getRealIpList().size(), 2);
    assertNotNull(createdLoadBalancer.getVirtualIp());
    assertEquals(createdLoadBalancer.getVirtualIp().getIp().getIp(), vip.getIp());

    LoadBalancer editedLoadBalancer =
        client
            .getLoadBalancerServices()
            .editLoadBalancerNamed(
                nameOfLoadBalancer,
                Arrays.asList(IpPortPair.builder().ip(realIp3).port(8181).build()));
    assert loadBalancerLatestJobCompleted.apply(editedLoadBalancer);
    assertNotNull(editedLoadBalancer.getRealIpList());
    assertEquals(editedLoadBalancer.getRealIpList().size(), 1);
    assertEquals(
        Iterables.getOnlyElement(editedLoadBalancer.getRealIpList()).getIp().getIp(),
        realIp3.getIp());

    int lbCountAfterAddingOneServer = client.getLoadBalancerServices().getLoadBalancerList().size();
    assert lbCountAfterAddingOneServer == lbCountBeforeTest + 1
        : "There should be +1 increase in the number of load balancers since the test started";

    // delete the load balancer
    client.getLoadBalancerServices().deleteByName(nameOfLoadBalancer);

    Set<Job> jobs = client.getJobServices().getJobsForObjectName(nameOfLoadBalancer);
    assert ("DeleteLoadBalancer".equals(Iterables.getLast(jobs).getCommand().getName()));

    assert loadBalancerLatestJobCompleted.apply(createdLoadBalancer);

    int lbCountAfterDeletingTheServer =
        client.getLoadBalancerServices().getLoadBalancerList().size();
    assert lbCountAfterDeletingTheServer == lbCountBeforeTest
        : "There should be the same # of load balancers as since the test started";
  }