Search in sources :

Example 86 with ui.ex1.entity

use of ui.ex1.entity in project DataflowTemplates by GoogleCloudPlatform.

the class BigQueryConvertersTest method testAvroToEntityStringIdColumn.

/**
 * Tests that {@link BigQueryConverters.AvroToEntity} creates an Entity with a valid key when the
 * unique name column is string.
 */
@Test
public void testAvroToEntityStringIdColumn() throws Exception {
    // Create test data
    List<TableFieldSchema> fields = new ArrayList<>();
    fields.add(new TableFieldSchema().setName(idField).setType("STRING"));
    fields.add(new TableFieldSchema().setName(shortStringField).setType("STRING"));
    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(generateShortStringField()).toString()));
    GenericRecordBuilder builder = new GenericRecordBuilder(avroSchema);
    builder.set(idField, idFieldValueStr);
    builder.set(shortStringField, shortStringFieldValue);
    Record record = builder.build();
    SchemaAndRecord inputBqData = new SchemaAndRecord(record, bqSchema);
    // Run the test
    Entity outputEntity = converter.apply(inputBqData);
    assertTrue(outputEntity.hasKey());
    assertEquals(idFieldValueStr, outputEntity.getKey().getPath(0).getName());
    validateMetadata(outputEntity);
}
Also used : Entity(com.google.datastore.v1.Entity) AvroToEntity(com.google.cloud.teleport.templates.common.BigQueryConverters.AvroToEntity) TableSchema(com.google.api.services.bigquery.model.TableSchema) TableSchema(com.google.api.services.bigquery.model.TableSchema) Schema(org.apache.avro.Schema) TableFieldSchema(com.google.api.services.bigquery.model.TableFieldSchema) ArrayList(java.util.ArrayList) GenericRecordBuilder(org.apache.avro.generic.GenericRecordBuilder) Record(org.apache.avro.generic.GenericData.Record) SchemaAndRecord(org.apache.beam.sdk.io.gcp.bigquery.SchemaAndRecord) TableFieldSchema(com.google.api.services.bigquery.model.TableFieldSchema) SchemaAndRecord(org.apache.beam.sdk.io.gcp.bigquery.SchemaAndRecord) Test(org.junit.Test)

Example 87 with ui.ex1.entity

use of ui.ex1.entity in project DataflowTemplates by GoogleCloudPlatform.

the class DatastoreConvertersTest method testCheckSameKey.

/**
 * Unit test for {@link DatastoreConverters.CheckSameKey}.
 */
@Test
@Category(NeedsRunner.class)
public void testCheckSameKey() throws Exception {
    Entity dupKeyEntity = Entity.newBuilder().setKey(entities.get(0).getKey()).putProperties("SomeBSProp", Value.newBuilder().setStringValue("Some BS Value").build()).build();
    // copy all entities
    ArrayList<Entity> testEntitiesWithConflictKey = new ArrayList<>(entities);
    // Add the duplicate entity at the end of the list
    testEntitiesWithConflictKey.add(dupKeyEntity);
    List<String> expectedErrors = new ArrayList<>();
    EntityJsonPrinter entityJsonPrinter = new EntityJsonPrinter();
    for (Entity e : Arrays.asList(entities.get(0), dupKeyEntity)) {
        expectedErrors.add(ErrorMessage.newBuilder().setMessage("Duplicate Datastore Key").setData(entityJsonPrinter.print(e)).build().toJson());
    }
    TupleTag<Entity> goodTag = new TupleTag<Entity>("entities") {
    };
    TupleTag<String> errorTag = new TupleTag<String>("errors") {
    };
    PCollectionTuple results = pipeline.apply("Create", Create.of(testEntitiesWithConflictKey)).apply("RemoveDupKeys", CheckSameKey.newBuilder().setGoodTag(goodTag).setErrorTag(errorTag).build());
    PAssert.that(results.get(goodTag)).containsInAnyOrder(entities.subList(1, entities.size()));
    PAssert.that(results.get(errorTag)).containsInAnyOrder(expectedErrors);
    pipeline.run();
}
Also used : JsonToEntity(com.google.cloud.teleport.templates.common.DatastoreConverters.JsonToEntity) Entity(com.google.datastore.v1.Entity) EntityJsonPrinter(com.google.cloud.teleport.templates.common.DatastoreConverters.EntityJsonPrinter) ArrayList(java.util.ArrayList) TupleTag(org.apache.beam.sdk.values.TupleTag) PCollectionTuple(org.apache.beam.sdk.values.PCollectionTuple) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Example 88 with ui.ex1.entity

