Implement DatastoreEntity and SqlEntity on more classes (#570)

* Implement DatastoreEntity and SqlEntity on more classes

For classes that aren't going to transition to SQL, they should just
return an empty list of SqlEntities. When reading these in from the
commit log manifests, we just won't persist anything to SQL.

By having all Datastore entity classes implement DatastoreEntity, we can
avoid potential bugs where we forget to transition some entity to SQL,
or we forget to have the capability to read back from the commit logs.

Note: the EntityTest is still @Ignore'd because there are many SQL and
Datastore classes left -- ones that we are still in the process of
converting or adding, or ones that require more complicated transitions.

Note: Locks and Cursors aren't converted (even though we could) because
they're ephemeral

* Responses to CR

Add a @EntityForTest annotation
fix null that snuck in

* Keep the test ignored for now
This commit is contained in:
gbrodman 2020-05-01 17:04:13 -04:00 committed by GitHub
parent 01e2d24658
commit c5aa0125ab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
31 changed files with 217 additions and 34 deletions

View file

@ -23,6 +23,7 @@ import com.google.common.hash.BloomFilter;
import google.registry.model.ImmutableObject;
import google.registry.persistence.transaction.JpaTestRules;
import google.registry.persistence.transaction.JpaTestRules.JpaUnitTestRule;
import google.registry.schema.replay.EntityTest.EntityForTesting;
import javax.persistence.Entity;
import javax.persistence.Id;
import org.junit.Rule;
@ -50,6 +51,7 @@ public class BloomFilterConverterTest {
}
@Entity(name = "TestEntity") // Override entity name to avoid the nested class reference.
@EntityForTesting
public static class TestEntity extends ImmutableObject {
@Id String name = "id";

View file

@ -20,6 +20,7 @@ import google.registry.model.CreateAutoTimestamp;
import google.registry.model.ImmutableObject;
import google.registry.persistence.transaction.JpaTestRules;
import google.registry.persistence.transaction.JpaTestRules.JpaUnitTestRule;
import google.registry.schema.replay.EntityTest.EntityForTesting;
import google.registry.testing.FakeClock;
import javax.persistence.Entity;
import javax.persistence.Id;
@ -66,6 +67,7 @@ public class CreateAutoTimestampConverterTest {
}
@Entity(name = "TestEntity") // Override entity name to avoid the nested class reference.
@EntityForTesting
public static class TestEntity extends ImmutableObject {
@Id String name;

View file

@ -21,6 +21,7 @@ import static org.junit.Assert.assertThrows;
import google.registry.model.ImmutableObject;
import google.registry.persistence.transaction.JpaTestRules;
import google.registry.persistence.transaction.JpaTestRules.JpaUnitTestRule;
import google.registry.schema.replay.EntityTest.EntityForTesting;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.PersistenceException;
@ -78,6 +79,7 @@ public class CurrencyUnitConverterTest {
}
@Entity(name = "TestEntity") // Override entity name to avoid the nested class reference.
@EntityForTesting
public static class TestEntity extends ImmutableObject {
@Id String name = "id";

View file

@ -20,6 +20,7 @@ import static google.registry.persistence.transaction.TransactionManagerFactory.
import google.registry.model.ImmutableObject;
import google.registry.persistence.transaction.JpaTestRules;
import google.registry.persistence.transaction.JpaTestRules.JpaUnitTestRule;
import google.registry.schema.replay.EntityTest.EntityForTesting;
import java.math.BigInteger;
import javax.persistence.Entity;
import javax.persistence.Id;
@ -65,6 +66,7 @@ public class DurationConverterTest {
}
@Entity(name = "TestEntity") // Override entity name to avoid the nested class reference.
@EntityForTesting
public static class TestEntity extends ImmutableObject {
@Id String name = "id";

View file

@ -20,6 +20,7 @@ import com.google.common.collect.ImmutableMap;
import google.registry.model.ImmutableObject;
import google.registry.persistence.transaction.JpaTestRules;
import google.registry.persistence.transaction.JpaTestRules.JpaUnitTestRule;
import google.registry.schema.replay.EntityTest.EntityForTesting;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;
@ -149,6 +150,7 @@ public class JodaMoneyConverterTest {
// Override entity name to exclude outer-class name in table name. Not necessary if class is not
// inner class. The double quotes are added to conform to our schema generation convention.
@Entity(name = "\"TestEntity\"")
@EntityForTesting
public static class TestEntity extends ImmutableObject {
@Id String name = "id";
@ -164,6 +166,7 @@ public class JodaMoneyConverterTest {
// See comments on the annotation for TestEntity above for reason.
@Entity(name = "\"ComplexTestEntity\"")
@EntityForTesting
// This entity is used to test column override for embedded fields and collections.
public static class ComplexTestEntity extends ImmutableObject {

View file

@ -20,6 +20,7 @@ import google.registry.model.ImmutableObject;
import google.registry.model.UpdateAutoTimestamp;
import google.registry.persistence.transaction.JpaTestRules;
import google.registry.persistence.transaction.JpaTestRules.JpaUnitTestRule;
import google.registry.schema.replay.EntityTest.EntityForTesting;
import google.registry.testing.FakeClock;
import javax.persistence.Entity;
import javax.persistence.Id;
@ -77,6 +78,7 @@ public class UpdateAutoTimestampConverterTest {
}
@Entity(name = "TestEntity") // Override entity name to avoid the nested class reference.
@EntityForTesting
public static class TestEntity extends ImmutableObject {
@Id String name;

View file

@ -22,6 +22,10 @@ import io.github.classgraph.ClassGraph;
import io.github.classgraph.ClassInfo;
import io.github.classgraph.ClassInfoList;
import io.github.classgraph.ScanResult;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.junit.Ignore;
import org.junit.Test;
@ -59,7 +63,13 @@ public class EntityTest {
return classInfoList.stream()
.filter(ClassInfo::isStandardClass)
.map(ClassInfo::loadClass)
.filter(clazz -> !clazz.isAnnotationPresent(EntityForTesting.class))
.map(Class::getName)
.collect(toImmutableSet());
}
/** Entities that are solely used for testing, to avoid scanning them in {@link EntityTest}. */
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface EntityForTesting {}
}