|
14 | 14 |
|
15 | 15 | package com.starrocks.lake;
|
16 | 16 |
|
| 17 | +import com.google.common.collect.Lists; |
| 18 | +import com.staros.proto.ShardGroupInfo; |
17 | 19 | import com.starrocks.catalog.Database;
|
| 20 | +import com.starrocks.catalog.DistributionInfo; |
| 21 | +import com.starrocks.catalog.HashDistributionInfo; |
| 22 | +import com.starrocks.catalog.MaterializedIndex; |
| 23 | +import com.starrocks.catalog.Partition; |
| 24 | +import com.starrocks.catalog.PartitionInfo; |
| 25 | +import com.starrocks.catalog.PhysicalPartition; |
| 26 | +import com.starrocks.catalog.SinglePartitionInfo; |
18 | 27 | import com.starrocks.catalog.Table;
|
19 | 28 | import com.starrocks.common.Config;
|
20 | 29 | import com.starrocks.qe.ConnectContext;
|
|
24 | 33 | import com.starrocks.sql.ast.CreateTableStmt;
|
25 | 34 | import com.starrocks.transaction.TransactionState;
|
26 | 35 | import com.starrocks.utframe.UtFrameUtils;
|
| 36 | +import mockit.Mock; |
| 37 | +import mockit.MockUp; |
| 38 | +import mockit.Mocked; |
27 | 39 | import org.junit.AfterClass;
|
28 | 40 | import org.junit.Assert;
|
29 | 41 | import org.junit.BeforeClass;
|
30 | 42 | import org.junit.Test;
|
31 | 43 |
|
| 44 | +import java.util.ArrayList; |
| 45 | +import java.util.Collection; |
| 46 | +import java.util.List; |
| 47 | +import java.util.stream.Collectors; |
| 48 | +import java.util.stream.Stream; |
| 49 | + |
32 | 50 | public class LakeTableHelperTest {
|
33 | 51 | private static ConnectContext connectContext;
|
34 | 52 | private static final String DB_NAME = "test_lake_table_helper";
|
@@ -74,4 +92,54 @@ public void testSupportCombinedTxnLog() throws Exception {
|
74 | 92 | Config.lake_use_combined_txn_log = false;
|
75 | 93 | Assert.assertFalse(LakeTableHelper.supportCombinedTxnLog(TransactionState.LoadJobSourceType.BACKEND_STREAMING));
|
76 | 94 | }
|
| 95 | + |
| 96 | + @Test |
| 97 | + public void testDeleteShardGroupMeta(@Mocked StarOSAgent starOSAgent) { |
| 98 | + |
| 99 | + new MockUp<GlobalStateMgr>() { |
| 100 | + @Mock |
| 101 | + public StarOSAgent getStarOSAgent() { |
| 102 | + return starOSAgent; |
| 103 | + } |
| 104 | + }; |
| 105 | + |
| 106 | + long tableId = 1001L; |
| 107 | + long partitionId = 1000L; |
| 108 | + long physicalPartitionId = 1002L; |
| 109 | + long groupIdToClear = 5100L; |
| 110 | + |
| 111 | + DistributionInfo distributionInfo = new HashDistributionInfo(10, Lists.newArrayList()); |
| 112 | + PartitionInfo partitionInfo = new SinglePartitionInfo(); |
| 113 | + partitionInfo.setReplicationNum(1000L, (short) 3); |
| 114 | + Partition partition = |
| 115 | + new Partition(partitionId, physicalPartitionId, "p1", new MaterializedIndex(), distributionInfo); |
| 116 | + Collection<PhysicalPartition> subPartitions = partition.getSubPartitions(); |
| 117 | + subPartitions.forEach(physicalPartition -> { |
| 118 | + MaterializedIndex materializedIndex = |
| 119 | + physicalPartition.getMaterializedIndices(MaterializedIndex.IndexExtState.ALL).get(0); |
| 120 | + materializedIndex.setShardGroupId(groupIdToClear); |
| 121 | + }); |
| 122 | + |
| 123 | + // build shardGroupInfos |
| 124 | + List<Long> allShardIds = Stream.of(1000L, 1001L, 1002L, 1003L).collect(Collectors.toList()); |
| 125 | + List<ShardGroupInfo> shardGroupInfos = new ArrayList<>(); |
| 126 | + ShardGroupInfo info = ShardGroupInfo.newBuilder() |
| 127 | + .setGroupId(groupIdToClear) |
| 128 | + .putLabels("tableId", String.valueOf(tableId)) |
| 129 | + .putProperties("createTime", String.valueOf(System.currentTimeMillis() - 86400 * 1000)) |
| 130 | + .addAllShardIds(allShardIds) |
| 131 | + .build(); |
| 132 | + shardGroupInfos.add(info); |
| 133 | + new MockUp<StarOSAgent>() { |
| 134 | + @Mock |
| 135 | + public void deleteShardGroup(List<Long> groupIds) { |
| 136 | + for (long groupId : groupIds) { |
| 137 | + shardGroupInfos.removeIf(item -> item.getGroupId() == groupId); |
| 138 | + } |
| 139 | + } |
| 140 | + }; |
| 141 | + |
| 142 | + LakeTableHelper.deleteShardGroupMeta(partition); |
| 143 | + Assert.assertEquals(0, shardGroupInfos.size()); |
| 144 | + } |
77 | 145 | }
|
0 commit comments