use of ui.ex1.entity in project DataflowTemplates by GoogleCloudPlatform.

the class DatastoreConvertersTest method testCheckNoKeyAllInvalid.

/**
 * Test {@link DatastoreConverters.CheckNoKey} with only invalid entities.
 */
@Test
@Category(NeedsRunner.class)
public void testCheckNoKeyAllInvalid() throws Exception {
    // Create test data
    List<Entity> testEntitiesWithNoKey = new ArrayList<>();
    List<String> expectedErrors = new ArrayList<>();
    EntityJsonPrinter entityJsonPrinter = new EntityJsonPrinter();
    for (int i = 0; i < entities.size(); i++) {
        Entity noKeyEntity = Entity.newBuilder().putProperties("street", Value.newBuilder().setStringValue("Some street").build()).putProperties("number", Value.newBuilder().setIntegerValue(1L).build()).build();
        testEntitiesWithNoKey.add(noKeyEntity);
        expectedErrors.add(ErrorMessage.newBuilder().setMessage("Datastore Entity Without Key").setData(entityJsonPrinter.print(noKeyEntity)).build().toJson());
    }
    // Run the test
    TupleTag<Entity> successTag = new TupleTag<Entity>("entities") {
    };
    TupleTag<String> failureTag = new TupleTag<String>("failures") {
    };
    PCollectionTuple results = pipeline.apply("Create", Create.of(testEntitiesWithNoKey)).apply("RemoveNoKeys", CheckNoKey.newBuilder().setSuccessTag(successTag).setFailureTag(failureTag).build());
    // Check the results
    PAssert.that(results.get(successTag)).empty();
    PAssert.that(results.get(failureTag)).containsInAnyOrder(expectedErrors);
    pipeline.run();
}
Also used : JsonToEntity(com.google.cloud.teleport.templates.common.DatastoreConverters.JsonToEntity) Entity(com.google.datastore.v1.Entity) EntityJsonPrinter(com.google.cloud.teleport.templates.common.DatastoreConverters.EntityJsonPrinter) ArrayList(java.util.ArrayList) TupleTag(org.apache.beam.sdk.values.TupleTag) PCollectionTuple(org.apache.beam.sdk.values.PCollectionTuple) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Example 89 with ui.ex1.entity

use of ui.ex1.entity in project DataflowTemplates by GoogleCloudPlatform.

the class DatastoreConvertersTest method testCheckNoKeyBothCorrectAndInvalid.

/**
 * Test {@link DatastoreConverters.CheckNoKey} with both correct and invalid entities.
 */
@Test
@Category(NeedsRunner.class)
public void testCheckNoKeyBothCorrectAndInvalid() throws Exception {
    // Create test data
    List<Entity> testEntitiesWithNoKey = new ArrayList<>();
    List<String> expectedErrors = new ArrayList<>();
    EntityJsonPrinter entityJsonPrinter = new EntityJsonPrinter();
    for (int i = 0; i < entities.size(); i++) {
        Entity noKeyEntity = Entity.newBuilder().putProperties("street", Value.newBuilder().setStringValue("Some street").build()).putProperties("number", Value.newBuilder().setIntegerValue(i).build()).build();
        testEntitiesWithNoKey.add(noKeyEntity);
        expectedErrors.add(ErrorMessage.newBuilder().setMessage("Datastore Entity Without Key").setData(entityJsonPrinter.print(noKeyEntity)).build().toJson());
    }
    List<Entity> testEntities = new ArrayList<>(entities);
    testEntities.addAll(testEntitiesWithNoKey);
    // Run the test
    TupleTag<Entity> successTag = new TupleTag<Entity>("entities") {
    };
    TupleTag<String> failureTag = new TupleTag<String>("failures") {
    };
    PCollectionTuple results = pipeline.apply("Create", Create.of(testEntities)).apply("RemoveNoKeys", CheckNoKey.newBuilder().setSuccessTag(successTag).setFailureTag(failureTag).build());
    // Check the results
    PAssert.that(results.get(successTag)).containsInAnyOrder(entities);
    PAssert.that(results.get(failureTag)).containsInAnyOrder(expectedErrors);
    pipeline.run();
}
Also used : JsonToEntity(com.google.cloud.teleport.templates.common.DatastoreConverters.JsonToEntity) Entity(com.google.datastore.v1.Entity) EntityJsonPrinter(com.google.cloud.teleport.templates.common.DatastoreConverters.EntityJsonPrinter) ArrayList(java.util.ArrayList) TupleTag(org.apache.beam.sdk.values.TupleTag) PCollectionTuple(org.apache.beam.sdk.values.PCollectionTuple) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Example 90 with ui.ex1.entity

