Ejemplo n.º 1
0
  @Test
  public void hypervisorCheckInReportsFailureWhenGuestIdUpdateFails() throws Exception {
    Owner owner = new Owner("admin");

    Map<String, List<GuestId>> hostGuestMap = new HashMap<String, List<GuestId>>();
    String expectedHostVirtId = "test-host";
    hostGuestMap.put(expectedHostVirtId, Arrays.asList(new GuestId("GUEST_B")));

    Consumer existing = new Consumer();
    existing.setUuid(expectedHostVirtId);
    existing.addGuestId(new GuestId("GUEST_A"));

    // Force update
    when(consumerCurator.findByUuid(eq(expectedHostVirtId))).thenReturn(existing);

    String expectedMessage = "Forced Exception.";
    RuntimeException exception = new RuntimeException(expectedMessage);
    // Simulate failure  when checking the owner
    when(consumerCurator.getHost(any(String.class))).thenThrow(exception);

    HypervisorCheckInResult result =
        hypervisorResource.hypervisorCheckIn(hostGuestMap, principal, owner.getKey());

    Set<String> failures = result.getFailedUpdate();
    assertEquals(1, failures.size());
    assertEquals(expectedHostVirtId + ": " + expectedMessage, failures.iterator().next());
  }
Ejemplo n.º 2
0
  @Test
  public void hypervisorCheckInUpdatesGuestIdsWhenHostConsumerExists() throws Exception {
    Owner owner = new Owner("admin");

    Map<String, List<GuestId>> hostGuestMap = new HashMap<String, List<GuestId>>();
    hostGuestMap.put("test-host", Arrays.asList(new GuestId("GUEST_B")));

    Owner o = new Owner();
    o.setId("owner-id");
    Consumer existing = new Consumer();
    existing.setUuid("test-host");
    existing.setOwner(o);
    existing.addGuestId(new GuestId("GUEST_A"));

    when(consumerCurator.findByUuid(eq("test-host"))).thenReturn(existing);

    HypervisorCheckInResult result =
        hypervisorResource.hypervisorCheckIn(hostGuestMap, principal, owner.getKey());
    Set<Consumer> updated = result.getUpdated();
    assertEquals(1, updated.size());

    Consumer c1 = updated.iterator().next();
    assertEquals("test-host", c1.getUuid());
    assertEquals(1, c1.getGuestIds().size());
    assertEquals("GUEST_B", c1.getGuestIds().get(0).getGuestId());
  }