This is an automated email from the ASF dual-hosted git repository. dlmarion pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/accumulo.git
The following commit(s) were added to refs/heads/main by this push: new de010341ad Removed PowerMock and the 2 unit tests using it (#3817) de010341ad is described below commit de010341adb204070571ef0e597ff90e90c70f72 Author: Dave Marion <dlmar...@apache.org> AuthorDate: Fri Oct 6 15:18:22 2023 -0400 Removed PowerMock and the 2 unit tests using it (#3817) Removed CompactionCoordinatorTest and CompactorTest which were testing the state of the CompactionCoordinator and Compactor internals. Removing these tests allowed me to remove PowerMock and JUnit4 from the build. --- pom.xml | 49 -- server/compaction-coordinator/pom.xml | 20 - .../coordinator/CompactionCoordinatorTest.java | 657 --------------------- server/compactor/pom.xml | 25 - .../apache/accumulo/compactor/CompactorTest.java | 455 -------------- .../src/test/resources/log4j2-test.properties | 35 -- server/native/pom.xml | 5 - src/build/ci/find-unapproved-junit.sh | 8 +- start/pom.xml | 10 - 9 files changed, 4 insertions(+), 1260 deletions(-) diff --git a/pom.xml b/pom.xml index a92287c8f9..602809f869 100644 --- a/pom.xml +++ b/pom.xml @@ -153,7 +153,6 @@ <version.hadoop>3.3.6</version.hadoop> <version.maven-javadoc-plugin>3.6.0</version.maven-javadoc-plugin> <version.opentelemetry>1.27.0</version.opentelemetry> - <version.powermock>2.0.9</version.powermock> <version.slf4j>2.0.7</version.slf4j> <version.thrift>0.17.0</version.thrift> <version.zookeeper>3.8.2</version.zookeeper> @@ -323,12 +322,6 @@ <artifactId>commons-logging</artifactId> <version>1.2</version> </dependency> - <dependency> - <!-- legacy junit version specified here for dependency convergence --> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>4.13.2</version> - </dependency> <dependency> <groupId>org.apache.accumulo</groupId> <artifactId>accumulo-compaction-coordinator</artifactId> @@ -629,32 +622,6 @@ </exclusion> </exclusions> </dependency> - <dependency> - <!-- converge transitive dependency version between powermock and easymock --> - <groupId>org.objenesis</groupId> - <artifactId>objenesis</artifactId> - <version>3.3</version> - </dependency> - <dependency> - <groupId>org.powermock</groupId> - <artifactId>powermock-api-easymock</artifactId> - <version>${version.powermock}</version> - </dependency> - <dependency> - <groupId>org.powermock</groupId> - <artifactId>powermock-core</artifactId> - <version>${version.powermock}</version> - </dependency> - <dependency> - <groupId>org.powermock</groupId> - <artifactId>powermock-module-junit4</artifactId> - <version>${version.powermock}</version> - </dependency> - <dependency> - <groupId>org.powermock</groupId> - <artifactId>powermock-reflect</artifactId> - <version>${version.powermock}</version> - </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> @@ -958,8 +925,6 @@ <undeclared>org.apache.httpcomponents:httpcore:jar:*</undeclared> <undeclared>org.powermock:powermock-core:jar:*</undeclared> <undeclared>org.powermock:powermock-reflect:jar:*</undeclared> - <!-- This should be removed upon completion of migrating junit 4 to 5 --> - <undeclared>junit:junit:jar:*</undeclared> </ignoredUsedUndeclaredDependencies> <ignoredUnusedDeclaredDependencies> <!-- auto-service isn't used in every module --> @@ -981,8 +946,6 @@ <unused>org.apache.logging.log4j:log4j-1.2-api:jar:*</unused> <unused>org.apache.logging.log4j:log4j-slf4j2-impl:jar:*</unused> <unused>org.apache.logging.log4j:log4j-web:jar:*</unused> - <!-- This should be removed upon completion of migrating junit 4 to 5 --> - <unused>org.junit.vintage:junit-vintage-engine:jar:*</unused> <unused>org.junit.jupiter:junit-jupiter-engine:jar:*</unused> </ignoredUnusedDeclaredDependencies> </configuration> @@ -1092,26 +1055,14 @@ <property name="format" value="org[.]apache[.]commons[.]math[.]" /> <property name="message" value="Use commons-math3 (org.apache.commons.math3.*)" /> </module> - <module name="RegexpSinglelineJava"> - <property name="format" value="junit[.]framework[.]TestCase" /> - <property name="message" value="Use JUnit4+ @Test annotation instead of TestCase" /> - </module> <module name="RegexpSinglelineJava"> <property name="format" value="import org[.]apache[.]accumulo[.]core[.]util[.]LazySingletons;" /> <property name="message" value="Use static imports for LazySingletons for consistency" /> </module> - <module name="RegexpSinglelineJava"> - <property name="format" value="import org[.]junit[.]Assert;" /> - <property name="message" value="Use static imports for Assert.* methods for consistency" /> - </module> <module name="RegexpSinglelineJava"> <property name="format" value="org[.]junit[.]jupiter[.]api[.]Assertions;" /> <property name="message" value="Use static imports for Assertions.* methods for consistency" /> </module> - <module name="RegexpSinglelineJava"> - <property name="format" value="import org[.]junit[.]Assume;" /> - <property name="message" value="Use static imports for Assume.* methods for consistency" /> - </module> <module name="RegexpSinglelineJava"> <property name="format" value="org[.]junit[.]jupiter[.]api[.]Assumptions;" /> <property name="message" value="Use static imports for Assumptions.* methods for consistency" /> diff --git a/server/compaction-coordinator/pom.xml b/server/compaction-coordinator/pom.xml index 5b3ad76e40..8531128ed4 100644 --- a/server/compaction-coordinator/pom.xml +++ b/server/compaction-coordinator/pom.xml @@ -81,30 +81,10 @@ <artifactId>log4j-slf4j2-impl</artifactId> <scope>test</scope> </dependency> - <dependency> - <groupId>org.easymock</groupId> - <artifactId>easymock</artifactId> - <scope>test</scope> - </dependency> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-api</artifactId> <scope>test</scope> </dependency> - <dependency> - <groupId>org.junit.vintage</groupId> - <artifactId>junit-vintage-engine</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.powermock</groupId> - <artifactId>powermock-api-easymock</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.powermock</groupId> - <artifactId>powermock-module-junit4</artifactId> - <scope>test</scope> - </dependency> </dependencies> </project> diff --git a/server/compaction-coordinator/src/test/java/org/apache/accumulo/coordinator/CompactionCoordinatorTest.java b/server/compaction-coordinator/src/test/java/org/apache/accumulo/coordinator/CompactionCoordinatorTest.java deleted file mode 100644 index 746f552a3c..0000000000 --- a/server/compaction-coordinator/src/test/java/org/apache/accumulo/coordinator/CompactionCoordinatorTest.java +++ /dev/null @@ -1,657 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.accumulo.coordinator; - -import static org.easymock.EasyMock.anyObject; -import static org.easymock.EasyMock.expect; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -import java.net.UnknownHostException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; -import java.util.TreeMap; -import java.util.TreeSet; -import java.util.UUID; -import java.util.concurrent.ScheduledThreadPoolExecutor; - -import org.apache.accumulo.core.cli.ConfigOpts; -import org.apache.accumulo.core.clientImpl.thrift.TInfo; -import org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException; -import org.apache.accumulo.core.compaction.thrift.TExternalCompaction; -import org.apache.accumulo.core.conf.DefaultConfiguration; -import org.apache.accumulo.core.dataImpl.thrift.TKeyExtent; -import org.apache.accumulo.core.metadata.TServerInstance; -import org.apache.accumulo.core.metadata.schema.ExternalCompactionId; -import org.apache.accumulo.core.rpc.ThriftUtil; -import org.apache.accumulo.core.securityImpl.thrift.TCredentials; -import org.apache.accumulo.core.tabletserver.thrift.TCompactionQueueSummary; -import org.apache.accumulo.core.tabletserver.thrift.TCompactionStats; -import org.apache.accumulo.core.tabletserver.thrift.TExternalCompactionJob; -import org.apache.accumulo.core.tabletserver.thrift.TabletServerClientService; -import org.apache.accumulo.core.tabletserver.thrift.TabletServerClientService.Client; -import org.apache.accumulo.core.trace.TraceUtil; -import org.apache.accumulo.core.util.compaction.ExternalCompactionUtil; -import org.apache.accumulo.core.util.compaction.RunningCompaction; -import org.apache.accumulo.server.AbstractServer; -import org.apache.accumulo.server.ServerContext; -import org.apache.accumulo.server.manager.LiveTServerSet; -import org.apache.accumulo.server.rpc.ServerAddress; -import org.apache.accumulo.server.security.AuditedSecurityOperation; -import org.apache.thrift.transport.TTransportException; -import org.apache.zookeeper.KeeperException; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.api.easymock.PowerMock; -import org.powermock.core.classloader.annotations.PowerMockIgnore; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor; -import org.powermock.modules.junit4.PowerMockRunner; - -import com.google.common.collect.Sets; -import com.google.common.net.HostAndPort; - -@RunWith(PowerMockRunner.class) -@PrepareForTest({CompactionCoordinator.class, DeadCompactionDetector.class, ThriftUtil.class, - ExternalCompactionUtil.class}) -@SuppressStaticInitializationFor({"org.apache.log4j.LogManager"}) -@PowerMockIgnore({"org.slf4j.*", "org.apache.logging.*", "org.apache.log4j.*", - "org.apache.commons.logging.*", "org.xml.*", "javax.xml.*", "org.w3c.dom.*", - "com.sun.org.apache.xerces.*"}) -public class CompactionCoordinatorTest { - - public class TestCoordinator extends CompactionCoordinator { - - private final ServerContext context; - private final ServerAddress client; - private final Client tabletServerClient; - - private Set<ExternalCompactionId> metadataCompactionIds = null; - - protected TestCoordinator(CompactionFinalizer finalizer, LiveTServerSet tservers, - ServerAddress client, Client tabletServerClient, ServerContext context, - AuditedSecurityOperation security) { - super(new ConfigOpts(), new String[] {}, context.getConfiguration()); - this.compactionFinalizer = finalizer; - this.tserverSet = tservers; - this.client = client; - this.tabletServerClient = tabletServerClient; - this.context = context; - this.security = security; - } - - @Override - protected void startDeadCompactionDetector() {} - - @Override - protected long getTServerCheckInterval() { - this.shutdown = true; - return 0L; - } - - @Override - protected void startCompactionCleaner(ScheduledThreadPoolExecutor schedExecutor) {} - - @Override - protected CompactionFinalizer createCompactionFinalizer(ScheduledThreadPoolExecutor stpe) { - return null; - } - - @Override - protected LiveTServerSet createLiveTServerSet() { - return null; - } - - @Override - protected void setupSecurity() {} - - @Override - protected void printStartupMsg() {} - - @Override - public ServerContext getContext() { - return this.context; - } - - @Override - protected void getCoordinatorLock(HostAndPort clientAddress) - throws KeeperException, InterruptedException {} - - @Override - protected ServerAddress startCoordinatorClientService() throws UnknownHostException { - return client; - } - - @Override - protected Client getTabletServerConnection(TServerInstance tserver) throws TTransportException { - return tabletServerClient; - } - - @Override - public void compactionCompleted(TInfo tinfo, TCredentials credentials, - String externalCompactionId, TKeyExtent textent, TCompactionStats stats) - throws ThriftSecurityException {} - - @Override - public void compactionFailed(TInfo tinfo, TCredentials credentials, String externalCompactionId, - TKeyExtent extent) throws ThriftSecurityException {} - - void setMetadataCompactionIds(Set<ExternalCompactionId> mci) { - metadataCompactionIds = mci; - } - - @Override - protected Set<ExternalCompactionId> readExternalCompactionIds() { - if (metadataCompactionIds == null) { - return RUNNING_CACHE.keySet(); - } else { - return metadataCompactionIds; - } - } - - public Map<String,TreeMap<Short,TreeSet<TServerInstance>>> getQueues() { - return CompactionCoordinator.QUEUE_SUMMARIES.QUEUES; - } - - public Map<TServerInstance,Set<QueueAndPriority>> getIndex() { - return CompactionCoordinator.QUEUE_SUMMARIES.INDEX; - } - - public Map<ExternalCompactionId,RunningCompaction> getRunning() { - return RUNNING_CACHE; - } - - public void resetInternals() { - getQueues().clear(); - getIndex().clear(); - getRunning().clear(); - metadataCompactionIds = null; - } - - } - - @Test - public void testCoordinatorColdStartNoCompactions() throws Exception { - PowerMock.resetAll(); - PowerMock.suppress(PowerMock.constructor(AbstractServer.class)); - PowerMock.suppress(PowerMock.methods(ThriftUtil.class, "returnClient")); - PowerMock.suppress(PowerMock.methods(DeadCompactionDetector.class, "detectDeadCompactions", - "detectDanglingFinalStateMarkers")); - - ServerContext context = PowerMock.createNiceMock(ServerContext.class); - expect(context.getConfiguration()).andReturn(DefaultConfiguration.getInstance()).anyTimes(); - - PowerMock.mockStatic(ExternalCompactionUtil.class); - List<RunningCompaction> runningCompactions = new ArrayList<>(); - expect(ExternalCompactionUtil.getCompactionsRunningOnCompactors(context)) - .andReturn(runningCompactions); - - CompactionFinalizer finalizer = PowerMock.createNiceMock(CompactionFinalizer.class); - LiveTServerSet tservers = PowerMock.createNiceMock(LiveTServerSet.class); - expect(tservers.getCurrentServers()).andReturn(Collections.emptySet()).anyTimes(); - - ServerAddress client = PowerMock.createNiceMock(ServerAddress.class); - HostAndPort address = HostAndPort.fromString("localhost:10240"); - expect(client.getAddress()).andReturn(address).anyTimes(); - - TServerInstance tsi = PowerMock.createNiceMock(TServerInstance.class); - expect(tsi.getHostPort()).andReturn("localhost:9997").anyTimes(); - - TabletServerClientService.Client tsc = - PowerMock.createNiceMock(TabletServerClientService.Client.class); - expect(tsc.getCompactionQueueInfo(anyObject(), anyObject())).andReturn(Collections.emptyList()) - .anyTimes(); - - AuditedSecurityOperation security = PowerMock.createNiceMock(AuditedSecurityOperation.class); - - PowerMock.replayAll(); - - var coordinator = new TestCoordinator(finalizer, tservers, client, tsc, context, security); - coordinator.resetInternals(); - assertEquals(0, coordinator.getQueues().size()); - assertEquals(0, coordinator.getIndex().size()); - assertEquals(0, coordinator.getRunning().size()); - coordinator.run(); - assertEquals(0, coordinator.getQueues().size()); - assertEquals(0, coordinator.getIndex().size()); - assertEquals(0, coordinator.getRunning().size()); - - PowerMock.verifyAll(); - coordinator.resetInternals(); - coordinator.close(); - } - - @Test - public void testCoordinatorColdStart() throws Exception { - PowerMock.resetAll(); - PowerMock.suppress(PowerMock.constructor(AbstractServer.class)); - PowerMock.suppress(PowerMock.methods(ThriftUtil.class, "returnClient")); - PowerMock.suppress(PowerMock.methods(DeadCompactionDetector.class, "detectDeadCompactions", - "detectDanglingFinalStateMarkers")); - - ServerContext context = PowerMock.createNiceMock(ServerContext.class); - expect(context.getConfiguration()).andReturn(DefaultConfiguration.getInstance()).anyTimes(); - - TCredentials creds = PowerMock.createNiceMock(TCredentials.class); - expect(context.rpcCreds()).andReturn(creds); - - PowerMock.mockStatic(ExternalCompactionUtil.class); - List<RunningCompaction> runningCompactions = new ArrayList<>(); - expect(ExternalCompactionUtil.getCompactionsRunningOnCompactors(context)) - .andReturn(runningCompactions); - - CompactionFinalizer finalizer = PowerMock.createNiceMock(CompactionFinalizer.class); - LiveTServerSet tservers = PowerMock.createNiceMock(LiveTServerSet.class); - TServerInstance instance = PowerMock.createNiceMock(TServerInstance.class); - expect(tservers.getCurrentServers()).andReturn(Collections.singleton(instance)).once(); - - ServerAddress client = PowerMock.createNiceMock(ServerAddress.class); - HostAndPort address = HostAndPort.fromString("localhost:10240"); - expect(client.getAddress()).andReturn(address).anyTimes(); - - TServerInstance tsi = PowerMock.createNiceMock(TServerInstance.class); - expect(tsi.getHostPort()).andReturn("localhost:9997").anyTimes(); - - TabletServerClientService.Client tsc = - PowerMock.createNiceMock(TabletServerClientService.Client.class); - TCompactionQueueSummary queueSummary = PowerMock.createNiceMock(TCompactionQueueSummary.class); - expect(tsc.getCompactionQueueInfo(anyObject(), anyObject())) - .andReturn(Collections.singletonList(queueSummary)).anyTimes(); - expect(queueSummary.getQueue()).andReturn("R2DQ").anyTimes(); - expect(queueSummary.getPriority()).andReturn((short) 1).anyTimes(); - - AuditedSecurityOperation security = PowerMock.createNiceMock(AuditedSecurityOperation.class); - - PowerMock.replayAll(); - - var coordinator = new TestCoordinator(finalizer, tservers, client, tsc, context, security); - coordinator.resetInternals(); - assertEquals(0, coordinator.getQueues().size()); - assertEquals(0, coordinator.getIndex().size()); - assertEquals(0, coordinator.getRunning().size()); - coordinator.run(); - assertEquals(1, coordinator.getQueues().size()); - QueueAndPriority qp = QueueAndPriority.get("R2DQ".intern(), (short) 1); - Map<Short,TreeSet<TServerInstance>> m = coordinator.getQueues().get("R2DQ".intern()); - assertNotNull(m); - assertEquals(1, m.size()); - assertTrue(m.containsKey((short) 1)); - Set<TServerInstance> t = m.get((short) 1); - assertNotNull(t); - assertEquals(1, t.size()); - TServerInstance queuedTsi = t.iterator().next(); - assertEquals(tsi.getHostPortSession(), queuedTsi.getHostPortSession()); - assertEquals(1, coordinator.getIndex().size()); - assertTrue(coordinator.getIndex().containsKey(queuedTsi)); - Set<QueueAndPriority> i = coordinator.getIndex().get(queuedTsi); - assertEquals(1, i.size()); - assertEquals(qp, i.iterator().next()); - assertEquals(0, coordinator.getRunning().size()); - - PowerMock.verifyAll(); - coordinator.resetInternals(); - coordinator.close(); - } - - @Test - public void testCoordinatorRestartNoRunningCompactions() throws Exception { - PowerMock.resetAll(); - PowerMock.suppress(PowerMock.constructor(AbstractServer.class)); - PowerMock.suppress(PowerMock.methods(ThriftUtil.class, "returnClient")); - PowerMock.suppress(PowerMock.methods(DeadCompactionDetector.class, "detectDeadCompactions", - "detectDanglingFinalStateMarkers")); - - ServerContext context = PowerMock.createNiceMock(ServerContext.class); - expect(context.getConfiguration()).andReturn(DefaultConfiguration.getInstance()).anyTimes(); - - TCredentials creds = PowerMock.createNiceMock(TCredentials.class); - expect(context.rpcCreds()).andReturn(creds); - - CompactionFinalizer finalizer = PowerMock.createNiceMock(CompactionFinalizer.class); - LiveTServerSet tservers = PowerMock.createNiceMock(LiveTServerSet.class); - TServerInstance instance = PowerMock.createNiceMock(TServerInstance.class); - HostAndPort tserverAddress = HostAndPort.fromString("localhost:9997"); - expect(instance.getHostAndPort()).andReturn(tserverAddress).anyTimes(); - expect(tservers.getCurrentServers()).andReturn(Sets.newHashSet(instance)).once(); - tservers.startListeningForTabletServerChanges(); - - PowerMock.mockStatic(ExternalCompactionUtil.class); - List<RunningCompaction> runningCompactions = new ArrayList<>(); - expect(ExternalCompactionUtil.getCompactionsRunningOnCompactors(context)) - .andReturn(runningCompactions); - - ServerAddress client = PowerMock.createNiceMock(ServerAddress.class); - HostAndPort address = HostAndPort.fromString("localhost:10240"); - expect(client.getAddress()).andReturn(address).anyTimes(); - - expect(instance.getHostPort()).andReturn("localhost:9997").anyTimes(); - - TabletServerClientService.Client tsc = - PowerMock.createNiceMock(TabletServerClientService.Client.class); - TCompactionQueueSummary queueSummary = PowerMock.createNiceMock(TCompactionQueueSummary.class); - expect(tsc.getCompactionQueueInfo(anyObject(), anyObject())) - .andReturn(Collections.singletonList(queueSummary)).anyTimes(); - expect(queueSummary.getQueue()).andReturn("R2DQ").anyTimes(); - expect(queueSummary.getPriority()).andReturn((short) 1).anyTimes(); - - AuditedSecurityOperation security = PowerMock.createNiceMock(AuditedSecurityOperation.class); - - PowerMock.replayAll(); - - var coordinator = new TestCoordinator(finalizer, tservers, client, tsc, context, security); - coordinator.resetInternals(); - assertEquals(0, coordinator.getQueues().size()); - assertEquals(0, coordinator.getIndex().size()); - assertEquals(0, coordinator.getRunning().size()); - coordinator.run(); - assertEquals(1, coordinator.getQueues().size()); - QueueAndPriority qp = QueueAndPriority.get("R2DQ".intern(), (short) 1); - Map<Short,TreeSet<TServerInstance>> m = coordinator.getQueues().get("R2DQ".intern()); - assertNotNull(m); - assertEquals(1, m.size()); - assertTrue(m.containsKey((short) 1)); - Set<TServerInstance> t = m.get((short) 1); - assertNotNull(t); - assertEquals(1, t.size()); - TServerInstance queuedTsi = t.iterator().next(); - assertEquals(instance.getHostPortSession(), queuedTsi.getHostPortSession()); - assertEquals(1, coordinator.getIndex().size()); - assertTrue(coordinator.getIndex().containsKey(queuedTsi)); - Set<QueueAndPriority> i = coordinator.getIndex().get(queuedTsi); - assertEquals(1, i.size()); - assertEquals(qp, i.iterator().next()); - assertEquals(0, coordinator.getRunning().size()); - - PowerMock.verifyAll(); - coordinator.resetInternals(); - coordinator.close(); - } - - @Test - public void testCoordinatorRestartOneRunningCompaction() throws Exception { - - PowerMock.resetAll(); - PowerMock.suppress(PowerMock.constructor(AbstractServer.class)); - PowerMock.suppress(PowerMock.methods(ThriftUtil.class, "returnClient")); - PowerMock.suppress(PowerMock.methods(DeadCompactionDetector.class, "detectDeadCompactions", - "detectDanglingFinalStateMarkers")); - - ServerContext context = PowerMock.createNiceMock(ServerContext.class); - expect(context.getConfiguration()).andReturn(DefaultConfiguration.getInstance()).anyTimes(); - - TCredentials creds = PowerMock.createNiceMock(TCredentials.class); - expect(context.rpcCreds()).andReturn(creds); - - CompactionFinalizer finalizer = PowerMock.createNiceMock(CompactionFinalizer.class); - LiveTServerSet tservers = PowerMock.createNiceMock(LiveTServerSet.class); - TServerInstance instance = PowerMock.createNiceMock(TServerInstance.class); - HostAndPort tserverAddress = HostAndPort.fromString("localhost:9997"); - expect(instance.getHostAndPort()).andReturn(tserverAddress).anyTimes(); - expect(tservers.getCurrentServers()).andReturn(Sets.newHashSet(instance)).once(); - tservers.startListeningForTabletServerChanges(); - - PowerMock.mockStatic(ExternalCompactionUtil.class); - List<RunningCompaction> runningCompactions = new ArrayList<>(); - ExternalCompactionId eci = ExternalCompactionId.generate(UUID.randomUUID()); - TExternalCompactionJob job = PowerMock.createNiceMock(TExternalCompactionJob.class); - expect(job.getExternalCompactionId()).andReturn(eci.toString()).anyTimes(); - TKeyExtent extent = new TKeyExtent(); - extent.setTable("1".getBytes()); - runningCompactions.add(new RunningCompaction(job, tserverAddress.toString(), "queue")); - expect(ExternalCompactionUtil.getCompactionsRunningOnCompactors(context)) - .andReturn(runningCompactions); - - ServerAddress client = PowerMock.createNiceMock(ServerAddress.class); - HostAndPort address = HostAndPort.fromString("localhost:10240"); - expect(client.getAddress()).andReturn(address).anyTimes(); - - expect(instance.getHostPort()).andReturn("localhost:9997").anyTimes(); - - TabletServerClientService.Client tsc = - PowerMock.createNiceMock(TabletServerClientService.Client.class); - TCompactionQueueSummary queueSummary = PowerMock.createNiceMock(TCompactionQueueSummary.class); - expect(tsc.getCompactionQueueInfo(anyObject(), anyObject())) - .andReturn(Collections.singletonList(queueSummary)).anyTimes(); - expect(queueSummary.getQueue()).andReturn("R2DQ").anyTimes(); - expect(queueSummary.getPriority()).andReturn((short) 1).anyTimes(); - - AuditedSecurityOperation security = PowerMock.createNiceMock(AuditedSecurityOperation.class); - - PowerMock.replayAll(); - - var coordinator = new TestCoordinator(finalizer, tservers, client, tsc, context, security); - coordinator.resetInternals(); - assertEquals(0, coordinator.getQueues().size()); - assertEquals(0, coordinator.getIndex().size()); - assertEquals(0, coordinator.getRunning().size()); - coordinator.run(); - assertEquals(1, coordinator.getQueues().size()); - QueueAndPriority qp = QueueAndPriority.get("R2DQ".intern(), (short) 1); - Map<Short,TreeSet<TServerInstance>> m = coordinator.getQueues().get("R2DQ".intern()); - assertNotNull(m); - assertEquals(1, m.size()); - assertTrue(m.containsKey((short) 1)); - Set<TServerInstance> t = m.get((short) 1); - assertNotNull(t); - assertEquals(1, t.size()); - TServerInstance queuedTsi = t.iterator().next(); - assertEquals(instance.getHostPortSession(), queuedTsi.getHostPortSession()); - assertEquals(1, coordinator.getIndex().size()); - assertTrue(coordinator.getIndex().containsKey(queuedTsi)); - Set<QueueAndPriority> i = coordinator.getIndex().get(queuedTsi); - assertEquals(1, i.size()); - assertEquals(qp, i.iterator().next()); - assertEquals(1, coordinator.getRunning().size()); - - PowerMock.verifyAll(); - coordinator.resetInternals(); - coordinator.close(); - } - - @Test - public void testGetCompactionJob() throws Exception { - PowerMock.resetAll(); - PowerMock.suppress(PowerMock.constructor(AbstractServer.class)); - PowerMock.suppress(PowerMock.methods(ThriftUtil.class, "returnClient")); - PowerMock.suppress(PowerMock.methods(DeadCompactionDetector.class, "detectDeadCompactions", - "detectDanglingFinalStateMarkers")); - - ServerContext context = PowerMock.createNiceMock(ServerContext.class); - expect(context.getConfiguration()).andReturn(DefaultConfiguration.getInstance()).anyTimes(); - - TCredentials creds = PowerMock.createNiceMock(TCredentials.class); - expect(context.rpcCreds()).andReturn(creds).anyTimes(); - - PowerMock.mockStatic(ExternalCompactionUtil.class); - List<RunningCompaction> runningCompactions = new ArrayList<>(); - expect(ExternalCompactionUtil.getCompactionsRunningOnCompactors(context)) - .andReturn(runningCompactions); - - CompactionFinalizer finalizer = PowerMock.createNiceMock(CompactionFinalizer.class); - LiveTServerSet tservers = PowerMock.createNiceMock(LiveTServerSet.class); - TServerInstance instance = PowerMock.createNiceMock(TServerInstance.class); - expect(tservers.getCurrentServers()).andReturn(Collections.singleton(instance)).once(); - HostAndPort tserverAddress = HostAndPort.fromString("localhost:9997"); - expect(instance.getHostAndPort()).andReturn(tserverAddress).anyTimes(); - - ServerAddress client = PowerMock.createNiceMock(ServerAddress.class); - HostAndPort address = HostAndPort.fromString("localhost:10240"); - expect(client.getAddress()).andReturn(address).anyTimes(); - - TServerInstance tsi = PowerMock.createNiceMock(TServerInstance.class); - expect(tsi.getHostPort()).andReturn("localhost:9997").anyTimes(); - - TabletServerClientService.Client tsc = - PowerMock.createNiceMock(TabletServerClientService.Client.class); - TCompactionQueueSummary queueSummary = PowerMock.createNiceMock(TCompactionQueueSummary.class); - expect(tsc.getCompactionQueueInfo(anyObject(), anyObject())) - .andReturn(Collections.singletonList(queueSummary)).anyTimes(); - expect(queueSummary.getQueue()).andReturn("R2DQ").anyTimes(); - expect(queueSummary.getPriority()).andReturn((short) 1).anyTimes(); - - ExternalCompactionId eci = ExternalCompactionId.generate(UUID.randomUUID()); - TExternalCompactionJob job = PowerMock.createNiceMock(TExternalCompactionJob.class); - expect(job.getExternalCompactionId()).andReturn(eci.toString()).anyTimes(); - TInfo trace = TraceUtil.traceInfo(); - expect(tsc.reserveCompactionJob(trace, creds, "R2DQ", 1, "localhost:10241", eci.toString())) - .andReturn(job).anyTimes(); - - AuditedSecurityOperation security = PowerMock.createNiceMock(AuditedSecurityOperation.class); - expect(security.canPerformSystemActions(creds)).andReturn(true); - - PowerMock.replayAll(); - - var coordinator = new TestCoordinator(finalizer, tservers, client, tsc, context, security); - coordinator.resetInternals(); - assertEquals(0, coordinator.getQueues().size()); - assertEquals(0, coordinator.getIndex().size()); - assertEquals(0, coordinator.getRunning().size()); - // Use coordinator.run() to populate the internal data structures. This is tested in a different - // test. - coordinator.run(); - - assertEquals(1, coordinator.getQueues().size()); - QueueAndPriority qp = QueueAndPriority.get("R2DQ".intern(), (short) 1); - Map<Short,TreeSet<TServerInstance>> m = coordinator.getQueues().get("R2DQ".intern()); - assertNotNull(m); - assertEquals(1, m.size()); - assertTrue(m.containsKey((short) 1)); - Set<TServerInstance> t = m.get((short) 1); - assertNotNull(t); - assertEquals(1, t.size()); - TServerInstance queuedTsi = t.iterator().next(); - assertEquals(tsi.getHostPortSession(), queuedTsi.getHostPortSession()); - assertEquals(1, coordinator.getIndex().size()); - assertTrue(coordinator.getIndex().containsKey(queuedTsi)); - Set<QueueAndPriority> i = coordinator.getIndex().get(queuedTsi); - assertEquals(1, i.size()); - assertEquals(qp, i.iterator().next()); - assertEquals(0, coordinator.getRunning().size()); - - // Get the next job - TExternalCompactionJob createdJob = - coordinator.getCompactionJob(trace, creds, "R2DQ", "localhost:10241", eci.toString()); - assertEquals(eci.toString(), createdJob.getExternalCompactionId()); - - assertEquals(1, coordinator.getQueues().size()); - assertEquals(1, coordinator.getIndex().size()); - assertEquals(1, coordinator.getRunning().size()); - Entry<ExternalCompactionId,RunningCompaction> entry = - coordinator.getRunning().entrySet().iterator().next(); - assertEquals(eci.toString(), entry.getKey().toString()); - assertEquals("localhost:10241", entry.getValue().getCompactorAddress()); - assertEquals(eci.toString(), entry.getValue().getJob().getExternalCompactionId()); - - PowerMock.verifyAll(); - coordinator.resetInternals(); - coordinator.close(); - - } - - @Test - public void testGetCompactionJobNoJobs() throws Exception { - PowerMock.resetAll(); - PowerMock.suppress(PowerMock.constructor(AbstractServer.class)); - - ServerContext context = PowerMock.createNiceMock(ServerContext.class); - expect(context.getConfiguration()).andReturn(DefaultConfiguration.getInstance()).anyTimes(); - - TCredentials creds = PowerMock.createNiceMock(TCredentials.class); - - CompactionFinalizer finalizer = PowerMock.createNiceMock(CompactionFinalizer.class); - LiveTServerSet tservers = PowerMock.createNiceMock(LiveTServerSet.class); - - ServerAddress client = PowerMock.createNiceMock(ServerAddress.class); - HostAndPort address = HostAndPort.fromString("localhost:10240"); - expect(client.getAddress()).andReturn(address).anyTimes(); - - TabletServerClientService.Client tsc = - PowerMock.createNiceMock(TabletServerClientService.Client.class); - - AuditedSecurityOperation security = PowerMock.createNiceMock(AuditedSecurityOperation.class); - expect(security.canPerformSystemActions(creds)).andReturn(true); - - PowerMock.replayAll(); - - var coordinator = new TestCoordinator(finalizer, tservers, client, tsc, context, security); - coordinator.resetInternals(); - TExternalCompactionJob job = coordinator.getCompactionJob(TraceUtil.traceInfo(), creds, "R2DQ", - "localhost:10240", UUID.randomUUID().toString()); - assertNull(job.getExternalCompactionId()); - - PowerMock.verifyAll(); - coordinator.resetInternals(); - coordinator.close(); - } - - @Test - public void testCleanUpRunning() throws Exception { - PowerMock.resetAll(); - PowerMock.suppress(PowerMock.constructor(AbstractServer.class)); - - ServerContext context = PowerMock.createNiceMock(ServerContext.class); - expect(context.getConfiguration()).andReturn(DefaultConfiguration.getInstance()).anyTimes(); - - TCredentials creds = PowerMock.createNiceMock(TCredentials.class); - - CompactionFinalizer finalizer = PowerMock.createNiceMock(CompactionFinalizer.class); - LiveTServerSet tservers = PowerMock.createNiceMock(LiveTServerSet.class); - - ServerAddress client = PowerMock.createNiceMock(ServerAddress.class); - HostAndPort address = HostAndPort.fromString("localhost:10240"); - expect(client.getAddress()).andReturn(address).anyTimes(); - - TabletServerClientService.Client tsc = - PowerMock.createNiceMock(TabletServerClientService.Client.class); - - AuditedSecurityOperation security = PowerMock.createNiceMock(AuditedSecurityOperation.class); - expect(security.canPerformSystemActions(creds)).andReturn(true); - - PowerMock.replayAll(); - - try (var coordinator = - new TestCoordinator(finalizer, tservers, client, tsc, context, security)) { - coordinator.resetInternals(); - - var ecid1 = ExternalCompactionId.generate(UUID.randomUUID()); - var ecid2 = ExternalCompactionId.generate(UUID.randomUUID()); - var ecid3 = ExternalCompactionId.generate(UUID.randomUUID()); - - coordinator.getRunning().put(ecid1, new RunningCompaction(new TExternalCompaction())); - coordinator.getRunning().put(ecid2, new RunningCompaction(new TExternalCompaction())); - coordinator.getRunning().put(ecid3, new RunningCompaction(new TExternalCompaction())); - - coordinator.cleanUpRunning(); - - assertEquals(Set.of(ecid1, ecid2, ecid3), coordinator.getRunning().keySet()); - - coordinator.setMetadataCompactionIds(Set.of(ecid1, ecid2)); - - coordinator.cleanUpRunning(); - - assertEquals(Set.of(ecid1, ecid2), coordinator.getRunning().keySet()); - } - } -} diff --git a/server/compactor/pom.xml b/server/compactor/pom.xml index efa5026c5e..a65974abe0 100644 --- a/server/compactor/pom.xml +++ b/server/compactor/pom.xml @@ -75,30 +75,5 @@ <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> </dependency> - <dependency> - <groupId>org.apache.logging.log4j</groupId> - <artifactId>log4j-slf4j2-impl</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.easymock</groupId> - <artifactId>easymock</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.junit.vintage</groupId> - <artifactId>junit-vintage-engine</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.powermock</groupId> - <artifactId>powermock-api-easymock</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.powermock</groupId> - <artifactId>powermock-module-junit4</artifactId> - <scope>test</scope> - </dependency> </dependencies> </project> diff --git a/server/compactor/src/test/java/org/apache/accumulo/compactor/CompactorTest.java b/server/compactor/src/test/java/org/apache/accumulo/compactor/CompactorTest.java deleted file mode 100644 index e61f9f1903..0000000000 --- a/server/compactor/src/test/java/org/apache/accumulo/compactor/CompactorTest.java +++ /dev/null @@ -1,455 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.accumulo.compactor; - -import static org.easymock.EasyMock.expect; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.net.UnknownHostException; -import java.util.Timer; -import java.util.TimerTask; -import java.util.UUID; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.atomic.AtomicReference; -import java.util.concurrent.atomic.LongAdder; -import java.util.function.Supplier; - -import org.apache.accumulo.core.cli.ConfigOpts; -import org.apache.accumulo.core.compaction.thrift.TCompactionState; -import org.apache.accumulo.core.compaction.thrift.TCompactionStatusUpdate; -import org.apache.accumulo.core.conf.AccumuloConfiguration; -import org.apache.accumulo.core.conf.ConfigurationCopy; -import org.apache.accumulo.core.conf.DefaultConfiguration; -import org.apache.accumulo.core.conf.Property; -import org.apache.accumulo.core.dataImpl.thrift.TKeyExtent; -import org.apache.accumulo.core.fate.zookeeper.ZooReaderWriter; -import org.apache.accumulo.core.metadata.schema.ExternalCompactionId; -import org.apache.accumulo.core.tabletserver.thrift.TCompactionStats; -import org.apache.accumulo.core.tabletserver.thrift.TExternalCompactionJob; -import org.apache.accumulo.core.util.Halt; -import org.apache.accumulo.core.util.UtilWaitThread; -import org.apache.accumulo.server.AbstractServer; -import org.apache.accumulo.server.ServerContext; -import org.apache.accumulo.server.compaction.RetryableThriftCall.RetriesExceededException; -import org.apache.accumulo.server.fs.VolumeManagerImpl; -import org.apache.accumulo.server.mem.LowMemoryDetector; -import org.apache.accumulo.server.rpc.ServerAddress; -import org.apache.zookeeper.KeeperException; -import org.apache.zookeeper.ZooKeeper; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.api.easymock.PowerMock; -import org.powermock.core.classloader.annotations.PowerMockIgnore; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor; -import org.powermock.modules.junit4.PowerMockRunner; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.net.HostAndPort; - -@RunWith(PowerMockRunner.class) -@PrepareForTest({Compactor.class}) -@SuppressStaticInitializationFor({"org.apache.log4j.LogManager"}) -@PowerMockIgnore({"org.slf4j.*", "org.apache.logging.*", "org.apache.log4j.*", - "org.apache.commons.logging.*", "org.xml.*", "javax.xml.*", "org.w3c.dom.*", - "com.sun.org.apache.xerces.*"}) -public class CompactorTest { - - public class SuccessfulCompaction implements Runnable { - - protected final Logger LOG = LoggerFactory.getLogger(this.getClass()); - - protected final LongAdder totalInputEntries; - protected final LongAdder totalInputBytes; - protected final CountDownLatch started; - protected final CountDownLatch stopped; - protected final AtomicReference<Throwable> err; - - public SuccessfulCompaction(LongAdder totalInputEntries, LongAdder totalInputBytes, - CountDownLatch started, CountDownLatch stopped, AtomicReference<Throwable> err) { - this.totalInputEntries = totalInputEntries; - this.totalInputBytes = totalInputBytes; - this.err = err; - this.started = started; - this.stopped = stopped; - } - - @Override - public void run() { - try { - started.countDown(); - UtilWaitThread.sleep(1000); - } catch (Exception e) { - err.set(e); - } finally { - stopped.countDown(); - } - } - } - - public class FailedCompaction extends SuccessfulCompaction { - - public FailedCompaction(LongAdder totalInputEntries, LongAdder totalInputBytes, - CountDownLatch started, CountDownLatch stopped, AtomicReference<Throwable> err) { - super(totalInputEntries, totalInputBytes, started, stopped, err); - } - - @Override - public void run() { - try { - started.countDown(); - UtilWaitThread.sleep(1000); - throw new RuntimeException(); - } catch (Exception e) { - err.set(e); - } finally { - stopped.countDown(); - } - } - } - - public class InterruptedCompaction extends SuccessfulCompaction { - - public InterruptedCompaction(LongAdder totalInputEntries, LongAdder totalInputBytes, - CountDownLatch started, CountDownLatch stopped, AtomicReference<Throwable> err) { - super(totalInputEntries, totalInputBytes, started, stopped, err); - } - - @Override - public void run() { - try { - started.countDown(); - final Thread thread = Thread.currentThread(); - Timer t = new Timer(); - TimerTask task = new TimerTask() { - @Override - public void run() { - thread.interrupt(); - } - }; - t.schedule(task, 250); - Thread.sleep(1000); - } catch (Exception e) { - LOG.error("Compaction failed: {}", e.getMessage()); - err.set(e); - throw new RuntimeException("Compaction failed", e); - } finally { - stopped.countDown(); - } - } - - } - - public class SuccessfulCompactor extends Compactor { - - private final Logger LOG = LoggerFactory.getLogger(SuccessfulCompactor.class); - - private final Supplier<UUID> uuid; - private final ServerAddress address; - private final TExternalCompactionJob job; - private final ServerContext context; - private final ExternalCompactionId eci; - private volatile boolean completedCalled = false; - private volatile boolean failedCalled = false; - private TCompactionStatusUpdate latestState = null; - - SuccessfulCompactor(Supplier<UUID> uuid, ServerAddress address, TExternalCompactionJob job, - ServerContext context, ExternalCompactionId eci) { - super(new ConfigOpts(), - new String[] {"-o", Property.COMPACTOR_QUEUE_NAME.getKey() + "=testQ"}, - context.getConfiguration()); - this.uuid = uuid; - this.address = address; - this.job = job; - this.context = context; - this.eci = eci; - } - - @Override - public AccumuloConfiguration getConfiguration() { - return context.getConfiguration(); - } - - @Override - protected void setupSecurity() {} - - @Override - protected void printStartupMsg() {} - - @Override - public ServerContext getContext() { - return this.context; - } - - @Override - protected void announceExistence(HostAndPort clientAddress) - throws KeeperException, InterruptedException {} - - @Override - protected ServerAddress startCompactorClientService() throws UnknownHostException { - return this.address; - } - - @Override - protected TExternalCompactionJob getNextJob(Supplier<UUID> uuid) - throws RetriesExceededException { - LOG.info("Attempting to get next job, eci = {}", eci); - currentCompactionId.set(eci); - this.shutdown = true; - return job; - } - - @Override - protected synchronized void checkIfCanceled() {} - - @Override - protected Runnable createCompactionJob(TExternalCompactionJob job, LongAdder totalInputEntries, - LongAdder totalInputBytes, CountDownLatch started, CountDownLatch stopped, - AtomicReference<Throwable> err) { - return new SuccessfulCompaction(totalInputEntries, totalInputBytes, started, stopped, err); - } - - @Override - protected Supplier<UUID> getNextId() { - return uuid; - } - - @Override - protected void updateCompactionState(TExternalCompactionJob job, TCompactionStatusUpdate update) - throws RetriesExceededException { - latestState = update; - } - - @Override - protected void updateCompactionFailed(TExternalCompactionJob job) - throws RetriesExceededException { - failedCalled = true; - } - - @Override - protected void updateCompactionCompleted(TExternalCompactionJob job, TCompactionStats stats) - throws RetriesExceededException { - completedCalled = true; - } - - public TCompactionState getLatestState() { - return latestState.getState(); - } - - public boolean isCompletedCalled() { - return completedCalled; - } - - public boolean isFailedCalled() { - return failedCalled; - } - - } - - public class FailedCompactor extends SuccessfulCompactor { - - FailedCompactor(Supplier<UUID> uuid, ServerAddress address, TExternalCompactionJob job, - ServerContext context, ExternalCompactionId eci) { - super(uuid, address, job, context, eci); - } - - @Override - protected Runnable createCompactionJob(TExternalCompactionJob job, LongAdder totalInputEntries, - LongAdder totalInputBytes, CountDownLatch started, CountDownLatch stopped, - AtomicReference<Throwable> err) { - return new FailedCompaction(totalInputEntries, totalInputBytes, started, stopped, err); - } - } - - public class InterruptedCompactor extends SuccessfulCompactor { - - InterruptedCompactor(Supplier<UUID> uuid, ServerAddress address, TExternalCompactionJob job, - ServerContext context, ExternalCompactionId eci) { - super(uuid, address, job, context, eci); - } - - @Override - protected Runnable createCompactionJob(TExternalCompactionJob job, LongAdder totalInputEntries, - LongAdder totalInputBytes, CountDownLatch started, CountDownLatch stopped, - AtomicReference<Throwable> err) { - return new InterruptedCompaction(totalInputEntries, totalInputBytes, started, stopped, err); - } - - } - - @Test - public void testCheckTime() throws Exception { - assertEquals(1, Compactor.calculateProgressCheckTime(1024)); - assertEquals(1, Compactor.calculateProgressCheckTime(1048576)); - assertEquals(1, Compactor.calculateProgressCheckTime(10485760)); - assertEquals(10, Compactor.calculateProgressCheckTime(104857600)); - assertEquals(102, Compactor.calculateProgressCheckTime(1024 * 1024 * 1024)); - } - - @Test - public void testCompactionSucceeds() throws Exception { - UUID uuid = UUID.randomUUID(); - Supplier<UUID> supplier = () -> uuid; - - ExternalCompactionId eci = ExternalCompactionId.generate(supplier.get()); - - PowerMock.resetAll(); - PowerMock.suppress(PowerMock.methods(Halt.class, "halt")); - PowerMock.suppress(PowerMock.constructor(AbstractServer.class)); - - ServerAddress client = PowerMock.createNiceMock(ServerAddress.class); - HostAndPort address = HostAndPort.fromString("localhost:10240"); - expect(client.getAddress()).andReturn(address); - - TExternalCompactionJob job = PowerMock.createNiceMock(TExternalCompactionJob.class); - TKeyExtent extent = PowerMock.createNiceMock(TKeyExtent.class); - expect(job.isSetExternalCompactionId()).andReturn(true).anyTimes(); - expect(job.getExternalCompactionId()).andReturn(eci.toString()).anyTimes(); - expect(job.getExtent()).andReturn(extent).anyTimes(); - expect(extent.getTable()).andReturn("testTable".getBytes()).anyTimes(); - - var conf = new ConfigurationCopy(DefaultConfiguration.getInstance()); - conf.set(Property.INSTANCE_ZK_TIMEOUT, "1d"); - - ServerContext context = PowerMock.createNiceMock(ServerContext.class); - expect(context.getConfiguration()).andReturn(conf).anyTimes(); - expect(context.getLowMemoryDetector()).andReturn(new LowMemoryDetector()).anyTimes(); - ZooReaderWriter zrw = PowerMock.createNiceMock(ZooReaderWriter.class); - ZooKeeper zk = PowerMock.createNiceMock(ZooKeeper.class); - expect(context.getZooReaderWriter()).andReturn(zrw).anyTimes(); - expect(zrw.getZooKeeper()).andReturn(zk).anyTimes(); - VolumeManagerImpl vm = PowerMock.createNiceMock(VolumeManagerImpl.class); - expect(context.getVolumeManager()).andReturn(vm); - vm.close(); - - PowerMock.replayAll(); - - SuccessfulCompactor c = new SuccessfulCompactor(supplier, client, job, context, eci); - c.run(); - - PowerMock.verifyAll(); - c.close(); - - assertTrue(c.isCompletedCalled()); - assertFalse(c.isFailedCalled()); - } - - @Test - public void testCompactionFails() throws Exception { - UUID uuid = UUID.randomUUID(); - Supplier<UUID> supplier = () -> uuid; - - ExternalCompactionId eci = ExternalCompactionId.generate(supplier.get()); - - PowerMock.resetAll(); - PowerMock.suppress(PowerMock.methods(Halt.class, "halt")); - PowerMock.suppress(PowerMock.constructor(AbstractServer.class)); - - ServerAddress client = PowerMock.createNiceMock(ServerAddress.class); - HostAndPort address = HostAndPort.fromString("localhost:10240"); - expect(client.getAddress()).andReturn(address); - - TExternalCompactionJob job = PowerMock.createNiceMock(TExternalCompactionJob.class); - TKeyExtent extent = PowerMock.createNiceMock(TKeyExtent.class); - expect(extent.getTable()).andReturn("testTable".getBytes()).anyTimes(); - - expect(job.isSetExternalCompactionId()).andReturn(true).anyTimes(); - expect(job.getExternalCompactionId()).andReturn(eci.toString()).anyTimes(); - expect(job.getExtent()).andReturn(extent).anyTimes(); - - var conf = new ConfigurationCopy(DefaultConfiguration.getInstance()); - conf.set(Property.INSTANCE_ZK_TIMEOUT, "1d"); - - ServerContext context = PowerMock.createNiceMock(ServerContext.class); - expect(context.getConfiguration()).andReturn(conf).anyTimes(); - expect(context.getLowMemoryDetector()).andReturn(new LowMemoryDetector()).anyTimes(); - ZooReaderWriter zrw = PowerMock.createNiceMock(ZooReaderWriter.class); - ZooKeeper zk = PowerMock.createNiceMock(ZooKeeper.class); - expect(context.getZooReaderWriter()).andReturn(zrw).anyTimes(); - expect(zrw.getZooKeeper()).andReturn(zk).anyTimes(); - VolumeManagerImpl vm = PowerMock.createNiceMock(VolumeManagerImpl.class); - expect(context.getVolumeManager()).andReturn(vm); - vm.close(); - - PowerMock.replayAll(); - - FailedCompactor c = new FailedCompactor(supplier, client, job, context, eci); - c.run(); - - PowerMock.verifyAll(); - c.close(); - - assertFalse(c.isCompletedCalled()); - assertTrue(c.isFailedCalled()); - assertEquals(TCompactionState.FAILED, c.getLatestState()); - } - - @Test - public void testCompactionInterrupted() throws Exception { - UUID uuid = UUID.randomUUID(); - Supplier<UUID> supplier = () -> uuid; - - ExternalCompactionId eci = ExternalCompactionId.generate(supplier.get()); - - PowerMock.resetAll(); - PowerMock.suppress(PowerMock.methods(Halt.class, "halt")); - PowerMock.suppress(PowerMock.constructor(AbstractServer.class)); - - ServerAddress client = PowerMock.createNiceMock(ServerAddress.class); - HostAndPort address = HostAndPort.fromString("localhost:10240"); - expect(client.getAddress()).andReturn(address); - - TExternalCompactionJob job = PowerMock.createNiceMock(TExternalCompactionJob.class); - TKeyExtent extent = PowerMock.createNiceMock(TKeyExtent.class); - expect(job.isSetExternalCompactionId()).andReturn(true).anyTimes(); - expect(job.getExternalCompactionId()).andReturn(eci.toString()).anyTimes(); - expect(job.getExtent()).andReturn(extent).anyTimes(); - expect(extent.getTable()).andReturn("testTable".getBytes()).anyTimes(); - - var conf = new ConfigurationCopy(DefaultConfiguration.getInstance()); - conf.set(Property.INSTANCE_ZK_TIMEOUT, "1d"); - - ServerContext context = PowerMock.createNiceMock(ServerContext.class); - expect(context.getConfiguration()).andReturn(conf).anyTimes(); - expect(context.getLowMemoryDetector()).andReturn(new LowMemoryDetector()).anyTimes(); - ZooReaderWriter zrw = PowerMock.createNiceMock(ZooReaderWriter.class); - ZooKeeper zk = PowerMock.createNiceMock(ZooKeeper.class); - expect(context.getZooReaderWriter()).andReturn(zrw).anyTimes(); - expect(zrw.getZooKeeper()).andReturn(zk).anyTimes(); - VolumeManagerImpl vm = PowerMock.createNiceMock(VolumeManagerImpl.class); - expect(context.getVolumeManager()).andReturn(vm); - vm.close(); - - PowerMock.replayAll(); - - InterruptedCompactor c = new InterruptedCompactor(supplier, client, job, context, eci); - c.run(); - - PowerMock.verifyAll(); - c.close(); - - assertFalse(c.isCompletedCalled()); - assertTrue(c.isFailedCalled()); - assertEquals(TCompactionState.CANCELLED, c.getLatestState()); - } - -} diff --git a/server/compactor/src/test/resources/log4j2-test.properties b/server/compactor/src/test/resources/log4j2-test.properties deleted file mode 100644 index f3095a1452..0000000000 --- a/server/compactor/src/test/resources/log4j2-test.properties +++ /dev/null @@ -1,35 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# - -status = info -dest = err -name = AccumuloCoreTestLoggingProperties - -appender.console.type = Console -appender.console.name = STDOUT -appender.console.target = SYSTEM_OUT -appender.console.layout.type = PatternLayout -appender.console.layout.pattern = [%t] %-5p %c %x - %m%n - -#logger.01.name = org.apache.accumulo.core.iterators.system.VisibilityFilter -#logger.01.level = fatal - -rootLogger.level = info -rootLogger.appenderRef.console.ref = STDOUT - diff --git a/server/native/pom.xml b/server/native/pom.xml index c47edace4b..1ac0de4e04 100644 --- a/server/native/pom.xml +++ b/server/native/pom.xml @@ -45,11 +45,6 @@ <artifactId>log4j-slf4j2-impl</artifactId> <scope>test</scope> </dependency> - <dependency> - <groupId>org.junit.vintage</groupId> - <artifactId>junit-vintage-engine</artifactId> - <scope>test</scope> - </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> diff --git a/src/build/ci/find-unapproved-junit.sh b/src/build/ci/find-unapproved-junit.sh index 39e6102c67..da8ac47cb0 100755 --- a/src/build/ci/find-unapproved-junit.sh +++ b/src/build/ci/find-unapproved-junit.sh @@ -23,8 +23,6 @@ # APIs to new jupiter tests. NUM_EXPECTED=0 ALLOWED=( - server/compaction-coordinator/src/test/java/org/apache/accumulo/coordinator/CompactionCoordinatorTest.java - server/compactor/src/test/java/org/apache/accumulo/compactor/CompactorTest.java ) ALLOWED_PIPE_SEP=$({ for x in "${ALLOWED[@]}"; do echo "$x"; done; } | paste -sd'|') @@ -38,8 +36,10 @@ function findalljunitproblems() { fi # find any new classes using something other than the jupiter API, except those allowed grep "$opts" --include='*.java' 'org[.]junit[.](?!jupiter)' | grep -Pv "^(${ALLOWED_PIPE_SEP//./[.]})\$" - # find any uses of the jupiter API in the allowed vintage classes - grep "$opts" 'org[.]junit[.]jupiter' "${ALLOWED[@]}" + if ((${#ALLOWED[@]} != 0)); then + # find any uses of the jupiter API in the allowed vintage classes + grep "$opts" 'org[.]junit[.]jupiter' "${ALLOWED[@]}" + fi } function comparecounts() { diff --git a/start/pom.xml b/start/pom.xml index 5ae1458971..ad83eaed4f 100644 --- a/start/pom.xml +++ b/start/pom.xml @@ -54,16 +54,6 @@ <artifactId>log4j-slf4j2-impl</artifactId> <scope>test</scope> </dependency> - <dependency> - <groupId>org.junit.vintage</groupId> - <artifactId>junit-vintage-engine</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.powermock</groupId> - <artifactId>powermock-api-easymock</artifactId> - <scope>test</scope> - </dependency> </dependencies> <build> <pluginManagement>