use of ui.ex1.entity in project DataflowTemplates by GoogleCloudPlatform.

the class BigQueryConvertersTest method testAvroToEntityRecordField.

/**
 * Tests that {@link BigQueryConverters.AvroToEntity} creates an Entity without a valid key when a
 * field is of type Record.
 */
@Test
public void testAvroToEntityRecordField() throws Exception {
    // Create test data
    TableFieldSchema column = generateNestedTableFieldSchema();
    List<TableFieldSchema> fields = new ArrayList<>();
    fields.add(column);
    TableSchema bqSchema = new TableSchema().setFields(fields);
    Record record = generateNestedAvroRecord();
    SchemaAndRecord inputBqData = new SchemaAndRecord(record, bqSchema);
    // Run the test
    Entity outputEntity = converter.apply(inputBqData);
    // Assess results
    String expectedCauseMessage = String.format("Column [address] of type [RECORD] not supported.");
    assertTrue(!outputEntity.hasKey());
    assertEquals(expectedCauseMessage, outputEntity.getPropertiesMap().get("cause").getStringValue());
    assertEquals(record.toString(), outputEntity.getPropertiesMap().get("row").getStringValue());
}
Also used : Entity(com.google.datastore.v1.Entity) AvroToEntity(com.google.cloud.teleport.templates.common.BigQueryConverters.AvroToEntity) TableSchema(com.google.api.services.bigquery.model.TableSchema) ArrayList(java.util.ArrayList) Record(org.apache.avro.generic.GenericData.Record) SchemaAndRecord(org.apache.beam.sdk.io.gcp.bigquery.SchemaAndRecord) TableFieldSchema(com.google.api.services.bigquery.model.TableFieldSchema) SchemaAndRecord(org.apache.beam.sdk.io.gcp.bigquery.SchemaAndRecord) Test(org.junit.Test)

Aggregations

LivingEntity (org.bukkit.entity.LivingEntity)94 SkinnableEntity (net.citizensnpcs.npc.skin.SkinnableEntity)88 Entity (org.hypertrace.entity.data.service.v1.Entity)44 Test (org.junit.jupiter.api.Test)43 net.minecraft.world.entity (net.minecraft.world.entity)32 org.bukkit.entity (org.bukkit.entity)32 Entity (com.google.datastore.v1.Entity)31 Location (org.bukkit.Location)29 Event (org.hypertrace.core.datamodel.Event)27 AttributeValue (org.hypertrace.core.datamodel.AttributeValue)22 ArrayList (java.util.ArrayList)21 BackendInfo (org.hypertrace.traceenricher.enrichment.enrichers.resolver.backend.BackendInfo)21 Test (org.junit.Test)21 Entity (net.minecraft.server.v1_12_R1.Entity)20 Entity (net.minecraft.server.v1_16_R3.Entity)19 NPCHolder (net.citizensnpcs.npc.ai.NPCHolder)18 Entity (net.minecraft.server.v1_8_R3.Entity)17 Entity (net.minecraft.server.v1_11_R1.Entity)16 Mob (net.minecraft.world.entity.Mob)16 CraftEntity (org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity)16