use of ui.ex1.entity in project nomulus by google.
the class BulkDeleteDatastorePipelineTest method splitEntitiesByKind.
@Test
void splitEntitiesByKind() {
TupleTagList tags = getDeletionTags(2);
PCollection<String> kinds = testPipeline.apply("InjectKinds", Create.of("A", "B"));
PCollectionView<Map<String, TupleTag<Entity>>> kindToTagMapping = BulkDeleteDatastorePipeline.mapKindsToDeletionTags(kinds, tags).apply(View.asMap());
Entity entityA = createTestEntity("A", 1);
Entity entityB = createTestEntity("B", 2);
PCollection<Entity> entities = testPipeline.apply("InjectEntities", Create.of(entityA, entityB));
PCollectionTuple allCollections = entities.apply("SplitByKind", ParDo.of(new SplitEntities(kindToTagMapping)).withSideInputs(kindToTagMapping).withOutputTags(getOneDeletionTag("placeholder"), tags));
PAssert.that(allCollections.get((TupleTag<Entity>) tags.get(0))).containsInAnyOrder(entityA);
PAssert.that(allCollections.get((TupleTag<Entity>) tags.get(1))).containsInAnyOrder(entityB);
testPipeline.run();
}
use of ui.ex1.entity in project nomulus by google.
the class BulkDeleteDatastorePipelineTest method mapKindsToTags_fewerKindsThanTags.
@Test
void mapKindsToTags_fewerKindsThanTags() {
TupleTagList tags = getDeletionTags(3);
PCollection<String> kinds = testPipeline.apply("InjectKinds", Create.of("A", "B"));
PCollection<KV<String, TupleTag<Entity>>> kindToTagMapping = BulkDeleteDatastorePipeline.mapKindsToDeletionTags(kinds, tags);
PAssert.thatMap(kindToTagMapping).isEqualTo(ImmutableMap.of("A", new TupleTag<Entity>("0"), "B", new TupleTag<Entity>("1")));
testPipeline.run();
}
use of ui.ex1.entity in project nomulus by google.
the class BulkDeleteDatastorePipelineTest method mapKindsToTags.
@Test
void mapKindsToTags() {
TupleTagList tags = getDeletionTags(2);
PCollection<String> kinds = testPipeline.apply("InjectKinds", Create.of("A", "B"));
PCollection<KV<String, TupleTag<Entity>>> kindToTagMapping = BulkDeleteDatastorePipeline.mapKindsToDeletionTags(kinds, tags);
PAssert.thatMap(kindToTagMapping).isEqualTo(ImmutableMap.of("A", new TupleTag<Entity>("0"), "B", new TupleTag<Entity>("1")));
testPipeline.run();
}
use of ui.ex1.entity in project nomulus by google.
the class BulkDeleteDatastorePipelineTest method mapKindsToTags_moreKindsThanTags.
@Test
void mapKindsToTags_moreKindsThanTags() {
TupleTagList tags = getDeletionTags(2);
PCollection<String> kinds = testPipeline.apply("InjectKinds", Create.of("A", "B", "C"));
PCollection<KV<String, TupleTag<Entity>>> kindToTagMapping = BulkDeleteDatastorePipeline.mapKindsToDeletionTags(kinds, tags);
PAssert.thatMap(kindToTagMapping).isEqualTo(ImmutableMap.of("A", new TupleTag<Entity>("0"), "B", new TupleTag<Entity>("1"), "C", new TupleTag<Entity>("0")));
testPipeline.run();
}
use of ui.ex1.entity in project DataflowTemplates by GoogleCloudPlatform.
the class BigQueryConvertersTest method testAvroToEntityInvalidTimestampField.
/**
* Tests that {@link BigQueryConverters.AvroToEntity} creates an Entity without a valid key when a
* Timestamp field is invalid.
*/
@Test
public void testAvroToEntityInvalidTimestampField() throws Exception {
// Create test data
List<TableFieldSchema> fields = new ArrayList<>();
fields.add(new TableFieldSchema().setName(idField).setType("STRING"));
fields.add(new TableFieldSchema().setName(invalidTimestampField).setType("TIMESTAMP"));
TableSchema bqSchema = new TableSchema().setFields(fields);
Schema avroSchema = new Schema.Parser().parse(String.format(avroSchemaTemplate, new StringBuilder().append(String.format(avroFieldTemplate, idField, "string", idFieldDesc)).append(",").append(String.format(avroFieldTemplate, invalidTimestampField, "long", invalidTimestampFieldDesc)).toString()));
GenericRecordBuilder builder = new GenericRecordBuilder(avroSchema);
builder.set(idField, idFieldValueStr);
builder.set(invalidTimestampField, invalidTimestampFieldValueNanos);
Record record = builder.build();
SchemaAndRecord inputBqData = new SchemaAndRecord(record, bqSchema);
// Run the test
Entity outputEntity = converter.apply(inputBqData);
// Assess results
assertTrue(!outputEntity.hasKey());
assertTrue(outputEntity.getPropertiesMap().get("cause").getStringValue().startsWith("Timestamp is not valid"));
assertEquals(record.toString(), outputEntity.getPropertiesMap().get("row").getStringValue());
}
Aggregations