Skip to content

Commit

Permalink
Merge branch 'dev' into dev_wenjun_disableCompositeIndicator
Browse files Browse the repository at this point in the history
  • Loading branch information
SbloodyS authored Jun 19, 2024
2 parents d4d411d + e18ed37 commit f8213e5
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.dolphinscheduler.dao.repository.impl;

import static com.google.common.truth.Truth.assertThat;
import static org.junit.jupiter.api.Assertions.assertFalse;

import org.apache.dolphinscheduler.common.constants.Constants;
import org.apache.dolphinscheduler.common.enums.CommandType;
Expand All @@ -28,45 +29,63 @@
import org.apache.dolphinscheduler.common.utils.DateUtils;
import org.apache.dolphinscheduler.dao.BaseDaoTest;
import org.apache.dolphinscheduler.dao.entity.Command;
import org.apache.dolphinscheduler.dao.mapper.CommandMapper;
import org.apache.dolphinscheduler.dao.repository.CommandDao;

import org.apache.commons.lang3.RandomUtils;

import java.util.List;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.RepeatedTest;
import org.springframework.beans.factory.annotation.Autowired;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

class CommandDaoImplTest extends BaseDaoTest {

@Autowired
private CommandDao commandDao;

@Test
@Autowired
private CommandMapper commandMapper;

@RepeatedTest(value = 100)
void fetchCommandByIdSlot() {
int commandSize = RandomUtils.nextInt(1, 1000);
for (int i = 0; i < commandSize; i++) {
createCommand(CommandType.START_PROCESS, 0);
}
// clear all commands
commandMapper.delete(new QueryWrapper<Command>().ge("id", -1));

int totalSlot = RandomUtils.nextInt(1, 10);
int currentSlotIndex = RandomUtils.nextInt(0, totalSlot);
int fetchSize = RandomUtils.nextInt(10, 100);
for (int i = 1; i < 5; i++) {
int idStep = i;
List<Command> commands = commandDao.queryCommandByIdSlot(currentSlotIndex, totalSlot, idStep, fetchSize);
assertThat(commands.size()).isGreaterThan(0);
assertThat(commands.size())
.isEqualTo(commandDao.queryAll()
.stream()
.filter(command -> (command.getId() / idStep) % totalSlot == currentSlotIndex)
.limit(fetchSize)
.count());

int idStep = RandomUtils.nextInt(1, 5);
int commandSize = RandomUtils.nextInt(currentSlotIndex, 1000);
// Generate commandSize commands
int id = 0;
for (int j = 0; j < commandSize; j++) {
Command command = generateCommand(CommandType.START_PROCESS, 0);
command.setId(id);
id += idStep;
commandDao.insert(command);
}

List<Command> commands = commandDao.queryCommandByIdSlot(currentSlotIndex, totalSlot, idStep, fetchSize);
assertFalse(commands.isEmpty(),
"Commands should not be empty, currentSlotIndex: " + currentSlotIndex +
", totalSlot: " + totalSlot +
", idStep: " + idStep +
", fetchSize: " + fetchSize +
", total command size: " + commandSize +
", total commands: " + commandDao.queryAll());
assertThat(commands.size())
.isEqualTo(commandDao.queryAll()
.stream()
.filter(command -> (command.getId() / idStep) % totalSlot == currentSlotIndex)
.limit(fetchSize)
.count());

}

private void createCommand(CommandType commandType, int processDefinitionCode) {
private Command generateCommand(CommandType commandType, int processDefinitionCode) {
Command command = new Command();
command.setCommandType(commandType);
command.setProcessDefinitionCode(processDefinitionCode);
Expand All @@ -83,6 +102,6 @@ private void createCommand(CommandType commandType, int processDefinitionCode) {
command.setWorkerGroup(Constants.DEFAULT_WORKER_GROUP);
command.setProcessInstanceId(0);
command.setProcessDefinitionVersion(0);
commandDao.insert(command);
return command;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@
import org.apache.dolphinscheduler.plugin.storage.api.StorageOperator;
import org.apache.dolphinscheduler.spi.enums.ResourceType;

import org.apache.commons.lang3.StringUtils;

import java.io.File;
import java.nio.file.FileAlreadyExistsException;
import java.nio.file.Files;
import java.nio.file.Paths;
Expand All @@ -45,15 +42,16 @@ class LocalStorageOperatorTest {

private StorageOperator storageOperator;

private static final String resourceBaseDir = StringUtils
.substringBeforeLast(FileUtils.getClassPathAbsolutePath(LocalStorageOperatorTest.class), File.separator);
private static final String resourceBaseDir =
Paths.get(LocalStorageOperatorTest.class.getResource("/").getFile(), "localStorage").toString();
private static final String tenantCode = "default";
private static final String baseDir =
Paths.get(resourceBaseDir, tenantCode, Constants.RESOURCE_TYPE_FILE).toString();

@SneakyThrows
@BeforeEach
public void setup() {
Files.createDirectories(Paths.get(resourceBaseDir));
System.setProperty(Constants.RESOURCE_UPLOAD_PATH, resourceBaseDir);

LocalStorageOperatorFactory localStorageOperatorFactory = new LocalStorageOperatorFactory();
Expand Down

0 comments on commit f8213e5

Please sign in to comment.