use of com.vmware.photon.controller.model.query.QueryUtils.QueryByPages in project photon-model by vmware.
the class TestAzureImageEnumerationTask method testPublicImageEnumeration_multi.
@Test
public void testPublicImageEnumeration_multi() throws Throwable {
Assume.assumeFalse(this.isMock);
// This test takes about less than 2 mins!
getHost().setTimeoutSeconds((int) TimeUnit.MINUTES.toSeconds(2));
ImageEnumerationTaskState task = kickOffImageEnumeration(this.endpointState, PUBLIC, AZURE_MULTI_IMAGES_FILTER);
// Validate at least 200+ image states are created.
QueryByPages<ImageState> queryAll = new QueryByPages<ImageState>(getHost(), Builder.create().addKindFieldClause(ImageState.class).build(), ImageState.class, task.tenantLinks);
queryAll.setMaxPageSize(QueryUtils.DEFAULT_MAX_RESULT_LIMIT);
Long imagesCount = PhotonModelUtils.waitToComplete(queryAll.collectLinks(Collectors.counting()));
Assert.assertTrue("Expected at least " + 200 + " images, but found only " + imagesCount, imagesCount > 200);
}
use of com.vmware.photon.controller.model.query.QueryUtils.QueryByPages in project photon-model by vmware.
the class TestAzureImageEnumerationTask method afterImageEnumTest.
@After
public final void afterImageEnumTest() throws Throwable {
QueryByPages<ImageState> queryAll = new QueryByPages<ImageState>(getHost(), Builder.create().addKindFieldClause(ImageState.class).build(), ImageState.class, null);
queryAll.setMaxPageSize(QueryUtils.DEFAULT_MAX_RESULT_LIMIT);
AtomicInteger counter = new AtomicInteger(0);
PhotonModelUtils.waitToComplete(queryAll.queryLinks(imageLink -> {
try {
deleteServiceSynchronously(imageLink);
counter.incrementAndGet();
} catch (Throwable e) {
throw new RuntimeException(e);
}
}));
getHost().log(Level.INFO, "[" + this.currentTestName.getMethodName() + "] Deleted " + counter + " ImageStates");
}
use of com.vmware.photon.controller.model.query.QueryUtils.QueryByPages in project photon-model by vmware.
the class QueryUtilsTest method testQueryReferrers_error.
@Test
public void testQueryReferrers_error() throws Throwable {
ComputeDescription cd = ModelUtils.createComputeDescription(this, null, null);
ModelUtils.createCompute(this, cd);
ModelUtils.createCompute(this, cd);
Query queryForReferrers = QueryUtils.queryForReferrers(cd.documentSelfLink, ComputeState.class, ComputeState.FIELD_NAME_DESCRIPTION_LINK);
// The class under testing
QueryStrategy<ComputeState> queryStrategy = new QueryByPages<>(getHost(), queryForReferrers, ComputeState.class, Collections.emptyList(), null);
Set<String> actual = new HashSet<>();
// The method under testing
waitToComplete(queryStrategy.queryDocuments(cs -> {
if (actual.isEmpty()) {
actual.add(cs.documentSelfLink);
} else {
throw new RuntimeException("consume error");
}
}).handle((v, e) -> {
// Validate processed docs
assertThat(actual.size(), equalTo(1));
// Validate exception propagation
assertThat(e, notNullValue());
assertThat(e, instanceOf(CompletionException.class));
assertThat(e.getCause().getMessage(), equalTo("consume error"));
// Recover from exception to prevent its propagation to outer test method
return (Void) null;
}));
}
use of com.vmware.photon.controller.model.query.QueryUtils.QueryByPages in project photon-model by vmware.
the class TestAWSImageEnumerationTask method testPublicImageEnumeration_all.
@Test
public void testPublicImageEnumeration_all() throws Throwable {
Assume.assumeFalse(this.isMock);
Assume.assumeTrue(this.enableLongRunning);
getHost().setTimeoutSeconds((int) TimeUnit.MINUTES.toSeconds(10));
// Important: MUST share same Endpoint between the two enum runs.
final EndpointState endpointState = createEndpointState();
ImageEnumerationTaskState task = kickOffImageEnumeration(endpointState, PUBLIC, AMAZON_PUBLIC_IMAGE_FILTER_ALL);
// Validate at least 10K image states are created
// NOTE: do not use queryDocumentsAndAssertExpectedCount
// since it fails with 'Query returned large number of results'
QueryByPages<ImageState> queryAll = new QueryByPages<ImageState>(getHost(), Builder.create().addKindFieldClause(ImageState.class).build(), ImageState.class, task.tenantLinks);
queryAll.setMaxPageSize(QueryUtils.DEFAULT_MAX_RESULT_LIMIT);
Long imagesCount = waitToComplete(queryAll.collectLinks(Collectors.counting()));
Assert.assertTrue("Expected at least " + AMAZON_PUBLIC_IMAGES_ALL_COUNT + " images, but found only " + imagesCount, imagesCount > AMAZON_PUBLIC_IMAGES_ALL_COUNT);
}
use of com.vmware.photon.controller.model.query.QueryUtils.QueryByPages in project photon-model by vmware.
the class AzureNetworkEnumerationAdapterService method queryNetworkStates.
/**
* Query network states stored in the local document store based on the retrieved azure virtual
* networks.
*/
private void queryNetworkStates(NetworkEnumContext context, NetworkEnumStages next) {
logFine(() -> "Query Network States from local document store.");
Query.Builder qBuilder = Query.Builder.create().addKindFieldClause(NetworkState.class).addInClause(NetworkState.FIELD_NAME_ID, context.virtualNetworks.keySet());
QueryByPages<NetworkState> queryLocalStates = new QueryByPages<>(getHost(), qBuilder.build(), NetworkState.class, context.parentCompute.tenantLinks, null, /* endpoint */
context.parentCompute.documentSelfLink).setMaxPageSize(QueryUtils.MAX_RESULT_LIMIT).setClusterType(ServiceTypeCluster.INVENTORY_SERVICE);
queryLocalStates.queryDocuments(network -> context.networkStates.put(network.id, network)).whenComplete(thenHandleSubStage(context, next));
}
Aggregations