Update tests and configuration for consistency All tests run with updated configuration. Additionally, configuration now uses constants for all configuration keys. Change-Id: I244709fac9ea133e59b90369e2e97547af9296fc
diff --git a/src/main/java/com/googlesource/gerrit/plugins/spannerrefdb/Configuration.java b/src/main/java/com/googlesource/gerrit/plugins/spannerrefdb/Configuration.java index 6e340c3..7f34313 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/spannerrefdb/Configuration.java +++ b/src/main/java/com/googlesource/gerrit/plugins/spannerrefdb/Configuration.java
@@ -33,6 +33,8 @@ public static final String DATABASE_KEY = "database"; public static final String INSTANCE_KEY = "instance"; + public static final String EMULATOR_KEY = "useEmulator"; + public static final String CREDENTIALS_KEY = "credentialsPath"; public static final String SECTION = "ref-database"; public static final String SUBSECTION = "spanner"; private final String spannerInstance; @@ -45,13 +47,13 @@ Config cfg = configFactory.getGlobalPluginConfig(pluginName); this.spannerInstance = getString(cfg, SECTION, SUBSECTION, INSTANCE_KEY, "spanner-instance"); this.spannerDatabase = getString(cfg, SECTION, SUBSECTION, DATABASE_KEY, "global-refdb"); - boolean useEmulator = cfg.getBoolean(SECTION, "useEmulator", false); + boolean useEmulator = cfg.getBoolean(SECTION, SUBSECTION, EMULATOR_KEY, false); if (useEmulator) { this.options = SpannerOptions.newBuilder().build(); logger.atInfo().log( "Using local Spanner emulator for global-refdb; Spanner credentials will not be read."); } else { - String credentialsPath = getString(cfg, SECTION, null, "credentialsPath", null); + String credentialsPath = getString(cfg, SECTION, SUBSECTION, CREDENTIALS_KEY, null); GoogleCredentials credentials = GoogleCredentials.fromStream(new FileInputStream(credentialsPath)); this.options = SpannerOptions.newBuilder().setCredentials(credentials).build();
diff --git a/src/main/java/com/googlesource/gerrit/plugins/spannerrefdb/Lock.java b/src/main/java/com/googlesource/gerrit/plugins/spannerrefdb/Lock.java index cb10160..287c9e1 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/spannerrefdb/Lock.java +++ b/src/main/java/com/googlesource/gerrit/plugins/spannerrefdb/Lock.java
@@ -37,15 +37,15 @@ import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; -/*** - * Locks are a mechanism to ensure exclusive usage of the locked resource. Here we - * provide a Spanner-specific implementation of locks which are used from the - * global-refdb module, which is used to ensure refs are updated consistently - * across multiple Gerrit primary sites (see README.md). +/** + * * Locks are a mechanism to ensure exclusive usage of the locked resource. Here we provide a + * Spanner-specific implementation of locks which are used from the global-refdb module, which is + * used to ensure refs are updated consistently across multiple Gerrit primary sites (see + * README.md). * - * Persistent distributed Locks are used to guard distributed transactions - * spanning RefUpdates in a git repo of the involved Gerrit primary sites and - * corresponding updates of those refs in the global-refdb. + * <p>Persistent distributed Locks are used to guard distributed transactions spanning RefUpdates in + * a git repo of the involved Gerrit primary sites and corresponding updates of those refs in the + * global-refdb. */ public class Lock implements AutoCloseable { private static final FluentLogger logger = FluentLogger.forEnclosingClass();
diff --git a/src/test/java/com/googlesource/gerrit/plugins/spannerrefdb/EmulatedSpannerRefDb.java b/src/test/java/com/googlesource/gerrit/plugins/spannerrefdb/EmulatedSpannerRefDb.java index 4eaaf84..3fa81e9 100644 --- a/src/test/java/com/googlesource/gerrit/plugins/spannerrefdb/EmulatedSpannerRefDb.java +++ b/src/test/java/com/googlesource/gerrit/plugins/spannerrefdb/EmulatedSpannerRefDb.java
@@ -15,6 +15,7 @@ package com.googlesource.gerrit.plugins.spannerrefdb; import static com.googlesource.gerrit.plugins.spannerrefdb.Configuration.DATABASE_KEY; +import static com.googlesource.gerrit.plugins.spannerrefdb.Configuration.EMULATOR_KEY; import static com.googlesource.gerrit.plugins.spannerrefdb.Configuration.INSTANCE_KEY; import static com.googlesource.gerrit.plugins.spannerrefdb.Configuration.SECTION; import static com.googlesource.gerrit.plugins.spannerrefdb.Configuration.SUBSECTION; @@ -45,8 +46,8 @@ @Ignore public class EmulatedSpannerRefDb { public static final String PROJECT_ID = "test"; - public static final String SPANNER_INSTANCE_ID = "instance"; - public static final String SPANNER_DATABASE_ID = "refdb"; + public static final String SPANNER_INSTANCE_ID = "spanner-instance"; + public static final String SPANNER_DATABASE_ID = "global-refdb"; private static final String pluginName = "spanner-refdb"; private final SpannerEmulatorContainer container; @@ -141,9 +142,9 @@ private Configuration createEmulatorConfiguration() throws IOException { Config refDbConfig = new Config(); - refDbConfig.setBoolean(Configuration.SECTION, null, "useEmulator", true); refDbConfig.setString(SECTION, SUBSECTION, INSTANCE_KEY, SPANNER_INSTANCE_ID); refDbConfig.setString(SECTION, SUBSECTION, DATABASE_KEY, SPANNER_DATABASE_ID); + refDbConfig.setBoolean(SECTION, SUBSECTION, EMULATOR_KEY, true); PluginConfigFactory cfgFactory = mock(PluginConfigFactory.class); when(cfgFactory.getGlobalPluginConfig(pluginName)).thenReturn(refDbConfig);
diff --git a/src/test/java/com/googlesource/gerrit/plugins/spannerrefdb/SpannerRefDatabaseTest.java b/src/test/java/com/googlesource/gerrit/plugins/spannerrefdb/SpannerRefDatabaseTest.java index 607256b..34ef27f 100644 --- a/src/test/java/com/googlesource/gerrit/plugins/spannerrefdb/SpannerRefDatabaseTest.java +++ b/src/test/java/com/googlesource/gerrit/plugins/spannerrefdb/SpannerRefDatabaseTest.java
@@ -54,7 +54,7 @@ } @Test - public void updateRef() throws Exception { + public void testUpdateRef() throws Exception { createNewRef(PROJECT_NAME_KEY, REF_NAME, OBJECT_ID_1); updateRef(PROJECT_NAME_KEY, REF_NAME, OBJECT_ID_1, OBJECT_ID_2);