Skip to content

Commit 3806a7b

Browse files
committed
Minor follow on to #5536
- Noticed several SharedMiniClusterBase ITs were not calling `stopMiniCluster()`. All tests which start a mini cluster now stop the mini cluster as well. - Added some javadoc changes to SharedMiniClusterBase and SimpleSharedMacTestSuite - Misc. other minor changes
1 parent af0ce90 commit 3806a7b

File tree

9 files changed

+43
-21
lines changed

9 files changed

+43
-21
lines changed

minicluster/src/main/java/org/apache/accumulo/miniclusterImpl/MiniAccumuloConfigImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public class MiniAccumuloConfigImpl {
7474
private String rootPassword = null;
7575
private Map<String,String> hadoopConfOverrides = new HashMap<>();
7676
private Map<String,String> siteConfig = new HashMap<>();
77-
private Map<String,String> configuredSiteConig = new HashMap<>();
77+
private Map<String,String> configuredSiteConfig = new HashMap<>();
7878
private Map<String,String> clientProps = new HashMap<>();
7979
private Map<ServerType,Long> memoryConfig = new HashMap<>();
8080
private final EnumMap<ServerType,Class<?>> serverTypeClasses =
@@ -315,7 +315,7 @@ public MiniAccumuloConfigImpl setClientProps(Map<String,String> clientProps) {
315315

316316
private MiniAccumuloConfigImpl _setSiteConfig(Map<String,String> siteConfig) {
317317
this.siteConfig = new HashMap<>(siteConfig);
318-
this.configuredSiteConig = new HashMap<>(siteConfig);
318+
this.configuredSiteConfig = new HashMap<>(siteConfig);
319319
return this;
320320
}
321321

@@ -439,7 +439,7 @@ public Map<String,String> getClientProps() {
439439
}
440440

441441
public Map<String,String> getConfiguredSiteConfig() {
442-
return new HashMap<>(configuredSiteConig);
442+
return new HashMap<>(configuredSiteConfig);
443443
}
444444

445445
/**

test/src/main/java/org/apache/accumulo/harness/MiniClusterConfigurationCallback.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
* Callback interface to inject configuration into the MiniAccumuloCluster or Hadoop core-site.xml
2626
* file used by the MiniAccumuloCluster
2727
*/
28+
@FunctionalInterface
2829
public interface MiniClusterConfigurationCallback {
2930

3031
class NoCallback implements MiniClusterConfigurationCallback {

test/src/main/java/org/apache/accumulo/harness/SharedMiniClusterBase.java

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import org.apache.accumulo.core.clientImpl.Namespace;
4848
import org.apache.accumulo.core.conf.ClientProperty;
4949
import org.apache.accumulo.miniclusterImpl.MiniAccumuloClusterImpl;
50+
import org.apache.accumulo.suites.SimpleSharedMacTestSuite;
5051
import org.apache.hadoop.conf.Configuration;
5152
import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
5253
import org.apache.hadoop.security.UserGroupInformation;
@@ -58,17 +59,20 @@
5859
* Integration-Test base class which starts one MAC for the entire Integration Test. This IT type is
5960
* faster and more geared for testing typical, expected behavior of a cluster. For more advanced
6061
* testing see {@link AccumuloClusterHarness}
61-
*
62+
* <p>
6263
* There isn't a good way to build this off of the {@link AccumuloClusterHarness} (as would be the
6364
* logical place) because we need to start the MiniAccumuloCluster in a static BeforeAll-annotated
6465
* method. Because it is static and invoked before any other BeforeAll methods in the
6566
* implementation, the actual test classes can't expose any information to tell the base class that
6667
* it is to perform the one-MAC-per-class semantics.
67-
*
68+
* <p>
6869
* Implementations of this class must be sure to invoke {@link #startMiniCluster()} or
6970
* {@link #startMiniClusterWithConfig(MiniClusterConfigurationCallback)} in a method annotated with
7071
* the {@link org.junit.jupiter.api.BeforeAll} JUnit annotation and {@link #stopMiniCluster()} in a
7172
* method annotated with the {@link org.junit.jupiter.api.AfterAll} JUnit annotation.
73+
* <p>
74+
* Implementations of this class should also consider if they can be added to
75+
* {@link SimpleSharedMacTestSuite}. See the suites description to determine if they can be added.
7276
*/
7377
@Tag(MINI_CLUSTER_ONLY)
7478
public abstract class SharedMiniClusterBase extends AccumuloITBase implements ClusterUsers {
@@ -82,7 +86,8 @@ public abstract class SharedMiniClusterBase extends AccumuloITBase implements Cl
8286
private static TestingKdc krb;
8387

8488
/**
85-
* Starts a MiniAccumuloCluster instance with the default configuration.
89+
* Starts a MiniAccumuloCluster instance with the default configuration. This method is
90+
* idempotent: necessitated by {@link SimpleSharedMacTestSuite}.
8691
*/
8792
public static void startMiniCluster() throws Exception {
8893
startMiniClusterWithConfig(MiniClusterConfigurationCallback.NO_CALLBACK);
@@ -91,6 +96,7 @@ public static void startMiniCluster() throws Exception {
9196
/**
9297
* Starts a MiniAccumuloCluster instance with the default configuration but also provides the
9398
* caller the opportunity to update the configuration before the MiniAccumuloCluster is started.
99+
* This method is idempotent: necessitated by {@link SimpleSharedMacTestSuite}.
94100
*
95101
* @param miniClusterCallback A callback to configure the minicluster before it is started.
96102
*/
@@ -146,14 +152,11 @@ private static String getTestClassName() {
146152
*/
147153
public static synchronized void stopMiniCluster() {
148154
if (STOP_DISABLED.get()) {
149-
// If stop is disabled, then we are likely running a
150-
// test class that is part of a larger suite. We don't
151-
// want to shut down the cluster, but we should clean
152-
// up any tables that were created, but not deleted,
153-
// by the test class. This will prevent issues with
154-
// subsequent tests that count objects or initiate
155-
// compactions and wait for them, but some other table
156-
// from a prior test is compacting.
155+
// If stop is disabled, then we are likely running a test class that is part of a larger
156+
// suite. We don't want to shut down the cluster, but we should clean up any tables or
157+
// namespaces that were created, but not deleted, by the test class. This will prevent issues
158+
// with subsequent tests that count objects or initiate compactions and wait for them, but
159+
// some other table from a prior test is compacting.
157160
try (AccumuloClient client = Accumulo.newClient().from(getClientProps()).build()) {
158161
for (String tableName : client.tableOperations().list()) {
159162
if (!tableName.startsWith(Namespace.ACCUMULO.name() + ".")) {

test/src/main/java/org/apache/accumulo/suites/SimpleSharedMacTestSuite.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,30 @@
2020

2121
import static org.apache.accumulo.harness.AccumuloITBase.SIMPLE_MINI_CLUSTER_SUITE;
2222

23+
import org.apache.accumulo.harness.MiniClusterConfigurationCallback;
2324
import org.apache.accumulo.harness.SharedMiniClusterBase;
25+
import org.junit.jupiter.api.Tag;
2426
import org.junit.platform.suite.api.AfterSuite;
2527
import org.junit.platform.suite.api.BeforeSuite;
2628
import org.junit.platform.suite.api.IncludeClassNamePatterns;
2729
import org.junit.platform.suite.api.IncludeTags;
2830
import org.junit.platform.suite.api.SelectPackages;
2931
import org.junit.platform.suite.api.Suite;
3032

33+
/**
34+
* This test suite is used to run applicable ITs against a single, shared cluster, starting and
35+
* stopping the cluster only once for the duration of the suite. This avoids starting and stopping a
36+
* cluster per IT, providing some speedup. An IT is applicable if:
37+
* <p>
38+
* 1) It is a subclass of {@link SharedMiniClusterBase}, meaning it starts and stops a single
39+
* cluster for the entire IT.
40+
* <p>
41+
* 2) It does not start the cluster with any custom config (i.e., it does not use
42+
* {@link SharedMiniClusterBase#startMiniClusterWithConfig(MiniClusterConfigurationCallback)})
43+
* <p>
44+
* An IT which meets this criteria should be tagged (using JUnit {@link Tag}) with
45+
* {@link #SIMPLE_MINI_CLUSTER_SUITE} to be added to the suite.
46+
*/
3147
@Suite
3248
@SelectPackages("org.apache.accumulo.test") // look in this package and subpackages
3349
@IncludeTags(SIMPLE_MINI_CLUSTER_SUITE) // for tests with this tag

test/src/main/java/org/apache/accumulo/test/compaction/ExternalCompaction_1_IT.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ public static void afterTests() throws Exception {
139139
if (testLock != null) {
140140
testLock.unlock();
141141
}
142+
stopMiniCluster();
142143
}
143144

144145
public static class TestFilter extends Filter {

test/src/main/java/org/apache/accumulo/test/compaction/ExternalCompaction_3_IT.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
import org.apache.hadoop.io.Text;
7575
import org.apache.thrift.TException;
7676
import org.apache.thrift.transport.TTransportException;
77+
import org.junit.jupiter.api.AfterAll;
7778
import org.junit.jupiter.api.BeforeAll;
7879
import org.junit.jupiter.api.Test;
7980

@@ -93,6 +94,11 @@ public static void beforeTests() throws Exception {
9394
startMiniClusterWithConfig(new ExternalCompaction3Config());
9495
}
9596

97+
@AfterAll
98+
public static void afterTests() {
99+
stopMiniCluster();
100+
}
101+
96102
@Test
97103
public void testMergeCancelsExternalCompaction() throws Exception {
98104

test/src/main/java/org/apache/accumulo/test/compaction/FlakyExternalCompaction2IT.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,12 @@
1818
*/
1919
package org.apache.accumulo.test.compaction;
2020

21-
import org.apache.accumulo.harness.SharedMiniClusterBase;
2221
import org.apache.accumulo.minicluster.ServerType;
2322
import org.apache.accumulo.miniclusterImpl.MiniAccumuloConfigImpl;
2423
import org.apache.accumulo.test.ample.FlakyAmpleManager;
2524
import org.apache.accumulo.test.ample.FlakyAmpleServerContext;
2625
import org.apache.accumulo.test.ample.FlakyAmpleTserver;
2726
import org.apache.hadoop.conf.Configuration;
28-
import org.junit.jupiter.api.AfterAll;
2927
import org.junit.jupiter.api.BeforeAll;
3028

3129
/**
@@ -52,9 +50,4 @@ public void configureMiniCluster(MiniAccumuloConfigImpl cfg, Configuration coreS
5250
public static void setup() throws Exception {
5351
startMiniClusterWithConfig(new FlakyExternalCompaction2Config());
5452
}
55-
56-
@AfterAll
57-
public static void teardown() {
58-
SharedMiniClusterBase.stopMiniCluster();
59-
}
6053
}

test/src/main/java/org/apache/accumulo/test/functional/ManagerAssignmentIT.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ public static void beforeAll() throws Exception {
110110
@AfterAll
111111
public static void afterAll() {
112112
client.close();
113+
SharedMiniClusterBase.stopMiniCluster();
113114
}
114115

115116
@BeforeEach

test/src/main/java/org/apache/accumulo/test/functional/OnDemandTabletUnloadingIT.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ public static void beforeAll() throws Exception {
116116

117117
@AfterAll
118118
public static void after() throws Exception {
119+
SharedMiniClusterBase.stopMiniCluster();
119120
sink.close();
120121
metricConsumer.interrupt();
121122
metricConsumer.join();

0 commit comments

Comments
 (0)