mirror of
https://github.com/google/nomulus.git
synced 2025-07-09 12:43:24 +02:00
Improve error information in coverage test. (#537)
* Improve error information in coverage test. If the golden schema isn't up-to-date with the persistence model, the coverage tests fail with an exception chain that ends in a PSQLException 'relation "TableName" does not exist' which is kind of misleading when the problem is that your golden schema isn't up-to-date. Check for this error in the coverage tests and generate a more informative error message indicating a likely root cause.
This commit is contained in:
parent
5b452bf074
commit
fa9134328a
1 changed files with 29 additions and 12 deletions
|
@ -23,6 +23,7 @@ import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
import google.registry.persistence.PersistenceXmlUtility;
|
import google.registry.persistence.PersistenceXmlUtility;
|
||||||
|
import java.sql.SQLException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -96,6 +97,7 @@ public class JpaEntityCoverage extends ExternalResource {
|
||||||
* @return true if an instance of {@code entityType} is found in the database and can be read
|
* @return true if an instance of {@code entityType} is found in the database and can be read
|
||||||
*/
|
*/
|
||||||
private static boolean isPersisted(Class entityType) {
|
private static boolean isPersisted(Class entityType) {
|
||||||
|
try {
|
||||||
List result =
|
List result =
|
||||||
jpaTm()
|
jpaTm()
|
||||||
.transact(
|
.transact(
|
||||||
|
@ -108,6 +110,21 @@ public class JpaEntityCoverage extends ExternalResource {
|
||||||
.setMaxResults(1)
|
.setMaxResults(1)
|
||||||
.getResultList());
|
.getResultList());
|
||||||
return !result.isEmpty() && entityType.isInstance(result.get(0));
|
return !result.isEmpty() && entityType.isInstance(result.get(0));
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
// See if this was caused by a "relation does not exist" error.
|
||||||
|
Throwable cause = e;
|
||||||
|
while ((cause = cause.getCause()) != null) {
|
||||||
|
if (cause instanceof SQLException
|
||||||
|
&& cause.getMessage().matches("(?s).*relation .* does not exist.*")) {
|
||||||
|
throw new RuntimeException(
|
||||||
|
"SQLException occurred. If you've updated the set of entities, make sure you've "
|
||||||
|
+ "also updated the golden schema. See db/README.md for details.",
|
||||||
|
e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getJpaEntityName(Class entityType) {
|
private static String getJpaEntityName(Class entityType) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue