Manno15 commented on a change in pull request #2240: URL: https://github.com/apache/accumulo/pull/2240#discussion_r701965405
########## File path: server/manager/src/test/java/org/apache/accumulo/manager/tableOps/compact/CompactionDriverTest.java ########## @@ -0,0 +1,135 @@ +/* + * 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.manager.tableOps.compact; + +import static org.junit.Assert.fail; + +import org.apache.accumulo.core.Constants; +import org.apache.accumulo.core.clientImpl.AcceptableThriftTableOperationException; +import org.apache.accumulo.core.clientImpl.thrift.TableOperation; +import org.apache.accumulo.core.clientImpl.thrift.TableOperationExceptionType; +import org.apache.accumulo.core.data.NamespaceId; +import org.apache.accumulo.core.data.TableId; +import org.apache.accumulo.fate.zookeeper.ZooReaderWriter; +import org.apache.accumulo.manager.Manager; +import org.apache.accumulo.server.ServerContext; +import org.easymock.EasyMock; +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.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +@PrepareForTest(CompactionDriver.class) +@PowerMockIgnore({"org.apache.logging.*", "javax.management.*", "org.slf4j.*"}) +public class CompactionDriverTest { + + @Test + public void testCancelId() throws Exception { + + final String instance = "test-instance"; + final long compactId = 123; + final long cancelId = 124; + final NamespaceId namespaceId = NamespaceId.of("13"); + final TableId tableId = TableId.of("42"); + final byte[] startRow = new byte[0]; + final byte[] endRow = new byte[0]; + + PowerMock.resetAll(); + Manager manager = PowerMock.createNiceMock(Manager.class); + ServerContext ctx = PowerMock.createNiceMock(ServerContext.class); + ZooReaderWriter zrw = PowerMock.createNiceMock(ZooReaderWriter.class); + EasyMock.expect(manager.getInstanceID()).andReturn(instance).anyTimes(); + EasyMock.expect(manager.getContext()).andReturn(ctx); + EasyMock.expect(ctx.getZooReaderWriter()).andReturn(zrw); + + final String zCancelID = Constants.ZROOT + "/" + instance + Constants.ZTABLES + "/" + + tableId.toString() + Constants.ZTABLE_COMPACT_CANCEL_ID; + EasyMock.expect(zrw.getData(zCancelID)).andReturn(Long.toString(cancelId).getBytes()); + + PowerMock.replayAll(); + + final CompactionDriver driver = + new CompactionDriver(compactId, namespaceId, tableId, startRow, endRow); + try { + driver.isReady(Long.parseLong(tableId.toString()), manager); + } catch (AcceptableThriftTableOperationException e) { + if (e.getTableId().equals(tableId.toString()) && e.getOp().equals(TableOperation.COMPACT) + && e.getType().equals(TableOperationExceptionType.OTHER) + && e.getDescription().equals("Compaction canceled")) { + // success + } else { + fail("Unexpected error thrown: " + e.getMessage()); + } + } catch (Exception e) { + fail("Unhandled error thrown: " + e.getMessage()); + } + PowerMock.verifyAll(); + } + + @Test + public void testTableBeingDeleted() throws Exception { + + final String instance = "test-instance"; + final long compactId = 123; + final long cancelId = 122; + final NamespaceId namespaceId = NamespaceId.of("14"); + final TableId tableId = TableId.of("43"); + final byte[] startRow = new byte[0]; + final byte[] endRow = new byte[0]; + + PowerMock.resetAll(); + Manager manager = PowerMock.createNiceMock(Manager.class); + ServerContext ctx = PowerMock.createNiceMock(ServerContext.class); + ZooReaderWriter zrw = PowerMock.createNiceMock(ZooReaderWriter.class); + EasyMock.expect(manager.getInstanceID()).andReturn(instance).anyTimes(); + EasyMock.expect(manager.getContext()).andReturn(ctx); + EasyMock.expect(ctx.getZooReaderWriter()).andReturn(zrw); + + final String zCancelID = Constants.ZROOT + "/" + instance + Constants.ZTABLES + "/" + + tableId.toString() + Constants.ZTABLE_COMPACT_CANCEL_ID; + EasyMock.expect(zrw.getData(zCancelID)).andReturn(Long.toString(cancelId).getBytes()); + + String deleteMarkerPath = Constants.ZROOT + "/" + instance + Constants.ZTABLES + "/" + tableId + + Constants.ZTABLE_DELETE_MARKER; + EasyMock.expect(zrw.exists(deleteMarkerPath)).andReturn(true); + + PowerMock.replayAll(); + + final CompactionDriver driver = + new CompactionDriver(compactId, namespaceId, tableId, startRow, endRow); + try { + driver.isReady(Long.parseLong(tableId.toString()), manager); + } catch (AcceptableThriftTableOperationException e) { + if (e.getTableId().equals(tableId.toString()) && e.getOp().equals(TableOperation.COMPACT) + && e.getType().equals(TableOperationExceptionType.OTHER) Review comment: Unrelated to the scope of this ticket, but should compaction exceptions get their own `TableOperationExceptionType` in the future? -- 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]
