use of com.vmware.xenon.common.test.TestContext in project photon-model by vmware.
the class AWSPowerServiceTest method changePowerState.
private void changePowerState(ComputeDescription cd, String computeLink, PowerState powerState) {
String taskLink = UUID.randomUUID().toString();
ComputePowerRequest powerRequest = new ComputePowerRequest();
powerRequest.isMockRequest = this.isMock;
powerRequest.powerState = powerState;
powerRequest.resourceReference = UriUtils.buildUri(this.host, computeLink);
powerRequest.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 powerOp = Operation.createPatch(cd.powerAdapterReference).setBody(powerRequest).setReferer("/boza").setCompletion((o, e) -> {
if (e != null) {
ctx.failIteration(e);
return;
}
ctx.completeIteration();
});
this.host.send(powerOp);
ctx.await();
ComputeState compute = this.host.getServiceState(null, ComputeState.class, UriUtils.buildUri(this.host, computeLink));
assertEquals(powerState, compute.powerState);
if (PowerState.OFF.equals(powerState)) {
assertTrue(compute.address.isEmpty());
}
}
use of com.vmware.xenon.common.test.TestContext in project photon-model by vmware.
the class AWSPowerServiceTest 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 AzureLifecycleOperationServiceTest 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 BaseVSphereAdapterTest method createSnapshotAndWaitFailure.
protected void createSnapshotAndWaitFailure(ComputeState vm) throws Throwable {
String taskLink = UUID.randomUUID().toString();
ResourceOperationRequest snapshotRequest = getCreateSnapshotRequest(ResourceOperation.CREATE_SNAPSHOT.operation, vm.documentSelfLink, taskLink);
Operation createSnapshotOp = Operation.createPatch(UriUtils.buildUri(this.host, VSphereAdapterSnapshotService.SELF_LINK)).setBody(snapshotRequest).setReferer(this.host.getReferer()).setCompletion((o, e) -> Assert.assertNull(e));
TestContext ctx2 = this.host.testCreate(1);
createTaskResultListener(this.host, taskLink, (u) -> {
if (u.getAction() != Service.Action.PATCH) {
return false;
}
ResourceOperationResponse response = u.getBody(ResourceOperationResponse.class);
if (TaskState.isFailed(response.taskInfo)) {
ctx2.completeIteration();
return true;
} else {
ctx2.completeIteration();
return false;
}
});
this.host.send(createSnapshotOp);
ctx2.await();
}
use of com.vmware.xenon.common.test.TestContext in project photon-model by vmware.
the class BaseVSphereAdapterTest method resetVSphereVM.
protected void resetVSphereVM(ComputeState computeState) {
String taskLink = UUID.randomUUID().toString();
ResourceOperationRequest resetVMRequest = getResourceOperationRequest("Reset", computeState.documentSelfLink, taskLink);
TestContext ctx = this.host.testCreate(1);
createTaskResultListener(this.host, taskLink, (u) -> {
if (u.getAction() != Service.Action.PATCH) {
return false;
}
ResourceOperationResponse response = u.getBody(ResourceOperationResponse.class);
if (TaskState.isFailed(response.taskInfo)) {
ctx.failIteration(new IllegalStateException(response.taskInfo.failure.message));
} else {
ctx.completeIteration();
}
return true;
});
TestContext ctx2 = this.host.testCreate(1);
Operation resetOp = Operation.createPatch(UriUtils.buildUri(this.host, VSphereAdapterD2PowerOpsService.SELF_LINK)).setBody(resetVMRequest).setReferer(this.host.getReferer()).setCompletion((o, e) -> {
if (e != null) {
ctx2.failIteration(e);
return;
}
ctx2.completeIteration();
});
this.host.send(resetOp);
ctx2.await();
ComputeState[] cState = new ComputeState[1];
this.host.waitFor("Reset VM request failed", () -> {
cState[0] = this.host.getServiceState(null, ComputeState.class, UriUtils.buildUri(this.host, computeState.documentSelfLink));
if (ComputeService.PowerState.ON.equals(cState[0].powerState)) {
return true;
} else {
return false;
}
});
assertEquals(ComputeService.PowerState.ON, cState[0].powerState);
}
Aggregations