private GroupResourcePlacementState createAndStoreGroupResourcePlacement() throws Throwable { return createAndStoreGroupResourcePlacement("reservation-test", 8 * CONTAINER_MEMORY + CONTAINER_MEMORY / 2, 0L, 0, 0, resourcePool.documentSelfLink, false); }
@Test public void testGroupPlacementValidation() throws Throwable { createAndStoreGroupResourcePlacement("negative-memory-limit", -1L, 0L, 0, 0, resourcePool.documentSelfLink, true /* expectFailure */); createAndStoreGroupResourcePlacement("negative-cpu-shares", 0L, 0L, 0, -1, resourcePool.documentSelfLink, true /* expectFailure */); createAndStoreGroupResourcePlacement("negative-priority-shares", 0L, 0L, -1, 0, resourcePool.documentSelfLink, true /* expectFailure */); }
createAndStoreGroupResourcePlacement("moreMemoryThanRP", MIN_MEMORY * 2 + 2, 1000L, 0, 0, resourcePool1.documentSelfLink, expectFailure); GroupResourcePlacementState firstPlacement = createAndStoreGroupResourcePlacement( "firstPlacement", MIN_MEMORY, 200L, 0, 0, resourcePool1.documentSelfLink, expectFailure); GroupResourcePlacementState secondPlacement = createAndStoreGroupResourcePlacement( "secondPlacement", MIN_MEMORY, 200L, 0, 0, resourcePool1.documentSelfLink, expectFailure); createAndStoreGroupResourcePlacement("moreMemoryThanWhatsLeft", MIN_MEMORY, 200L, 0, 0, resourcePool1.documentSelfLink, expectFailure);
@Test public void testDeleteWhenNoActiveReservation() throws Throwable { GroupResourcePlacementState placementState = createAndStoreGroupResourcePlacement(); try { DeploymentProfileConfig.getInstance().setTest(false); doDelete(UriUtils.buildUri(host, placementState.documentSelfLink), false); } finally { DeploymentProfileConfig.getInstance().setTest(true); } ServiceDocumentQuery<GroupResourcePlacementState> query = new ServiceDocumentQuery<>(host, GroupResourcePlacementState.class); AtomicBoolean deleted = new AtomicBoolean(); CountDownLatch countDownLatch = new CountDownLatch(1); query.queryDocument(placementState.documentSelfLink, (r) -> { if (!r.hasException() && !r.hasResult()) { deleted.set(true); countDownLatch.countDown(); } }); countDownLatch.await(); assertTrue(deleted.get()); }
@Test public void testDeleteWhenActiveReservation() throws Throwable { GroupResourcePlacementState placementState = createAndStoreGroupResourcePlacement(); placementState = makeResourcePlacementReservationRequest(placementState, 5); boolean expectedFailure = true; try { DeploymentProfileConfig.getInstance().setTest(false); doDelete(UriUtils.buildUri(host, placementState.documentSelfLink), expectedFailure); fail("expect validation error during deletion"); } catch (LocalizableValidationException e) { // expected } finally { DeploymentProfileConfig.getInstance().setTest(true); } }
@Test public void testDeleteWhenWrongReservationCount() throws Throwable { GroupResourcePlacementState placementState = createAndStoreGroupResourcePlacement(); createContainer(placementState.documentSelfLink); boolean expectedFailure = true; try { DeploymentProfileConfig.getInstance().setTest(false); doDelete(UriUtils.buildUri(host, placementState.documentSelfLink), expectedFailure); fail("expect validation error during deletion"); } catch (LocalizableValidationException e) { // expected } finally { DeploymentProfileConfig.getInstance().setTest(true); } }
@Test public void testMemoryPlacementPatchRequest() throws Throwable { GroupResourcePlacementState placementState = createAndStoreGroupResourcePlacement(); String descLink = containerDescription.documentSelfLink; int count = 8; boolean expectFailure = false; placementState = makeResourcePlacementReservationRequest(count, descLink, placementState, expectFailure); // Set the memory limit to something smaller than what's already reserved placementState.memoryLimit = 700; expectFailure = true; host.testStart(1); host.send(Operation .createPut(UriUtils.buildUri(host, placementState.documentSelfLink)) .setBody(placementState) .setCompletion(expectFailure ? host.getExpectedFailureCompletion() : host.getCompletion())); host.testWait("Asd", (int) TimeUnit.MINUTES.toSeconds(1)); releasePlacement(placementState, descLink, count); }
@Test public void testUpdateWhenNoActiveReservations() throws Throwable { GroupResourcePlacementState placementState = createAndStoreGroupResourcePlacement(); String newName = "newName"; int newMaxInstance = 7;
@Test public void testResourcePlacementReservationRequest() throws Throwable { GroupResourcePlacementState placementState = createAndStoreGroupResourcePlacement(); String descLink = containerDescription.documentSelfLink; int count = 8; boolean expectFailure = false; placementState = makeResourcePlacementReservationRequest(count, descLink, placementState, expectFailure); assertEquals(2, placementState.availableInstancesCount); assertEquals(count, placementState.allocatedInstancesCount); // release resource placements: count = -5; placementState = makeResourcePlacementReservationRequest(count, descLink, placementState, expectFailure); assertEquals(7, placementState.availableInstancesCount); assertEquals(3, placementState.allocatedInstancesCount); // try to release resource placements more than max (success with log warning): count = (int) -(placementState.maxNumberInstances - placementState.availableInstancesCount + 1); placementState = makeResourcePlacementReservationRequest(count, descLink, placementState, expectFailure); // releasing placements within max but more than reserved per desc: descLink = createAndStoreContainerDescription("new-desc").documentSelfLink; count = 4; placementState = makeResourcePlacementReservationRequest(count, descLink, placementState, expectFailure); doDelete(UriUtils.buildUri(host, descLink), false); // release what's left of the provisioned resources releasePlacement(placementState, descLink, count); }
@Test public void testMemoryPlacementReservationRequest() throws Throwable { GroupResourcePlacementState placementState = createAndStoreGroupResourcePlacement(); String descLink = containerDescription.documentSelfLink; int count = 8; createAndStoreGroupResourcePlacement( "test", 0L, 0L, 0, 0, resourcePool.documentSelfLink, false); expectFailure = false;
@Test public void testUpdateWhenActiveReservations() throws Throwable { GroupResourcePlacementState placementState = createAndStoreGroupResourcePlacement();