@Test public void testMissingComputeLink() throws Throwable { ModelUtils.createComputeWithDescription(this); ProvisionComputeTaskService.ProvisionComputeTaskState startState = new ProvisionComputeTaskService.ProvisionComputeTaskState(); startState.computeLink = null; postServiceSynchronously( ProvisionComputeTaskService.FACTORY_LINK, startState, ProvisionComputeTaskService.ProvisionComputeTaskState.class, IllegalArgumentException.class); }
private void createValidStates() throws Throwable { this.endpointState = ModelUtils.createEndpoint(this); this.networkState = ModelUtils.createNetwork(this, this.endpointState); this.subnetState = ModelUtils.createSubnet(this, this.networkState, this.endpointState); this.subnetRangeState1 = ModelUtils .createSubnetRange(this, this.subnetState, this.startIpInRange1, this.endIpInRange1); this.subnetRangeState2 = ModelUtils .createSubnetRange(this, this.subnetState, this.startIpInRange2, this.endIpInRange2); }
ResourceRemovalTaskState startState = buildValidStartState(); ComputeService.ComputeStateWithDescription cs = ModelUtils .createComputeWithDescription(this, MockAdapter.MockSuccessInstanceAdapter.SELF_LINK, null); List<SnapshotService.SnapshotState> sl = ModelUtils.createSnapshotsWithHierarchy(this, cs.documentSelfLink);
@Test public void testAllocationTaskServiceWithNoRanges() throws Throwable { SubnetService.SubnetState subnetState = ModelUtils.createSubnet(this, this .networkState, this.endpointState); IPAddressAllocationTaskState allocationTask = createIpAddressAllocationTask( subnetState.documentSelfLink, ComputeService.FACTORY_LINK + "/machine-1"); IPAddressAllocationTaskState allocationTaskResult; addFakeCallBack(allocationTask); // task should not fail, but no IP addresses are allocated allocationTaskResult = performTask(allocationTask); assertNotNull(allocationTaskResult); assertEquals(0, allocationTaskResult.rsrcToAllocatedIpsMap.size()); assertEquals(0, allocationTaskResult.subnetRangeLinks.size()); }
@Test public void testSuccessWithEnumerationAndExpliciteResourcePool() throws Throwable { EndpointState endpoint = createEndpointState(); ResourcePoolState pool = ModelUtils.createResourcePool(this); EndpointAllocationTaskState startState = createEndpointAllocationRequest(endpoint); startState.adapterReference = UriUtils.buildUri(getHost(),
@Test public void testAllocateSpecificIPWithNoRanges() throws Throwable { SubnetService.SubnetState subnetState = ModelUtils.createSubnet(this, this .networkState, this.endpointState); IPAddressAllocationTaskState allocationTask = createIpAddressAllocationTask( subnetState.documentSelfLink, ComputeService.FACTORY_LINK + "/machine-1"); allocationTask.requestType = RequestType.ALLOCATE_SPECIFIC_IP; allocationTask.ipAddresses.add(SPECIFIC_IP); IPAddressAllocationTaskState allocationTaskResult; addFakeCallBack(allocationTask); // task should not fail, but no IP addresses are allocated allocationTaskResult = performTask(allocationTask); assertNotNull(allocationTaskResult); assertEquals(0, allocationTaskResult.rsrcToAllocatedIpsMap.size()); assertEquals(0, allocationTaskResult.subnetRangeLinks.size()); assertEquals(0, allocationTaskResult.ipAddresses.size()); assertEquals(0, allocationTaskResult.ipAddressLinks.size()); }
@Test public void testSuccessUpdateWithEnumerationAndExpliciteResourcePool() throws Throwable { EndpointState endpoint = createEndpointState(); ResourcePoolState pool = ModelUtils.createResourcePool(this); EndpointAllocationTaskState startState = createEndpointAllocationRequest(endpoint); startState.adapterReference = UriUtils.buildUri(getHost(),
@Test public void testMissingSubStage() throws Throwable { ModelUtils.createComputeWithDescription(this); ProvisionComputeTaskService.ProvisionComputeTaskState startState = new ProvisionComputeTaskService.ProvisionComputeTaskState(); startState.taskSubStage = null; postServiceSynchronously( ProvisionComputeTaskService.FACTORY_LINK, startState, ProvisionComputeTaskService.ProvisionComputeTaskState.class, IllegalArgumentException.class); }
if (i == 3) { computes.add(ModelUtils .createComputeWithDescription(this, MockAdapter.MockFailureInstanceAdapter.SELF_LINK, null)); } else { computes.add(ModelUtils.createComputeWithDescription(this, MockAdapter.MockSuccessInstanceAdapter.SELF_LINK, null));
new ArrayList<>(totalComputeCount); for (int i = 0; i < totalComputeCount; i++) { computes.add(ModelUtils.createComputeWithDescription(this, MockAdapter.MockSuccessInstanceAdapter.SELF_LINK, null));
new ArrayList<>(totalComputeCount); for (int i = 0; i < totalComputeCount; i++) { computes.add(ModelUtils.createComputeWithDescription(this, MockAdapter.MockSuccessInstanceAdapter.SELF_LINK, null));
@Test public void testCreateHostFailure() throws Throwable { ComputeService.ComputeStateWithDescription cs = ModelUtils .createComputeWithDescription(this, MockAdapter.MockFailureInstanceAdapter.SELF_LINK, null); ProvisionComputeTaskService.ProvisionComputeTaskState startState = new ProvisionComputeTaskService.ProvisionComputeTaskState(); startState.computeLink = cs.documentSelfLink; startState.taskSubStage = ProvisionComputeTaskService.ProvisionComputeTaskState.SubStage.CREATING_HOST; startState.isMockRequest = true; ProvisionComputeTaskService.ProvisionComputeTaskState returnState = postServiceSynchronously( ProvisionComputeTaskService.FACTORY_LINK, startState, ProvisionComputeTaskService.ProvisionComputeTaskState.class); ProvisionComputeTaskService.ProvisionComputeTaskState completeState = waitForServiceState( ProvisionComputeTaskService.ProvisionComputeTaskState.class, returnState.documentSelfLink, state -> TaskState.TaskStage.FINISHED.ordinal() <= state.taskInfo.stage .ordinal()); assertThat(completeState.taskInfo.stage, is(TaskState.TaskStage.FAILED)); }
@Test public void testCreateAndBootHostSuccess() throws Throwable { ComputeService.ComputeStateWithDescription cs = ModelUtils .createComputeWithDescription(this, MockAdapter.MockSuccessInstanceAdapter.SELF_LINK, MockAdapter.MockSuccessBootAdapter.SELF_LINK); ProvisionComputeTaskService.ProvisionComputeTaskState startState = new ProvisionComputeTaskService.ProvisionComputeTaskState(); startState.computeLink = cs.documentSelfLink; startState.taskSubStage = ProvisionComputeTaskService.ProvisionComputeTaskState.SubStage.CREATING_HOST; startState.isMockRequest = true; ProvisionComputeTaskService.ProvisionComputeTaskState returnState = postServiceSynchronously( ProvisionComputeTaskService.FACTORY_LINK, startState, ProvisionComputeTaskService.ProvisionComputeTaskState.class); ProvisionComputeTaskService.ProvisionComputeTaskState completeState = waitForServiceState( ProvisionComputeTaskService.ProvisionComputeTaskState.class, returnState.documentSelfLink, state -> TaskState.TaskStage.FINISHED.ordinal() <= state.taskInfo.stage .ordinal()); assertThat(completeState.taskInfo.stage, is(TaskState.TaskStage.FINISHED)); }
@Test public void testValidateComputeHost() throws Throwable { ComputeService.ComputeStateWithDescription cs = ModelUtils .createComputeWithDescription(this); ProvisionComputeTaskService.ProvisionComputeTaskState startState = new ProvisionComputeTaskService.ProvisionComputeTaskState(); startState.computeLink = cs.documentSelfLink; startState.taskSubStage = ProvisionComputeTaskService.ProvisionComputeTaskState.SubStage.VALIDATE_COMPUTE_HOST; startState.isMockRequest = true; ProvisionComputeTaskService.ProvisionComputeTaskState returnState = postServiceSynchronously( ProvisionComputeTaskService.FACTORY_LINK, startState, ProvisionComputeTaskService.ProvisionComputeTaskState.class); ProvisionComputeTaskService.ProvisionComputeTaskState completeState = waitForServiceState( ProvisionComputeTaskService.ProvisionComputeTaskState.class, returnState.documentSelfLink, state -> TaskState.TaskStage.FINISHED.ordinal() <= state.taskInfo.stage .ordinal()); assertThat(completeState.taskInfo.stage, is(TaskState.TaskStage.FINISHED)); }
@Test public void testBootHostFailure() throws Throwable { ComputeService.ComputeStateWithDescription cs = ModelUtils .createComputeWithDescription(this, MockAdapter.MockSuccessInstanceAdapter.SELF_LINK, MockAdapter.MockFailureBootAdapter.SELF_LINK); ProvisionComputeTaskService.ProvisionComputeTaskState startState = new ProvisionComputeTaskService.ProvisionComputeTaskState(); startState.computeLink = cs.documentSelfLink; startState.taskSubStage = ProvisionComputeTaskService.ProvisionComputeTaskState.SubStage.CREATING_HOST; startState.isMockRequest = true; ProvisionComputeTaskService.ProvisionComputeTaskState returnState = postServiceSynchronously( ProvisionComputeTaskService.FACTORY_LINK, startState, ProvisionComputeTaskService.ProvisionComputeTaskState.class); ProvisionComputeTaskService.ProvisionComputeTaskState completeState = waitForServiceState( ProvisionComputeTaskService.ProvisionComputeTaskState.class, returnState.documentSelfLink, state -> TaskState.TaskStage.FINISHED.ordinal() <= state.taskInfo.stage .ordinal()); assertThat(completeState.taskInfo.stage, is(TaskState.TaskStage.FAILED)); } }
@Test public void testLocalResourceRemovalOnlySuccess() throws Throwable { ResourceRemovalTaskState startState = buildValidStartState(); startState.options = EnumSet.of(TaskOption.DOCUMENT_CHANGES_ONLY); ComputeService.ComputeStateWithDescription cs = ModelUtils .createComputeWithDescription(this, MockAdapter.MockFailOnInvokeInstanceAdapter.SELF_LINK, null); ResourceRemovalTaskState returnState = this .postServiceSynchronously( ResourceRemovalTaskService.FACTORY_LINK, startState, ResourceRemovalTaskState.class); returnState = this .waitForServiceState( ResourceRemovalTaskState.class, returnState.documentSelfLink, state -> state.taskInfo.stage == TaskState.TaskStage.FINISHED); assertThat(returnState.taskSubStage, is(SubStage.FINISHED)); // Clean up the compute and description documents this.deleteServiceSynchronously(cs.documentSelfLink); this.deleteServiceSynchronously(cs.descriptionLink); // Stop factory service. this.deleteServiceSynchronously(ResourceRemovalTaskService.FACTORY_LINK); // stop the removal task this.stopServiceSynchronously(returnState.documentSelfLink); }
@Test public void testResourceRemovalSuccess() throws Throwable { ResourceRemovalTaskState startState = buildValidStartState(); ComputeService.ComputeStateWithDescription cs = ModelUtils .createComputeWithDescription(this, MockAdapter.MockSuccessInstanceAdapter.SELF_LINK, null); ResourceRemovalTaskState returnState = this .postServiceSynchronously( ResourceRemovalTaskService.FACTORY_LINK, startState, ResourceRemovalTaskState.class); returnState = this .waitForServiceState( ResourceRemovalTaskState.class, returnState.documentSelfLink, state -> state.taskInfo.stage == TaskState.TaskStage.FINISHED); assertThat(returnState.taskSubStage, is(SubStage.FINISHED)); // Clean up the compute and description documents this.deleteServiceSynchronously(cs.documentSelfLink); this.deleteServiceSynchronously(cs.descriptionLink); // Stop factory service. this.deleteServiceSynchronously(ResourceRemovalTaskService.FACTORY_LINK); // stop the removal task this.stopServiceSynchronously(returnState.documentSelfLink); }
@Test public void testResourceRemovalFailure() throws Throwable { ResourceRemovalTaskState startState = buildValidStartState(); ComputeService.ComputeStateWithDescription cs = ModelUtils .createComputeWithDescription(this, MockAdapter.MockFailureInstanceAdapter.SELF_LINK, null); ResourceRemovalTaskState returnState = this .postServiceSynchronously( ResourceRemovalTaskService.FACTORY_LINK, startState, ResourceRemovalTaskState.class); this.waitForServiceState( ResourceRemovalTaskState.class, returnState.documentSelfLink, state -> state.taskInfo.stage == TaskState.TaskStage.FAILED); // Clean up the compute and description documents this.deleteServiceSynchronously(cs.documentSelfLink); this.deleteServiceSynchronously(cs.descriptionLink); }