use of com.vmware.xenon.common.test.TestContext in project photon-model by vmware.
the class AzurePowerServiceTest method createTaskResultListener.
private void createTaskResultListener(VerificationHost host, String taskLink, Function<Operation, Boolean> h) {
StatelessService service = new StatelessService() {
@Override
public void handleRequest(Operation update) {
if (!h.apply(update)) {
super.handleRequest(update);
}
}
};
TestContext ctx = this.host.testCreate(1);
Operation startOp = Operation.createPost(host, taskLink).setCompletion((o, e) -> {
if (e != null) {
ctx.failIteration(e);
return;
}
ctx.completeIteration();
}).setReferer(this.host.getReferer());
this.host.startService(startOp, service);
ctx.await();
}
use of com.vmware.xenon.common.test.TestContext in project photon-model by vmware.
the class AzureInstanceTypeServiceTest method testGetInstanceTypes.
@Test
public void testGetInstanceTypes() throws Throwable {
Assume.assumeFalse(this.isMock);
TestContext ctx = getHost().testCreate(1);
URI uri = buildUri(getHost(), AzureInstanceTypeService.SELF_LINK, buildUriQuery("endpoint", this.endpointState.documentSelfLink));
send(Operation.createGet(uri).setCompletion((op, t) -> {
try {
if (t != null) {
ctx.failIteration(t);
return;
}
assertEquals(Operation.STATUS_CODE_OK, op.getStatusCode());
InstanceTypeList instanceTypesList = op.getBody(InstanceTypeList.class);
assertNotNull("Tenant links should ne set.", instanceTypesList.tenantLinks);
assertEquals("Tenant links size equal to endpoint tenant links size is " + "expected.", this.endpointState.tenantLinks.size(), instanceTypesList.tenantLinks.size());
assertNotNull("Instance types should not be null.", instanceTypesList.instanceTypes);
InstanceType instanceTypeBasicA0 = instanceTypesList.instanceTypes.stream().filter(instanceType -> VirtualMachineSizeTypes.BASIC_A0.toString().equals(instanceType.name)).findFirst().get();
assertNotNull("BASIC_A0 Instance type should not be null.", instanceTypeBasicA0);
final String regionId = this.endpointState.endpointProperties.get(EndpointConfigRequest.REGION_KEY);
final List<VirtualMachineSizeInner> azureSizes = getAzureSdkClients().getComputeManager().inner().virtualMachineSizes().list(regionId);
assertEquals(azureSizes.size(), instanceTypesList.instanceTypes.size());
VirtualMachineSizeInner azureSizeBasicA0 = azureSizes.stream().filter(azureSize -> VirtualMachineSizeTypes.BASIC_A0.toString().equals(azureSize.name())).findFirst().get();
assertEquals("Invalid cpuCount", azureSizeBasicA0.numberOfCores(), instanceTypeBasicA0.cpuCount);
assertEquals("Invalid dataDiskMaxCount", azureSizeBasicA0.maxDataDiskCount(), instanceTypeBasicA0.dataDiskMaxCount);
assertEquals("Invalid dataDiskSizeInMB", azureSizeBasicA0.resourceDiskSizeInMB(), instanceTypeBasicA0.dataDiskSizeInMB);
assertEquals("Invalid bootDiskSizeInMB", azureSizeBasicA0.osDiskSizeInMB(), instanceTypeBasicA0.bootDiskSizeInMB);
assertEquals("Invalid memoryInMB", azureSizeBasicA0.memoryInMB(), instanceTypeBasicA0.memoryInMB);
ctx.completeIteration();
} catch (AssertionError err) {
ctx.failIteration(err);
}
}));
testWait(ctx);
}
use of com.vmware.xenon.common.test.TestContext in project photon-model by vmware.
the class AzureLifecycleOperationServiceTest method triggerRestart.
private void triggerRestart() {
String taskLink = UUID.randomUUID().toString();
ResourceOperationRequest request = new ResourceOperationRequest();
request.isMockRequest = this.isMock;
request.operation = ResourceOperation.RESTART.operation;
request.resourceReference = UriUtils.buildUri(this.host, this.vmState.documentSelfLink);
request.taskReference = UriUtils.buildUri(this.host, taskLink);
TestContext ctx = this.host.testCreate(2);
createTaskResultListener(this.host, taskLink, (u) -> {
if (u.getAction() != Action.PATCH) {
return false;
}
ResourceOperationResponse response = u.getBody(ResourceOperationResponse.class);
if (TaskState.isFailed(response.taskInfo)) {
ctx.failIteration(new IllegalStateException(response.taskInfo.failure.message));
} else if (TaskState.isFinished(response.taskInfo)) {
ctx.completeIteration();
}
return true;
});
Operation restartOp = Operation.createPatch(UriUtils.buildUri(this.host, AzureLifecycleOperationService.SELF_LINK)).setBody(request).setReferer("/tests").setCompletion((o, e) -> {
if (e != null) {
ctx.failIteration(e);
return;
}
ctx.completeIteration();
});
this.host.send(restartOp);
ctx.await();
}
use of com.vmware.xenon.common.test.TestContext in project photon-model by vmware.
the class AzureLifecycleOperationServiceTest method triggerSuspend.
private void triggerSuspend() {
String taskLink = UUID.randomUUID().toString();
ResourceOperationRequest request = new ResourceOperationRequest();
request.isMockRequest = this.isMock;
request.operation = ResourceOperation.SUSPEND.operation;
request.resourceReference = UriUtils.buildUri(this.host, this.vmState.documentSelfLink);
request.taskReference = UriUtils.buildUri(this.host, taskLink);
TestContext ctx = this.host.testCreate(2);
createTaskResultListener(this.host, taskLink, (u) -> {
if (u.getAction() != Action.PATCH) {
return false;
}
ResourceOperationResponse response = u.getBody(ResourceOperationResponse.class);
if (TaskState.isFailed(response.taskInfo)) {
ctx.failIteration(new IllegalStateException(response.taskInfo.failure.message));
} else if (TaskState.isFinished(response.taskInfo)) {
ctx.completeIteration();
}
return true;
});
Operation restartOp = Operation.createPatch(UriUtils.buildUri(this.host, AzureLifecycleOperationService.SELF_LINK)).setBody(request).setReferer("/tests2").setCompletion((o, e) -> {
if (e != null) {
ctx.failIteration(e);
return;
}
ctx.completeIteration();
});
this.host.send(restartOp);
ctx.await();
}
use of com.vmware.xenon.common.test.TestContext in project photon-model by vmware.
the class TestAWSEnumerationTask method setUp.
@Before
public void setUp() throws Throwable {
CommandLineArgumentParser.parseFromProperties(this);
setAwsClientMockInfo(this.isAwsClientMock, this.awsMockEndpointReference);
// create credentials
AuthCredentialsServiceState creds = new AuthCredentialsServiceState();
creds.privateKey = this.secretKey;
creds.privateKeyId = this.accessKey;
TestContext ec2WaitContext = new TestContext(1, Duration.ofSeconds(30L));
AWSUtils.getEc2AsyncClient(creds, TestAWSSetupUtils.regionId, getExecutor()).exceptionally(t -> {
ec2WaitContext.fail(t);
throw new CompletionException(t);
}).thenAccept(ec2Client -> {
this.client = ec2Client;
ec2WaitContext.complete();
});
ec2WaitContext.await();
TestContext s3WaitContext = new TestContext(1, Duration.ofSeconds(30L));
AWSUtils.getS3ClientAsync(creds, TestAWSSetupUtils.regionId, getExecutor()).exceptionally(t -> {
s3WaitContext.fail(t);
throw new CompletionException(t);
}).thenAccept(ec2Client -> {
this.s3Client = ec2Client;
s3WaitContext.complete();
});
s3WaitContext.await();
if (ENABLE_LOAD_BALANCER_ENUMERATION) {
TestContext lbWaitContext = new TestContext(1, Duration.ofSeconds(30L));
AWSUtils.getAwsLoadBalancingAsyncClient(creds, TestAWSSetupUtils.regionId, getExecutor()).exceptionally(t -> {
lbWaitContext.fail(t);
throw new CompletionException(t);
}).thenAccept(ec2Client -> {
this.lbClient = ec2Client;
lbWaitContext.complete();
});
lbWaitContext.await();
}
this.awsTestContext = new HashMap<>();
setUpTestVpc(this.client, this.awsTestContext, this.isMock);
this.vpcId = (String) this.awsTestContext.get(TestAWSSetupUtils.VPC_KEY);
this.subnetId = (String) this.awsTestContext.get(TestAWSSetupUtils.SUBNET_KEY);
this.securityGroupId = (String) this.awsTestContext.get(TestAWSSetupUtils.SECURITY_GROUP_KEY);
this.singleNicSpec = (AwsNicSpecs) this.awsTestContext.get(TestAWSSetupUtils.NIC_SPECS_KEY);
try {
PhotonModelServices.startServices(this.host);
PhotonModelMetricServices.startServices(this.host);
PhotonModelTaskServices.startServices(this.host);
PhotonModelAdaptersRegistryAdapters.startServices(this.host);
AWSAdaptersTestUtils.startServicesSynchronously(this.host);
this.host.setTimeoutSeconds(this.timeoutSeconds);
this.host.waitForServiceAvailable(PhotonModelServices.LINKS);
this.host.waitForServiceAvailable(PhotonModelTaskServices.LINKS);
} catch (Throwable e) {
this.host.log("Error starting up services for the test %s", e.getMessage());
throw new Exception(e);
}
// create the compute host, resource pool and the VM state to be used in the test.
initResourcePoolAndComputeHost();
}
Aggregations