|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | + |
| 19 | +package org.apache.iotdb.db.consensus.statemachine.dataregion; |
| 20 | + |
| 21 | +import org.apache.iotdb.common.rpc.thrift.TSStatus; |
| 22 | +import org.apache.iotdb.commons.path.PartialPath; |
| 23 | +import org.apache.iotdb.db.queryengine.plan.planner.plan.node.PlanNodeId; |
| 24 | +import org.apache.iotdb.db.queryengine.plan.planner.plan.node.write.DeleteDataNode; |
| 25 | +import org.apache.iotdb.db.storageengine.dataregion.DataRegion; |
| 26 | +import org.apache.iotdb.rpc.TSStatusCode; |
| 27 | + |
| 28 | +import org.junit.Assert; |
| 29 | +import org.junit.Test; |
| 30 | +import org.mockito.Mockito; |
| 31 | + |
| 32 | +import java.io.IOException; |
| 33 | +import java.util.Collections; |
| 34 | + |
| 35 | +import static org.mockito.ArgumentMatchers.any; |
| 36 | +import static org.mockito.ArgumentMatchers.anyLong; |
| 37 | + |
| 38 | +public class DataExecutionVisitorTest { |
| 39 | + |
| 40 | + @Test |
| 41 | + public void testDeleteFailureReturnsMessage() throws Exception { |
| 42 | + final DataRegion dataRegion = Mockito.mock(DataRegion.class); |
| 43 | + Mockito.when(dataRegion.getDatabaseName()).thenReturn("root.sg"); |
| 44 | + final IOException failure = new IOException("injected delete failure"); |
| 45 | + Mockito.doThrow(failure) |
| 46 | + .when(dataRegion) |
| 47 | + .deleteByDevice(any(PartialPath.class), anyLong(), anyLong(), anyLong()); |
| 48 | + |
| 49 | + final DeleteDataNode node = |
| 50 | + new DeleteDataNode( |
| 51 | + new PlanNodeId("delete-error-test"), |
| 52 | + Collections.singletonList(new PartialPath("root.sg.device.s1")), |
| 53 | + Long.MIN_VALUE, |
| 54 | + Long.MAX_VALUE); |
| 55 | + |
| 56 | + final TSStatus status = new DataExecutionVisitor().visitDeleteData(node, dataRegion); |
| 57 | + |
| 58 | + Assert.assertEquals(TSStatusCode.WRITE_PROCESS_ERROR.getStatusCode(), status.getCode()); |
| 59 | + Assert.assertEquals(failure.getMessage(), status.getMessage()); |
| 60 | + Mockito.verify(dataRegion).writeUnlock(); |
| 61 | + } |
| 62 | +} |
0 commit comments