use of com.vmware.xenon.common.test.TestContext in project photon-model by vmware.
the class TestVSphereLinkedCloneProvisionTask method sendOperationSynchronously.
private Operation sendOperationSynchronously(Operation op) throws Throwable {
final Operation[] returnedOp = { null };
TestContext ctx = this.host.testCreate(1);
op.setCompletion((operation, throwable) -> {
returnedOp[0] = operation;
if (throwable != null) {
ctx.failIteration(throwable);
} else {
ctx.completeIteration();
}
});
this.host.send(op);
this.host.testWait(ctx);
return returnedOp[0];
}
use of com.vmware.xenon.common.test.TestContext in project photon-model by vmware.
the class ResourcePoolQueryHelperTest method runHelperSynchronously.
/**
* Synchronously executes the given ResourcePoolQueryHelper instance.
*/
private static ResourcePoolQueryHelper.QueryResult runHelperSynchronously(VerificationHost host, ResourcePoolQueryHelper helper) {
ResourcePoolQueryHelper.QueryResult[] resultHolder = { null };
TestContext ctx = host.testCreate(1);
helper.query(qr -> {
if (qr.error != null) {
ctx.failIteration(qr.error);
return;
}
resultHolder[0] = qr;
ctx.completeIteration();
});
host.testWait(ctx);
return resultHolder[0];
}
use of com.vmware.xenon.common.test.TestContext in project photon-model by vmware.
the class BaseModelTest method getServiceSynchronously.
public <T extends ServiceDocument> T getServiceSynchronously(String serviceUri, Class<T> type, Class<? extends Throwable> expectedException) throws Throwable {
AtomicReference<T> responseBody = new AtomicReference<>();
TestContext ctx = this.host.testCreate(1);
Operation getOperation = Operation.createGet(UriUtils.buildUri(this.host, serviceUri)).setCompletion((operation, throwable) -> {
boolean failureExpected = (expectedException != null);
boolean failureReturned = (throwable != null);
if (failureExpected ^ failureReturned) {
Throwable t = throwable == null ? new IllegalArgumentException("Call did not fail as expected") : throwable;
ctx.failIteration(t);
return;
}
if (failureExpected && expectedException != throwable.getClass()) {
ctx.failIteration(throwable);
return;
}
if (!failureExpected) {
responseBody.set(operation.getBody(type));
}
ctx.completeIteration();
});
this.send(getOperation);
this.testWait(ctx);
return responseBody.get();
}
use of com.vmware.xenon.common.test.TestContext in project photon-model by vmware.
the class BaseModelTest method patchServiceSynchronously.
public <T> T patchServiceSynchronously(String serviceUri, T patchBody, Class<T> type) throws Throwable {
AtomicReference<T> responseObj = new AtomicReference<>();
TestContext ctx = this.host.testCreate(1);
Operation patchOperation = Operation.createPatch(UriUtils.buildUri(this.host, serviceUri)).setBody(patchBody).setCompletion((operation, throwable) -> {
if (throwable != null) {
ctx.failIteration(throwable);
} else {
responseObj.set(operation.getBody(type));
ctx.completeIteration();
}
});
this.host.send(patchOperation);
this.host.testWait(ctx);
return responseObj.get();
}
use of com.vmware.xenon.common.test.TestContext in project photon-model by vmware.
the class BaseModelTest method patchServiceSynchronously.
public <T> void patchServiceSynchronously(String serviceUri, T patchBody) throws Throwable {
TestContext ctx = this.host.testCreate(1);
Operation patchOperation = Operation.createPatch(UriUtils.buildUri(this.host, serviceUri)).setBody(patchBody).setCompletion(ctx.getCompletion());
this.host.send(patchOperation);
this.host.testWait(ctx);
}
Aggregations