milleruntime commented on a change in pull request #2358:
URL: https://github.com/apache/accumulo/pull/2358#discussion_r751324573



##########
File path: 
test/src/main/java/org/apache/accumulo/test/compaction/ExternalCompactionProgressIT.java
##########
@@ -0,0 +1,166 @@
+/*
+ * 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.test.compaction;
+
+import static 
org.apache.accumulo.fate.util.UtilWaitThread.sleepUninterruptibly;
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.apache.accumulo.compactor.Compactor;
+import org.apache.accumulo.coordinator.CompactionCoordinator;
+import org.apache.accumulo.core.client.Accumulo;
+import org.apache.accumulo.core.client.AccumuloClient;
+import org.apache.accumulo.core.client.IteratorSetting;
+import org.apache.accumulo.core.compaction.thrift.TCompactionState;
+import org.apache.accumulo.core.iterators.IteratorUtil;
+import org.apache.accumulo.core.util.threads.Threads;
+import org.apache.accumulo.harness.AccumuloClusterHarness;
+import org.apache.accumulo.miniclusterImpl.MiniAccumuloClusterImpl;
+import org.apache.accumulo.miniclusterImpl.MiniAccumuloConfigImpl;
+import 
org.apache.accumulo.monitor.rest.compactions.external.RunningCompactorInfo;
+import org.apache.accumulo.test.functional.SlowIterator;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.thrift.TException;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Tests that external compactions report progress from start to finish. To 
prevent flaky test
+ * failures, we only measure progress in quarter segments: STARTED, QUARTER, 
HALF, THREE_QUARTERS.
+ * We can detect if the compaction finished without errors but the coordinator 
will never report
+ * 100% progress since it will remove the ECID upon completion. The {@link 
SlowIterator} is used to
+ * control the length of time it takes to complete the compaction.
+ */
+public class ExternalCompactionProgressIT extends AccumuloClusterHarness {
+  private static final Logger log = 
LoggerFactory.getLogger(ExternalCompactionProgressIT.class);
+  private static final int ROWS = 10_000;
+
+  enum EC_PROGRESS {
+    STARTED, QUARTER, HALF, THREE_QUARTERS
+  }
+
+  Map<String,RunningCompactorInfo> runningMap = new HashMap<>();
+  List<EC_PROGRESS> progressList = new ArrayList<>();
+
+  private final AtomicBoolean compactionFinished = new AtomicBoolean(false);
+
+  @Override
+  public void configureMiniCluster(MiniAccumuloConfigImpl cfg, Configuration 
coreSite) {
+    ExternalCompactionTestUtils.configureMiniCluster(cfg, coreSite);
+  }
+
+  @Test
+  public void testProgress() throws Exception {
+    MiniAccumuloClusterImpl.ProcessInfo c1 = null, coord = null;
+    String table1 = this.getUniqueNames(1)[0];
+    try (AccumuloClient client =
+        Accumulo.newClient().from(getCluster().getClientProperties()).build()) 
{
+      ExternalCompactionTestUtils.createTable(client, table1, "cs1");
+      ExternalCompactionTestUtils.writeData(client, table1, ROWS);
+      c1 = ((MiniAccumuloClusterImpl) getCluster()).exec(Compactor.class, 
"-q", "DCQ1");
+      coord = 
ExternalCompactionTestUtils.startCoordinator(((MiniAccumuloClusterImpl) 
getCluster()),
+          CompactionCoordinator.class, getCluster().getServerContext());
+
+      Thread checkerThread = startChecker();
+      checkerThread.start();
+
+      IteratorSetting setting = new IteratorSetting(50, "Slow", 
SlowIterator.class);
+      SlowIterator.setSleepTime(setting, 1);
+      client.tableOperations().attachIterator(table1, setting,
+          EnumSet.of(IteratorUtil.IteratorScope.majc));
+      log.info("Compacting table");
+      ExternalCompactionTestUtils.compact(client, table1, 2, "DCQ1", true);
+      ExternalCompactionTestUtils.verify(client, table1, 2, ROWS);
+
+      log.info("Done Compacting table");
+      compactionFinished.set(true);
+      checkerThread.join();
+
+      verifyProgress();
+    } finally {
+      ExternalCompactionTestUtils.stopProcesses(c1, coord);
+    }
+  }
+
+  public Thread startChecker() {
+    return Threads.createThread("RC checker", () -> {
+      try {
+        while (!compactionFinished.get()) {
+          checkRunning();
+          sleepUninterruptibly(1000, TimeUnit.MILLISECONDS);
+        }
+      } catch (TException e) {
+        log.warn("{}", e.getMessage(), e);
+      }
+    });
+  }
+
+  /**
+   * Check running compaction progress.
+   */
+  private void checkRunning() throws TException {
+    var ecList = 
ExternalCompactionTestUtils.getRunningCompactions(getCluster().getServerContext());
+    var ecMap = ecList.getCompactions();
+    if (ecMap != null) {
+      ecMap.forEach((ecid, ec) -> {
+        // returns null if it's a new mapping
+        var rci = new RunningCompactorInfo(System.currentTimeMillis(), ecid, 
ec);
+        var previous = runningMap.put(ecid, rci);

Review comment:
       It shouldn't ever store a null value for the `RunningCompactorInfo` 
object. I replaced var with the actual type and renamed the variable to make it 
more clear.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to