use of com.vmware.xenon.common.test.VerificationHost in project photon-model by vmware.
the class BaseTestCase method createHost.
protected VerificationHost createHost() throws Throwable {
ServiceHost.Arguments args = new ServiceHost.Arguments();
// ask runtime to pick a random storage location
args.sandbox = null;
// ask runtime to pick a random port
args.port = 0;
Map<Class<? extends Service>, Class<? extends OperationProcessingChain>> chains = new HashMap<>();
customizeChains(chains);
VerificationHost h = VerificationHost.initialize(new CustomizationVerificationHost(chains), args);
h.setMaintenanceIntervalMicros(this.getMaintenanceIntervalMillis() * 1000);
h.setTimeoutSeconds(HOST_TIMEOUT_SECONDS);
h.setPeerSynchronizationEnabled(this.getPeerSynchronizationEnabled());
h.start();
return h;
}
use of com.vmware.xenon.common.test.VerificationHost in project photon-model by vmware.
the class StatsAggregationTaskServiceTest method setupMetricHost.
private VerificationHost setupMetricHost() throws Throwable {
// Start a metric Host separately.
VerificationHost metricHost = VerificationHost.create(0);
metricHost.start();
ServiceTypeCluster.METRIC_SERVICE.setUri(metricHost.getUri().toString());
PhotonModelMetricServices.startServices(metricHost);
return metricHost;
}
use of com.vmware.xenon.common.test.VerificationHost in project photon-model by vmware.
the class StatsAggregationTaskServiceTest method testStatsAggregation.
private void testStatsAggregation(boolean testOnCluster) throws Throwable {
VerificationHost metricHost = null;
if (testOnCluster) {
metricHost = this.setupMetricHost();
}
// Use this.host if metricHost is null.
VerificationHost verificationHost = (metricHost == null ? this.host : metricHost);
// create a resource pool
ResourcePoolState rpState = new ResourcePoolState();
rpState.name = "testName";
ResourcePoolState rpReturnState = postServiceSynchronously(ResourcePoolService.FACTORY_LINK, rpState, ResourcePoolState.class);
ComputeDescription cDesc = new ComputeDescription();
cDesc.name = rpState.name;
cDesc.statsAdapterReference = UriUtils.buildUri(this.host, MockStatsAdapter.SELF_LINK);
ComputeDescription descReturnState = postServiceSynchronously(ComputeDescriptionService.FACTORY_LINK, cDesc, ComputeDescription.class);
ComputeState computeState = new ComputeState();
computeState.name = rpState.name;
computeState.descriptionLink = descReturnState.documentSelfLink;
computeState.resourcePoolLink = rpReturnState.documentSelfLink;
List<String> computeLinks = new ArrayList<>();
for (int i = 0; i < this.numResources; i++) {
ComputeState res = postServiceSynchronously(ComputeService.FACTORY_LINK, computeState, ComputeState.class);
computeLinks.add(res.documentSelfLink);
}
// kick off an aggregation task when stats are not populated
StatsAggregationTaskState aggregationTaskState = new StatsAggregationTaskState();
Query taskQuery = Query.Builder.create().addFieldClause(ComputeState.FIELD_NAME_RESOURCE_POOL_LINK, rpReturnState.documentSelfLink).build();
aggregationTaskState.query = taskQuery;
aggregationTaskState.metricNames = Collections.singleton(MockStatsAdapter.KEY_1);
aggregationTaskState.taskInfo = TaskState.createDirect();
postServiceSynchronously(StatsAggregationTaskService.FACTORY_LINK, aggregationTaskState, StatsAggregationTaskState.class);
this.host.waitFor("Error waiting for stats", () -> {
ServiceDocumentQueryResult aggrRes = verificationHost.getFactoryState(UriUtils.buildUri(verificationHost, ResourceMetricsService.FACTORY_LINK));
// Expect 0 stats because they're not collected yet
if (aggrRes.documentCount == 0) {
return true;
}
return false;
});
StatsCollectionTaskState collectionTaskState = new StatsCollectionTaskState();
collectionTaskState.resourcePoolLink = rpReturnState.documentSelfLink;
collectionTaskState.taskInfo = TaskState.createDirect();
postServiceSynchronously(StatsCollectionTaskService.FACTORY_LINK, collectionTaskState, StatsCollectionTaskState.class);
int numberOfRawMetrics = this.numResources * 4;
// kick off an aggregation task
aggregationTaskState = new StatsAggregationTaskState();
aggregationTaskState.query = taskQuery;
aggregationTaskState.metricNames = Collections.singleton(MockStatsAdapter.KEY_1);
aggregationTaskState.taskInfo = TaskState.createDirect();
postServiceSynchronously(StatsAggregationTaskService.FACTORY_LINK, aggregationTaskState, StatsAggregationTaskState.class);
this.host.waitFor("Error waiting for stats", () -> {
ServiceDocumentQueryResult aggrRes = verificationHost.getFactoryState(UriUtils.buildUri(verificationHost, ResourceMetricsService.FACTORY_LINK));
if (aggrRes.documentCount == this.numResources + numberOfRawMetrics) {
return true;
}
return false;
});
// verify that the aggregation tasks have been deleted
this.host.waitFor("Timeout waiting for task to expire", () -> {
ServiceDocumentQueryResult res = this.host.getFactoryState(UriUtils.buildUri(this.host, StatsAggregationTaskService.FACTORY_LINK));
if (res.documentLinks.size() == 0) {
return true;
}
return false;
});
if (testOnCluster) {
this.cleanUpMetricHost(metricHost);
}
}
use of com.vmware.xenon.common.test.VerificationHost in project photon-model by vmware.
the class StatsCollectionTaskServiceTest method setupMetricHost.
private VerificationHost setupMetricHost() throws Throwable {
// Start a metric Host separately.
VerificationHost metricHost = VerificationHost.create(0);
metricHost.start();
ServiceTypeCluster.METRIC_SERVICE.setUri(metricHost.getUri().toString());
PhotonModelMetricServices.startServices(metricHost);
return metricHost;
}
use of com.vmware.xenon.common.test.VerificationHost 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();
}
Aggregations