|
| 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, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +package org.apache.iotdb.db.queryengine.plan.scheduler.load; |
| 21 | + |
| 22 | +import org.apache.iotdb.common.rpc.thrift.TConsensusGroupId; |
| 23 | +import org.apache.iotdb.common.rpc.thrift.TDataNodeLocation; |
| 24 | +import org.apache.iotdb.common.rpc.thrift.TEndPoint; |
| 25 | +import org.apache.iotdb.common.rpc.thrift.TRegionReplicaSet; |
| 26 | +import org.apache.iotdb.commons.consensus.DataRegionId; |
| 27 | +import org.apache.iotdb.commons.partition.StorageExecutor; |
| 28 | +import org.apache.iotdb.commons.queryengine.plan.planner.plan.node.PlanNodeId; |
| 29 | +import org.apache.iotdb.db.queryengine.common.PlanFragmentId; |
| 30 | +import org.apache.iotdb.db.queryengine.plan.planner.plan.FragmentInstance; |
| 31 | +import org.apache.iotdb.db.queryengine.plan.planner.plan.PlanFragment; |
| 32 | +import org.apache.iotdb.db.queryengine.plan.planner.plan.node.load.LoadTsFilePieceNode; |
| 33 | +import org.apache.iotdb.db.storageengine.StorageEngine; |
| 34 | +import org.apache.iotdb.rpc.RpcUtils; |
| 35 | + |
| 36 | +import org.junit.Test; |
| 37 | +import org.junit.runner.RunWith; |
| 38 | +import org.mockito.Mockito; |
| 39 | +import org.powermock.api.mockito.PowerMockito; |
| 40 | +import org.powermock.core.classloader.annotations.PowerMockIgnore; |
| 41 | +import org.powermock.core.classloader.annotations.PrepareForTest; |
| 42 | +import org.powermock.modules.junit4.PowerMockRunner; |
| 43 | + |
| 44 | +import java.io.File; |
| 45 | +import java.util.Collections; |
| 46 | + |
| 47 | +@PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "javax.management.*"}) |
| 48 | +@RunWith(PowerMockRunner.class) |
| 49 | +@PrepareForTest(StorageEngine.class) |
| 50 | +public class LoadTsFileDispatcherImplTest { |
| 51 | + |
| 52 | + @Test |
| 53 | + public void testDispatchLocallyPieceNodeSkipsSerdeRoundTrip() throws Exception { |
| 54 | + final StorageEngine storageEngine = Mockito.mock(StorageEngine.class); |
| 55 | + PowerMockito.mockStatic(StorageEngine.class); |
| 56 | + PowerMockito.when(StorageEngine.getInstance()).thenReturn(storageEngine); |
| 57 | + |
| 58 | + final LoadTsFileDispatcherImpl dispatcher = new LoadTsFileDispatcherImpl(null, false); |
| 59 | + dispatcher.setUuid("test-uuid"); |
| 60 | + |
| 61 | + final LoadTsFilePieceNode pieceNode = |
| 62 | + new LoadTsFilePieceNode(new PlanNodeId("piece"), new File("test.tsfile")); |
| 63 | + final FragmentInstance instance = createFragmentInstance(pieceNode); |
| 64 | + |
| 65 | + Mockito.when( |
| 66 | + storageEngine.writeLoadTsFileNode( |
| 67 | + Mockito.eq(new DataRegionId(1)), Mockito.same(pieceNode), Mockito.eq("test-uuid"))) |
| 68 | + .thenReturn(RpcUtils.SUCCESS_STATUS); |
| 69 | + |
| 70 | + dispatcher.dispatchLocally(instance); |
| 71 | + |
| 72 | + Mockito.verify(storageEngine) |
| 73 | + .writeLoadTsFileNode( |
| 74 | + Mockito.eq(new DataRegionId(1)), Mockito.same(pieceNode), Mockito.eq("test-uuid")); |
| 75 | + } |
| 76 | + |
| 77 | + private static FragmentInstance createFragmentInstance(final LoadTsFilePieceNode pieceNode) { |
| 78 | + final PlanFragmentId fragmentId = new PlanFragmentId("test", 0); |
| 79 | + final FragmentInstance instance = |
| 80 | + new FragmentInstance( |
| 81 | + new PlanFragment(fragmentId, pieceNode), |
| 82 | + fragmentId.genFragmentInstanceId(), |
| 83 | + null, |
| 84 | + null, |
| 85 | + 0, |
| 86 | + null, |
| 87 | + false, |
| 88 | + false); |
| 89 | + final TConsensusGroupId consensusGroupId = new DataRegionId(1).convertToTConsensusGroupId(); |
| 90 | + instance.setExecutorAndHost( |
| 91 | + new StorageExecutor( |
| 92 | + new TRegionReplicaSet( |
| 93 | + consensusGroupId, |
| 94 | + Collections.singletonList( |
| 95 | + new TDataNodeLocation().setInternalEndPoint(new TEndPoint("127.0.0.1", 1)))))); |
| 96 | + return instance; |
| 97 | + } |
| 98 | +} |
0 commit comments