You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by dl...@apache.org on 2021/04/06 16:21:21 UTC
[accumulo] branch 1451-external-compactions-feature updated: Added
unit test for Compactor
This is an automated email from the ASF dual-hosted git repository.
dlmarion pushed a commit to branch 1451-external-compactions-feature
in repository https://gitbox.apache.org/repos/asf/accumulo.git
The following commit(s) were added to refs/heads/1451-external-compactions-feature by this push:
new 8c7bf59 Added unit test for Compactor
8c7bf59 is described below
commit 8c7bf59b6445dfdf23df2a21012bdd2f480faf22
Author: Dave Marion <dl...@apache.org>
AuthorDate: Tue Apr 6 16:20:16 2021 +0000
Added unit test for Compactor
---
server/compactor/pom.xml | 36 ++
.../org/apache/accumulo/compactor/Compactor.java | 73 +++-
.../apache/accumulo/compactor/CompactorTest.java | 441 +++++++++++++++++++++
.../src/test/resources/log4j2-test.properties | 35 ++
4 files changed, 564 insertions(+), 21 deletions(-)
diff --git a/server/compactor/pom.xml b/server/compactor/pom.xml
index 2466190..e193175 100644
--- a/server/compactor/pom.xml
+++ b/server/compactor/pom.xml
@@ -36,8 +36,44 @@
<optional>true</optional>
</dependency>
<dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.apache.accumulo</groupId>
<artifactId>accumulo-server-base</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-1.2-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-slf4j-impl</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/main/java/org/apache/accumulo/compactor/Compactor.java b/server/compactor/src/main/java/org/apache/accumulo/compactor/Compactor.java
index 5bc0656..a7cb5b6 100644
--- a/server/compactor/src/main/java/org/apache/accumulo/compactor/Compactor.java
+++ b/server/compactor/src/main/java/org/apache/accumulo/compactor/Compactor.java
@@ -78,6 +78,7 @@ import org.apache.accumulo.server.compaction.RetryableThriftCall;
import org.apache.accumulo.server.compaction.RetryableThriftCall.RetriesExceededException;
import org.apache.accumulo.server.compaction.RetryableThriftFunction;
import org.apache.accumulo.server.conf.TableConfiguration;
+import org.apache.accumulo.server.fs.VolumeManager;
import org.apache.accumulo.server.rpc.ServerAddress;
import org.apache.accumulo.server.rpc.TCredentialsUpdatingWrapper;
import org.apache.accumulo.server.rpc.TServerUtils;
@@ -96,7 +97,7 @@ import com.beust.jcommander.Parameter;
public class Compactor extends AbstractServer
implements org.apache.accumulo.core.compaction.thrift.Compactor.Iface {
- private static class CompactorServerOpts extends ServerOpts {
+ static class CompactorServerOpts extends ServerOpts {
@Parameter(required = true, names = {"-q", "--queue"}, description = "compaction queue name")
private String queueName = null;
@@ -105,8 +106,6 @@ public class Compactor extends AbstractServer
}
}
- public static final String COMPACTOR_SERVICE = "COMPACTOR_SVC";
-
private static final Logger LOG = LoggerFactory.getLogger(Compactor.class);
private static final long TIME_BETWEEN_GC_CHECKS = 5000;
private static final CompactionJobHolder JOB_HOLDER = new CompactionJobHolder();
@@ -118,22 +117,37 @@ public class Compactor extends AbstractServer
private final String queueName;
private final AtomicReference<CompactionCoordinator.Client> coordinatorClient =
new AtomicReference<>();
- private final SecurityOperation security;
- private final AtomicReference<ExternalCompactionId> currentCompactionId = new AtomicReference<>();
+ protected final AtomicReference<ExternalCompactionId> currentCompactionId =
+ new AtomicReference<>();
+ private SecurityOperation security;
private ZooLock compactorLock;
private ServerAddress compactorAddress = null;
+ // Exposed for tests
+ protected volatile Boolean shutdown = false;
+
Compactor(CompactorServerOpts opts, String[] args) {
super("compactor", opts, args);
queueName = opts.getQueueName();
+ aconf = getConfiguration();
+ setupSecurity();
+ startGCLogger();
+ printStartupMsg();
+ }
+
+ private void setupSecurity() {
getContext().setupCrypto();
security = AuditedSecurityOperation.getInstance(getContext());
+ }
- aconf = getConfiguration();
+ private void startGCLogger() {
ThreadPools.createGeneralScheduledExecutorService(aconf).scheduleWithFixedDelay(
() -> gcLogger.logGCInfo(getConfiguration()), 0, TIME_BETWEEN_GC_CHECKS,
TimeUnit.MILLISECONDS);
+ }
+
+ private void printStartupMsg() {
LOG.info("Version " + Constants.VERSION);
LOG.info("Instance " + getContext().getInstanceID());
}
@@ -500,8 +514,15 @@ public class Compactor extends AbstractServer
* @param numBytes
* @return number of seconds to wait between progress checks
*/
- private long calculateProgressCheckTime(long numBytes) {
- return Math.max(1, (numBytes % TEN_MEGABYTES));
+ protected long calculateProgressCheckTime(long numBytes) {
+ return Math.max(1, (numBytes / TEN_MEGABYTES));
+ }
+
+ protected Supplier<UUID> getNextId() {
+ Supplier<UUID> supplier = () -> {
+ return UUID.randomUUID();
+ };
+ return supplier;
}
@Override
@@ -512,7 +533,7 @@ public class Compactor extends AbstractServer
} catch (UnknownHostException e1) {
throw new RuntimeException("Failed to start the compactor client service", e1);
}
- final HostAndPort clientAddress = compactorAddress.address;
+ final HostAndPort clientAddress = compactorAddress.getAddress();
try {
announceExistence(clientAddress);
@@ -525,17 +546,14 @@ public class Compactor extends AbstractServer
final AtomicReference<Throwable> err = new AtomicReference<>();
- while (true) {
+ while (!shutdown) {
currentCompactionId.set(null);
err.set(null);
JOB_HOLDER.reset();
TExternalCompactionJob job;
try {
- Supplier<UUID> supplier = () -> {
- return UUID.randomUUID();
- };
- job = getNextJob(supplier);
+ job = getNextJob(getNextId());
if (!job.isSetExternalCompactionId()) {
LOG.info("No external compactions in queue {}", this.queueName);
continue;
@@ -563,8 +581,8 @@ public class Compactor extends AbstractServer
JOB_HOLDER.set(job, compactionThread);
}
- compactionThread.start(); // start the compactionThread
try {
+ compactionThread.start(); // start the compactionThread
started.await(); // wait until the compactor is started
final long inputEntries = totalInputEntries.sum();
final long waitTime = calculateProgressCheckTime(totalInputBytes.sum());
@@ -587,6 +605,7 @@ public class Compactor extends AbstractServer
info.getEntriesWritten());
LOG.info(message);
try {
+ LOG.info("Updating coordinator with compaction progress: {}.", message);
updateCompactionState(job, CompactionState.IN_PROGRESS, message);
} catch (RetriesExceededException e) {
LOG.warn("Error updating coordinator with compaction progress, error: {}",
@@ -596,8 +615,10 @@ public class Compactor extends AbstractServer
}
}
compactionThread.join();
+ LOG.info("Compaction thread finished.");
- if (compactionThread.isInterrupted()) {
+ if (compactionThread.isInterrupted()
+ || ((err.get() != null && err.get().getClass().equals(InterruptedException.class)))) {
LOG.warn("Compaction thread was interrupted, sending CANCELLED state");
try {
updateCompactionState(job, CompactionState.CANCELLED, "Compaction cancelled");
@@ -609,6 +630,7 @@ public class Compactor extends AbstractServer
}
} else if (err.get() != null) {
try {
+ LOG.info("Updating coordinator with compaction failure.");
updateCompactionState(job, CompactionState.FAILED,
"Compaction failed due to: " + err.get().getMessage());
updateCompactionFailed(job);
@@ -619,6 +641,7 @@ public class Compactor extends AbstractServer
}
} else {
try {
+ LOG.info("Updating coordinator with compaction completion.");
updateCompactionCompleted(job, JOB_HOLDER.getStats());
} catch (RetriesExceededException e) {
LOG.error(
@@ -633,7 +656,7 @@ public class Compactor extends AbstractServer
currentCompactionId.set(null);
}
}
- } catch (InterruptedException e1) {
+ } catch (RuntimeException e1) {
LOG.error(
"Compactor thread was interrupted waiting for compaction to start, cancelling job",
e1);
@@ -662,7 +685,10 @@ public class Compactor extends AbstractServer
try {
LOG.debug("Closing filesystems");
- getContext().getVolumeManager().close();
+ VolumeManager mgr = getContext().getVolumeManager();
+ if (null != mgr) {
+ mgr.close();
+ }
} catch (IOException e) {
LOG.warn("Failed to close filesystem : {}", e.getMessage(), e);
}
@@ -670,7 +696,9 @@ public class Compactor extends AbstractServer
gcLogger.logGCInfo(getConfiguration());
LOG.info("stop requested. exiting ... ");
try {
- compactorLock.unlock();
+ if (null != compactorLock) {
+ compactorLock.unlock();
+ }
} catch (Exception e) {
LOG.warn("Failed to release compactor lock", e);
}
@@ -716,12 +744,16 @@ public class Compactor extends AbstractServer
} else {
return job;
}
-
}
@Override
public String getRunningCompactionId(TInfo tinfo, TCredentials credentials)
throws ThriftSecurityException, TException {
+ // do not expect users to call this directly, expect other tservers to call this method
+ if (!security.canPerformSystemActions(credentials)) {
+ throw new AccumuloSecurityException(credentials.getPrincipal(),
+ SecurityErrorCode.PERMISSION_DENIED).asThriftException();
+ }
// Any returned id must cover the time period from before a job is reserved until after it
// commits. This method is called to detect dead compactions and depends on this behavior.
@@ -734,5 +766,4 @@ public class Compactor extends AbstractServer
return eci.canonical();
}
}
-
}
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
new file mode 100644
index 0000000..872213c
--- /dev/null
+++ b/server/compactor/src/test/java/org/apache/accumulo/compactor/CompactorTest.java
@@ -0,0 +1,441 @@
+/*
+ * 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
+ *
+ * http://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 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.compaction.thrift.CompactionState;
+import org.apache.accumulo.core.conf.AccumuloConfiguration;
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.dataImpl.thrift.TKeyExtent;
+import org.apache.accumulo.core.metadata.schema.ExternalCompactionId;
+import org.apache.accumulo.core.tabletserver.thrift.CompactionStats;
+import org.apache.accumulo.core.tabletserver.thrift.TExternalCompactionJob;
+import org.apache.accumulo.core.util.Halt;
+import org.apache.accumulo.core.util.HostAndPort;
+import org.apache.accumulo.fate.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.rpc.ServerAddress;
+import org.apache.accumulo.server.rpc.TServerUtils;
+import org.apache.zookeeper.KeeperException;
+import org.easymock.EasyMock;
+import org.junit.Assert;
+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.powermock.reflect.Whitebox;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@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 AccumuloConfiguration conf;
+ private final ServerContext ctx;
+ private final ExternalCompactionId eci;
+ private volatile boolean completedCalled = false;
+ private volatile boolean failedCalled = false;
+ private CompactionState latestState = null;
+
+ SuccessfulCompactor(Supplier<UUID> uuid, ServerAddress address, TExternalCompactionJob job,
+ AccumuloConfiguration conf, ServerContext ctx, ExternalCompactionId eci) {
+ super(new CompactorServerOpts(), new String[] {"-q", "testQ"});
+ this.uuid = uuid;
+ this.address = address;
+ this.job = job;
+ this.conf = conf;
+ this.ctx = ctx;
+ this.eci = eci;
+ }
+
+ @Override
+ public ServerContext getContext() {
+ return this.ctx;
+ }
+
+ @Override
+ public AccumuloConfiguration getConfiguration() {
+ return this.conf;
+ }
+
+ @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 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, CompactionState state,
+ String message) throws RetriesExceededException {
+ latestState = state;
+ }
+
+ @Override
+ protected void updateCompactionFailed(TExternalCompactionJob job)
+ throws RetriesExceededException {
+ failedCalled = true;
+ }
+
+ @Override
+ protected void updateCompactionCompleted(TExternalCompactionJob job, CompactionStats stats)
+ throws RetriesExceededException {
+ completedCalled = true;
+ }
+
+ public CompactionState getLatestState() {
+ return latestState;
+ }
+
+ public boolean isCompletedCalled() {
+ return completedCalled;
+ }
+
+ public boolean isFailedCalled() {
+ return failedCalled;
+ }
+
+ }
+
+ public class FailedCompactor extends SuccessfulCompactor {
+
+ FailedCompactor(Supplier<UUID> uuid, ServerAddress address, TExternalCompactionJob job,
+ AccumuloConfiguration conf, ServerContext ctx, ExternalCompactionId eci) {
+ super(uuid, address, job, conf, ctx, 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,
+ AccumuloConfiguration conf, ServerContext ctx, ExternalCompactionId eci) {
+ super(uuid, address, job, conf, ctx, 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 {
+ // Instantiates class without calling constructor
+ Compactor c = Whitebox.newInstance(Compactor.class);
+ Assert.assertEquals(1, c.calculateProgressCheckTime(1024));
+ Assert.assertEquals(1, c.calculateProgressCheckTime(1048576));
+ Assert.assertEquals(1, c.calculateProgressCheckTime(10485760));
+ Assert.assertEquals(10, c.calculateProgressCheckTime(104857600));
+ Assert.assertEquals(102, c.calculateProgressCheckTime(1024 * 1024 * 1024));
+ }
+
+ @Test
+ public void testCompactionSucceeds() throws Exception {
+ UUID uuid = UUID.randomUUID();
+ Supplier<UUID> supplier = new Supplier<>() {
+ @Override
+ public UUID get() {
+ return uuid;
+ }
+ };
+
+ ExternalCompactionId eci = ExternalCompactionId.generate(supplier.get());
+
+ PowerMock.resetAll();
+ PowerMock.suppress(PowerMock.methods(Halt.class, "halt"));
+ PowerMock.suppress(PowerMock.methods(TServerUtils.class, "stopTServer"));
+ PowerMock.suppress(PowerMock.constructor(AbstractServer.class));
+ PowerMock.suppress(
+ PowerMock.methods(Compactor.class, "setupSecurity", "startGCLogger", "printStartupMsg"));
+
+ ServerAddress client = PowerMock.createNiceMock(ServerAddress.class);
+ HostAndPort address = HostAndPort.fromString("localhost:10240");
+ EasyMock.expect(client.getAddress()).andReturn(address);
+
+ TExternalCompactionJob job = PowerMock.createNiceMock(TExternalCompactionJob.class);
+ TKeyExtent extent = PowerMock.createNiceMock(TKeyExtent.class);
+ EasyMock.expect(job.isSetExternalCompactionId()).andReturn(true).anyTimes();
+ EasyMock.expect(job.getExternalCompactionId()).andReturn(eci.toString()).anyTimes();
+ EasyMock.expect(job.getExtent()).andReturn(extent);
+
+ AccumuloConfiguration conf = PowerMock.createNiceMock(AccumuloConfiguration.class);
+ EasyMock.expect(conf.getTimeInMillis(Property.INSTANCE_ZK_TIMEOUT)).andReturn(86400000L);
+
+ ServerContext ctx = PowerMock.createNiceMock(ServerContext.class);
+ VolumeManagerImpl vm = PowerMock.createNiceMock(VolumeManagerImpl.class);
+ EasyMock.expect(ctx.getVolumeManager()).andReturn(vm);
+ vm.close();
+
+ PowerMock.replayAll();
+
+ SuccessfulCompactor c = new SuccessfulCompactor(supplier, client, job, conf, ctx, eci);
+ c.run();
+
+ PowerMock.verifyAll();
+ c.close();
+
+ Assert.assertTrue(c.isCompletedCalled());
+ Assert.assertFalse(c.isFailedCalled());
+ }
+
+ @Test
+ public void testCompactionFails() throws Exception {
+ UUID uuid = UUID.randomUUID();
+ Supplier<UUID> supplier = new Supplier<>() {
+ @Override
+ public UUID get() {
+ return uuid;
+ }
+ };
+
+ ExternalCompactionId eci = ExternalCompactionId.generate(supplier.get());
+
+ PowerMock.resetAll();
+ PowerMock.suppress(PowerMock.methods(Halt.class, "halt"));
+ PowerMock.suppress(PowerMock.methods(TServerUtils.class, "stopTServer"));
+ PowerMock.suppress(PowerMock.constructor(AbstractServer.class));
+ PowerMock.suppress(
+ PowerMock.methods(Compactor.class, "setupSecurity", "startGCLogger", "printStartupMsg"));
+
+ ServerAddress client = PowerMock.createNiceMock(ServerAddress.class);
+ HostAndPort address = HostAndPort.fromString("localhost:10240");
+ EasyMock.expect(client.getAddress()).andReturn(address);
+
+ TExternalCompactionJob job = PowerMock.createNiceMock(TExternalCompactionJob.class);
+ TKeyExtent extent = PowerMock.createNiceMock(TKeyExtent.class);
+ EasyMock.expect(job.isSetExternalCompactionId()).andReturn(true).anyTimes();
+ EasyMock.expect(job.getExternalCompactionId()).andReturn(eci.toString()).anyTimes();
+ EasyMock.expect(job.getExtent()).andReturn(extent);
+
+ AccumuloConfiguration conf = PowerMock.createNiceMock(AccumuloConfiguration.class);
+ EasyMock.expect(conf.getTimeInMillis(Property.INSTANCE_ZK_TIMEOUT)).andReturn(86400000L);
+
+ ServerContext ctx = PowerMock.createNiceMock(ServerContext.class);
+ VolumeManagerImpl vm = PowerMock.createNiceMock(VolumeManagerImpl.class);
+ EasyMock.expect(ctx.getVolumeManager()).andReturn(vm);
+ vm.close();
+
+ PowerMock.replayAll();
+
+ FailedCompactor c = new FailedCompactor(supplier, client, job, conf, ctx, eci);
+ c.run();
+
+ PowerMock.verifyAll();
+ c.close();
+
+ Assert.assertFalse(c.isCompletedCalled());
+ Assert.assertTrue(c.isFailedCalled());
+ Assert.assertEquals(CompactionState.FAILED, c.getLatestState());
+ }
+
+ @Test
+ public void testCompactionInterrupted() throws Exception {
+ UUID uuid = UUID.randomUUID();
+ Supplier<UUID> supplier = new Supplier<>() {
+ @Override
+ public UUID get() {
+ return uuid;
+ }
+ };
+
+ ExternalCompactionId eci = ExternalCompactionId.generate(supplier.get());
+
+ PowerMock.resetAll();
+ PowerMock.suppress(PowerMock.methods(Halt.class, "halt"));
+ PowerMock.suppress(PowerMock.methods(TServerUtils.class, "stopTServer"));
+ PowerMock.suppress(PowerMock.constructor(AbstractServer.class));
+ PowerMock.suppress(
+ PowerMock.methods(Compactor.class, "setupSecurity", "startGCLogger", "printStartupMsg"));
+
+ ServerAddress client = PowerMock.createNiceMock(ServerAddress.class);
+ HostAndPort address = HostAndPort.fromString("localhost:10240");
+ EasyMock.expect(client.getAddress()).andReturn(address);
+
+ TExternalCompactionJob job = PowerMock.createNiceMock(TExternalCompactionJob.class);
+ TKeyExtent extent = PowerMock.createNiceMock(TKeyExtent.class);
+ EasyMock.expect(job.isSetExternalCompactionId()).andReturn(true).anyTimes();
+ EasyMock.expect(job.getExternalCompactionId()).andReturn(eci.toString()).anyTimes();
+ EasyMock.expect(job.getExtent()).andReturn(extent);
+
+ AccumuloConfiguration conf = PowerMock.createNiceMock(AccumuloConfiguration.class);
+ EasyMock.expect(conf.getTimeInMillis(Property.INSTANCE_ZK_TIMEOUT)).andReturn(86400000L);
+
+ ServerContext ctx = PowerMock.createNiceMock(ServerContext.class);
+ VolumeManagerImpl vm = PowerMock.createNiceMock(VolumeManagerImpl.class);
+ EasyMock.expect(ctx.getVolumeManager()).andReturn(vm);
+ vm.close();
+
+ PowerMock.replayAll();
+
+ InterruptedCompactor c = new InterruptedCompactor(supplier, client, job, conf, ctx, eci);
+ c.run();
+
+ PowerMock.verifyAll();
+ c.close();
+
+ Assert.assertFalse(c.isCompletedCalled());
+ Assert.assertTrue(c.isFailedCalled());
+ Assert.assertEquals(CompactionState.CANCELLED, c.getLatestState());
+ }
+
+}
diff --git a/server/compactor/src/test/resources/log4j2-test.properties b/server/compactor/src/test/resources/log4j2-test.properties
new file mode 100644
index 0000000..5f9bfbc
--- /dev/null
+++ b/server/compactor/src/test/resources/log4j2-test.properties
@@ -0,0 +1,35 @@
+#
+# 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
+#
+# http://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
+