Compare commits

..
Author SHA1 Message Date
Weimin YuandGitHub f408dc03f1 Test database should use real locale configs (#3204)
Use the real locale configs from Cloud SQL when creating postgres
database using docker.
2026-08-11 16:49:13 +00:00
Ben McIlwainandGitHub 575192016f Change rotatePrimaryCert type to primitive boolean (#3205)
Change the rotatePrimaryCert field in CreateOrUpdateRegistrarCommand
from object Boolean to primitive boolean. Since the field is initialized
to default false and used as a presence-based switch without tri-state
semantics, primitive boolean accurately reflects its behavior and avoids
unnecessary object wrapper overhead.

BUG= http://b/537308816
2026-08-10 22:03:26 +00:00
3 changed files with 43 additions and 1 deletions
@@ -138,7 +138,7 @@ abstract class CreateOrUpdateRegistrarCommand extends MutatingCommand {
description =
"Used together with --cert_file when updating an registrar. "
+ "If set, current cert is saved as failover.")
private Boolean rotatePrimaryCert = Boolean.FALSE;
private boolean rotatePrimaryCert = false;
@Nullable
@Parameter(
@@ -139,6 +139,11 @@ public abstract class JpaTransactionManagerExtension
private static JdbcDatabaseContainer<?> create() {
PostgreSQLContainer<?> container =
new PostgreSQLContainer<>(NomulusPostgreSql.getDockerImageName())
// Locale configs in use on Cloud SQL in all environments
.withEnv(
"POSTGRES_INITDB_ARGS",
"--encoding=UTF8 --lc-collate=en_US.UTF8 --lc-ctype=en_US.UTF8"
+ " --locale-provider=libc --no-locale")
.withDatabaseName(POSTGRES_DB_NAME);
container.start();
return container;
@@ -25,7 +25,10 @@ import google.registry.persistence.transaction.JpaTestExtensions.JpaUnitTestExte
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.PersistenceException;
import jakarta.persistence.Tuple;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
@@ -59,6 +62,40 @@ public class JpaTransactionManagerExtensionTest {
});
}
@Test
void verifyDatabaseEncodingConfig() {
String sql =
"""
SELECT
pg_encoding_to_char(encoding) AS encoding,
datcollate AS collation,
datctype AS ctype,
datlocprovider AS locale_provider,
datlocale AS locale
FROM
pg_database
WHERE
datname = 'postgres'
""";
List<Tuple> rows =
tm().transact(
() -> tm().getEntityManager().createNativeQuery(sql, Tuple.class).getResultList());
assertThat(rows).hasSize(1);
var row =
rows.get(0).getElements().stream()
.collect(
HashMap::new, // Use HashMap since there may be null value
(m, element) -> m.put(element.getAlias(), rows.get(0).get(element)),
Map::putAll);
assertThat(row)
.containsExactly(
"encoding", "UTF8",
"collation", "en_US.UTF8",
"ctype", "en_US.UTF8",
"locale_provider", 'c', // c --> libc
"locale", null);
}
@Test
void testReplicaJpaTm() {
TestEntity testEntity = new TestEntity("foo", "bar");