This is an automated email from the ASF dual-hosted git repository.

dlmarion pushed a commit to branch elasticity
in repository https://gitbox.apache.org/repos/asf/accumulo.git


The following commit(s) were added to refs/heads/elasticity by this push:
     new ca56493db7 Resurrected CompactionDriverTest resolving TODO in 
PreDeleteTable (#4377)
ca56493db7 is described below

commit ca56493db7eb122345a7c954c820fe9b51e4687e
Author: Dave Marion <dlmar...@apache.org>
AuthorDate: Tue Mar 19 12:20:17 2024 -0400

    Resurrected CompactionDriverTest resolving TODO in PreDeleteTable (#4377)
    
    The TODO asked if the the delete marker in ZooKeeper was still
    being used / tested. It is still being used by the CompactionDriver.
    However, the CompactionDriverTest class was deleted at some point
    which tests it. I resurrected and fixed the test.
---
 .../manager/tableOps/compact/CompactionDriver.java |   3 +-
 .../manager/tableOps/delete/PreDeleteTable.java    |   1 -
 .../tableOps/compact/CompactionDriverTest.java     | 148 +++++++++++++++++++++
 3 files changed, 150 insertions(+), 2 deletions(-)

diff --git 
a/server/manager/src/main/java/org/apache/accumulo/manager/tableOps/compact/CompactionDriver.java
 
b/server/manager/src/main/java/org/apache/accumulo/manager/tableOps/compact/CompactionDriver.java
index f8ad23172b..6167ca05cf 100644
--- 
a/server/manager/src/main/java/org/apache/accumulo/manager/tableOps/compact/CompactionDriver.java
+++ 
b/server/manager/src/main/java/org/apache/accumulo/manager/tableOps/compact/CompactionDriver.java
@@ -129,7 +129,8 @@ class CompactionDriver extends ManagerRepo {
     return sleepTime;
   }
 
-  private boolean isCancelled(FateId fateId, ServerContext context)
+  // visible for testing
+  protected boolean isCancelled(FateId fateId, ServerContext context)
       throws InterruptedException, KeeperException {
     return CompactionConfigStorage.getConfig(context, fateId) == null;
   }
diff --git 
a/server/manager/src/main/java/org/apache/accumulo/manager/tableOps/delete/PreDeleteTable.java
 
b/server/manager/src/main/java/org/apache/accumulo/manager/tableOps/delete/PreDeleteTable.java
index 196e898c09..6094960b38 100644
--- 
a/server/manager/src/main/java/org/apache/accumulo/manager/tableOps/delete/PreDeleteTable.java
+++ 
b/server/manager/src/main/java/org/apache/accumulo/manager/tableOps/delete/PreDeleteTable.java
@@ -60,7 +60,6 @@ public class PreDeleteTable extends ManagerRepo {
 
   private void preventFutureCompactions(Manager environment)
       throws KeeperException, InterruptedException {
-    // ELASTICITY_TODO investigate this. Is still needed? Is it still working 
as expected?
     String deleteMarkerPath = 
createDeleteMarkerPath(environment.getInstanceID(), tableId);
     ZooReaderWriter zoo = environment.getContext().getZooReaderWriter();
     zoo.putPersistentData(deleteMarkerPath, new byte[] {}, 
NodeExistsPolicy.SKIP);
diff --git 
a/server/manager/src/test/java/org/apache/accumulo/manager/tableOps/compact/CompactionDriverTest.java
 
b/server/manager/src/test/java/org/apache/accumulo/manager/tableOps/compact/CompactionDriverTest.java
new file mode 100644
index 0000000000..caf8be89d5
--- /dev/null
+++ 
b/server/manager/src/test/java/org/apache/accumulo/manager/tableOps/compact/CompactionDriverTest.java
@@ -0,0 +1,148 @@
+/*
+ * 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.manager.tableOps.compact;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import java.util.UUID;
+
+import 
org.apache.accumulo.core.clientImpl.AcceptableThriftTableOperationException;
+import org.apache.accumulo.core.clientImpl.TableOperationsImpl;
+import org.apache.accumulo.core.clientImpl.thrift.TableOperation;
+import org.apache.accumulo.core.clientImpl.thrift.TableOperationExceptionType;
+import org.apache.accumulo.core.data.InstanceId;
+import org.apache.accumulo.core.data.NamespaceId;
+import org.apache.accumulo.core.data.TableId;
+import org.apache.accumulo.core.fate.FateId;
+import org.apache.accumulo.core.fate.FateInstanceType;
+import org.apache.accumulo.core.fate.zookeeper.ZooReaderWriter;
+import org.apache.accumulo.manager.Manager;
+import org.apache.accumulo.manager.tableOps.delete.PreDeleteTable;
+import org.apache.accumulo.server.ServerContext;
+import org.apache.zookeeper.KeeperException;
+import org.easymock.EasyMock;
+import org.junit.jupiter.api.Test;
+
+public class CompactionDriverTest {
+
+  public static class CancelledCompactionDriver extends CompactionDriver {
+
+    private static final long serialVersionUID = 1L;
+
+    public CancelledCompactionDriver(NamespaceId namespaceId, TableId tableId, 
byte[] startRow,
+        byte[] endRow) {
+      super(namespaceId, tableId, startRow, endRow);
+    }
+
+    @Override
+    protected boolean isCancelled(FateId fateId, ServerContext context)
+        throws InterruptedException, KeeperException {
+      return true;
+    }
+
+  }
+
+  public static class NotCancelledCompactionDriver extends CompactionDriver {
+
+    private static final long serialVersionUID = 1L;
+
+    public NotCancelledCompactionDriver(NamespaceId namespaceId, TableId 
tableId, byte[] startRow,
+        byte[] endRow) {
+      super(namespaceId, tableId, startRow, endRow);
+    }
+
+    @Override
+    protected boolean isCancelled(FateId fateId, ServerContext context)
+        throws InterruptedException, KeeperException {
+      return false;
+    }
+
+  }
+
+  @Test
+  public void testCancelId() throws Exception {
+
+    final InstanceId instance = InstanceId.of(UUID.randomUUID());
+    final NamespaceId namespaceId = NamespaceId.of("13");
+    final TableId tableId = TableId.of("42");
+    final FateId compactionFateId = FateId.from(FateInstanceType.USER, 
UUID.randomUUID());
+    final byte[] startRow = new byte[0];
+    final byte[] endRow = new byte[0];
+
+    Manager manager = EasyMock.createNiceMock(Manager.class);
+    ServerContext ctx = EasyMock.createNiceMock(ServerContext.class);
+    ZooReaderWriter zrw = EasyMock.createNiceMock(ZooReaderWriter.class);
+    EasyMock.expect(manager.getInstanceID()).andReturn(instance).anyTimes();
+    EasyMock.expect(manager.getContext()).andReturn(ctx);
+    EasyMock.expect(ctx.getZooReaderWriter()).andReturn(zrw);
+
+    EasyMock.replay(manager, ctx, zrw);
+
+    final CancelledCompactionDriver driver =
+        new CancelledCompactionDriver(namespaceId, tableId, startRow, endRow);
+
+    var e = assertThrows(AcceptableThriftTableOperationException.class,
+        () -> driver.isReady(compactionFateId, manager));
+
+    assertEquals(e.getTableId(), tableId.toString());
+    assertEquals(e.getOp(), TableOperation.COMPACT);
+    assertEquals(e.getType(), TableOperationExceptionType.OTHER);
+    assertEquals(TableOperationsImpl.COMPACTION_CANCELED_MSG, 
e.getDescription());
+
+    EasyMock.verify(manager, ctx, zrw);
+  }
+
+  @Test
+  public void testTableBeingDeleted() throws Exception {
+
+    final InstanceId instance = InstanceId.of(UUID.randomUUID());
+    final NamespaceId namespaceId = NamespaceId.of("14");
+    final TableId tableId = TableId.of("43");
+    final FateId compactionFateId = FateId.from(FateInstanceType.USER, 
UUID.randomUUID());
+    final byte[] startRow = new byte[0];
+    final byte[] endRow = new byte[0];
+
+    Manager manager = EasyMock.createNiceMock(Manager.class);
+    ServerContext ctx = EasyMock.createNiceMock(ServerContext.class);
+    ZooReaderWriter zrw = EasyMock.createNiceMock(ZooReaderWriter.class);
+    EasyMock.expect(manager.getInstanceID()).andReturn(instance).anyTimes();
+    EasyMock.expect(manager.getContext()).andReturn(ctx);
+    EasyMock.expect(ctx.getZooReaderWriter()).andReturn(zrw);
+
+    String deleteMarkerPath = PreDeleteTable.createDeleteMarkerPath(instance, 
tableId);
+    EasyMock.expect(zrw.exists(deleteMarkerPath)).andReturn(true);
+
+    EasyMock.replay(manager, ctx, zrw);
+
+    final NotCancelledCompactionDriver driver =
+        new NotCancelledCompactionDriver(namespaceId, tableId, startRow, 
endRow);
+
+    var e = assertThrows(AcceptableThriftTableOperationException.class,
+        () -> driver.isReady(compactionFateId, manager));
+
+    assertEquals(e.getTableId(), tableId.toString());
+    assertEquals(e.getOp(), TableOperation.COMPACT);
+    assertEquals(e.getType(), TableOperationExceptionType.OTHER);
+    assertEquals(TableOperationsImpl.TABLE_DELETED_MSG, e.getDescription());
+
+    EasyMock.verify(manager, ctx, zrw);
+  }
+
+}

Reply via email to