Search in sources :

Example 6 with TestContext

use of com.vmware.xenon.common.test.TestContext in project photon-model by vmware.

the class BaseTestCase method getDocument.

@SuppressWarnings("unchecked")
protected <T> T getDocument(Class<T> type, URI uri) throws Throwable {
    TestContext ctx = testCreate(1);
    Object[] result = new Object[1];
    Operation get = Operation.createGet(uri).addPragmaDirective(Operation.PRAGMA_DIRECTIVE_QUEUE_FOR_SERVICE_AVAILABILITY).setReferer(this.host.getReferer()).setCompletion((o, e) -> {
        if (e != null) {
            this.host.log("Can't load document %s. Error: %s", uri, Utils.toString(e));
            ctx.failIteration(e);
        } else {
            result[0] = o.getBody(type);
            ctx.completeIteration();
        }
    });
    this.host.send(get);
    ctx.await();
    return (T) result[0];
}
Also used : TestContext(com.vmware.xenon.common.test.TestContext) Operation(com.vmware.xenon.common.Operation)

Example 7 with TestContext

use of com.vmware.xenon.common.test.TestContext in project photon-model by vmware.

the class BaseModelTest method patchServiceSynchronously.

public <T extends ServiceDocument> int patchServiceSynchronously(String serviceUri, ComputeInstanceRequest 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.testWait(ctx);
    return patchOperation.getStatusCode();
}
Also used : TestContext(com.vmware.xenon.common.test.TestContext) Operation(com.vmware.xenon.common.Operation)

Example 8 with TestContext

use of com.vmware.xenon.common.test.TestContext in project photon-model by vmware.

the class BaseModelTest method waitForServiceAvailability.

protected void waitForServiceAvailability(ServiceHost h, String... serviceLinks) throws Throwable {
    if (serviceLinks == null || serviceLinks.length == 0) {
        throw new IllegalArgumentException("null or empty serviceLinks");
    }
    TestContext ctx = testCreate(serviceLinks.length);
    h.registerForServiceAvailability(ctx.getCompletion(), serviceLinks);
    ctx.await();
}
Also used : TestContext(com.vmware.xenon.common.test.TestContext)

Example 9 with TestContext

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) throws Throwable {
    AtomicReference<T> responseBody = new AtomicReference<>();
    TestContext ctx = this.host.testCreate(1);
    Operation getOperation = Operation.createGet(UriUtils.buildUri(this.host, serviceUri)).addPragmaDirective(Operation.PRAGMA_DIRECTIVE_QUEUE_FOR_SERVICE_AVAILABILITY).setCompletion((operation, throwable) -> {
        if (throwable != null) {
            ctx.failIteration(throwable);
            return;
        }
        responseBody.set(operation.getBody(type));
        ctx.completeIteration();
    });
    this.send(getOperation);
    this.testWait(ctx);
    return responseBody.get();
}
Also used : TestContext(com.vmware.xenon.common.test.TestContext) AtomicReference(java.util.concurrent.atomic.AtomicReference) Operation(com.vmware.xenon.common.Operation)

Example 10 with TestContext

use of com.vmware.xenon.common.test.TestContext in project photon-model by vmware.

the class BaseModelTest method deleteServiceSynchronously.

private <T extends ServiceDocument> void deleteServiceSynchronously(String serviceUri, boolean stopOnly) throws Throwable {
    TestContext ctx = this.host.testCreate(1);
    Operation deleteOperation = Operation.createDelete(UriUtils.buildUri(this.host, serviceUri)).setCompletion((operation, throwable) -> {
        if (throwable != null) {
            ctx.failIteration(throwable);
        }
        ctx.completeIteration();
    });
    if (stopOnly) {
        deleteOperation.addPragmaDirective(Operation.PRAGMA_DIRECTIVE_NO_INDEX_UPDATE);
    }
    this.send(deleteOperation);
    this.testWait(ctx);
}
Also used : TestContext(com.vmware.xenon.common.test.TestContext) Operation(com.vmware.xenon.common.Operation)

Aggregations

TestContext (com.vmware.xenon.common.test.TestContext)43 Operation (com.vmware.xenon.common.Operation)37 Test (org.junit.Test)18 ResourceOperationResponse (com.vmware.photon.controller.model.adapterapi.ResourceOperationResponse)14 UriUtils (com.vmware.xenon.common.UriUtils)13 AuthCredentialsServiceState (com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState)13 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)12 After (org.junit.After)12 Assert.assertEquals (org.junit.Assert.assertEquals)12 Before (org.junit.Before)12 CompletionException (java.util.concurrent.CompletionException)11 AmazonEC2AsyncClient (com.amazonaws.services.ec2.AmazonEC2AsyncClient)10 ResourceOperation (com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperation)10 ResourceOperationRequest (com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationRequest)10 CommandLineArgumentParser (com.vmware.xenon.common.CommandLineArgumentParser)10 ArrayList (java.util.ArrayList)10 List (java.util.List)10 Duration (java.time.Duration)9 HashMap (java.util.HashMap)9 Level (java.util.logging.Level)9