Search in sources :

Example 1 with TestDataLayoutHint

use of org.apache.beam.sdk.io.gcp.firestore.it.FirestoreTestingHelper.TestDataLayoutHint in project beam by apache.

the class BaseFirestoreIT method listCollections.

@Test
@TestDataLayoutHint(DataLayout.Deep)
public final void listCollections() throws Exception {
    // verification and cleanup of nested collections is much slower because each document
    // requires an rpc to find its collections, instead of using the usual size, use 20
    // to keep the test quick
    List<String> collectionIds = IntStream.rangeClosed(1, 20).mapToObj(i -> helper.colId()).collect(Collectors.toList());
    ApiFutures.transform(ApiFutures.allAsList(chunkUpDocIds(collectionIds).map(chunk -> {
        WriteBatch batch = helper.getFs().batch();
        chunk.stream().map(col -> helper.getBaseDocument().collection(col).document()).forEach(ref -> batch.set(ref, ImmutableMap.of("foo", "bar")));
        return batch.commit();
    }).collect(Collectors.toList())), FirestoreTestingHelper.flattenListList(), MoreExecutors.directExecutor()).get(10, TimeUnit.SECONDS);
    PCollection<String> actualCollectionIds = testPipeline.apply(Create.of("")).apply(getListCollectionIdsPTransform(testName.getMethodName())).apply(FirestoreIO.v1().read().listCollectionIds().withRpcQosOptions(rpcQosOptions).build());
    PAssert.that(actualCollectionIds).containsInAnyOrder(collectionIds);
    testPipeline.run(options);
}
Also used : IntStream(java.util.stream.IntStream) BatchGetDocumentsResponse(com.google.firestore.v1.BatchGetDocumentsResponse) Assume.assumeThat(org.junit.Assume.assumeThat) RunQueryRequest(com.google.firestore.v1.RunQueryRequest) Write(com.google.firestore.v1.Write) BeforeClass(org.junit.BeforeClass) TestDataLayoutHint(org.apache.beam.sdk.io.gcp.firestore.it.FirestoreTestingHelper.TestDataLayoutHint) CleanupMode(org.apache.beam.sdk.io.gcp.firestore.it.FirestoreTestingHelper.CleanupMode) ImmutableMap(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableMap) BatchGetDocumentsRequest(com.google.firestore.v1.BatchGetDocumentsRequest) PTransform(org.apache.beam.sdk.transforms.PTransform) DocumentGenerator(org.apache.beam.sdk.io.gcp.firestore.it.FirestoreTestingHelper.DocumentGenerator) Create(org.apache.beam.sdk.transforms.Create) TestName(org.junit.rules.TestName) TestPipeline(org.apache.beam.sdk.testing.TestPipeline) FirestoreOptions(org.apache.beam.sdk.io.gcp.firestore.FirestoreOptions) Timeout(org.junit.rules.Timeout) ListCollectionIdsRequest(com.google.firestore.v1.ListCollectionIdsRequest) FirestoreTestingHelper.assumeEnvVarSet(org.apache.beam.sdk.io.gcp.firestore.it.FirestoreTestingHelper.assumeEnvVarSet) FirestoreTestingHelper.chunkUpDocIds(org.apache.beam.sdk.io.gcp.firestore.it.FirestoreTestingHelper.chunkUpDocIds) Before(org.junit.Before) DoFn(org.apache.beam.sdk.transforms.DoFn) AssumptionViolatedException(org.junit.AssumptionViolatedException) MoreExecutors(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.util.concurrent.MoreExecutors) ApiFutures(com.google.api.core.ApiFutures) GcpOptions(org.apache.beam.sdk.extensions.gcp.options.GcpOptions) PAssert(org.apache.beam.sdk.testing.PAssert) Document(com.google.firestore.v1.Document) Test(org.junit.Test) UUID(java.util.UUID) PCollection(org.apache.beam.sdk.values.PCollection) Collectors(java.util.stream.Collectors) FirestoreIO(org.apache.beam.sdk.io.gcp.firestore.FirestoreIO) TimeUnit(java.util.concurrent.TimeUnit) ListDocumentsRequest(com.google.firestore.v1.ListDocumentsRequest) WriteBatch(com.google.cloud.firestore.WriteBatch) List(java.util.List) Rule(org.junit.Rule) Filter(org.apache.beam.sdk.transforms.Filter) ParDo(org.apache.beam.sdk.transforms.ParDo) DataLayout(org.apache.beam.sdk.io.gcp.firestore.it.FirestoreTestingHelper.DataLayout) Matchers.equalTo(org.hamcrest.Matchers.equalTo) RpcQosOptions(org.apache.beam.sdk.io.gcp.firestore.RpcQosOptions) RunQueryResponse(com.google.firestore.v1.RunQueryResponse) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) PartitionQueryRequest(com.google.firestore.v1.PartitionQueryRequest) WriteBatch(com.google.cloud.firestore.WriteBatch) Test(org.junit.Test) TestDataLayoutHint(org.apache.beam.sdk.io.gcp.firestore.it.FirestoreTestingHelper.TestDataLayoutHint)

Aggregations

ApiFutures (com.google.api.core.ApiFutures)1 WriteBatch (com.google.cloud.firestore.WriteBatch)1 BatchGetDocumentsRequest (com.google.firestore.v1.BatchGetDocumentsRequest)1 BatchGetDocumentsResponse (com.google.firestore.v1.BatchGetDocumentsResponse)1 Document (com.google.firestore.v1.Document)1 ListCollectionIdsRequest (com.google.firestore.v1.ListCollectionIdsRequest)1 ListDocumentsRequest (com.google.firestore.v1.ListDocumentsRequest)1 PartitionQueryRequest (com.google.firestore.v1.PartitionQueryRequest)1 RunQueryRequest (com.google.firestore.v1.RunQueryRequest)1 RunQueryResponse (com.google.firestore.v1.RunQueryResponse)1 Write (com.google.firestore.v1.Write)1 Collections (java.util.Collections)1 List (java.util.List)1 UUID (java.util.UUID)1 TimeUnit (java.util.concurrent.TimeUnit)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1 GcpOptions (org.apache.beam.sdk.extensions.gcp.options.GcpOptions)1 FirestoreIO (org.apache.beam.sdk.io.gcp.firestore.FirestoreIO)1 FirestoreOptions (org.apache.beam.sdk.io.gcp.firestore.FirestoreOptions)1