package Visual_DVM_2021.Passes.All; import Common.Constants; import Common.Current; import Common.Global; import Common.UI.UI; import Common.Utils.Index; import ProjectData.LanguageName; import Repository.Server.ServerCode; import Repository.Server.ServerExchangeUnit_2021; import SapforTestingSystem.SapforConfiguration.SapforConfiguration; import SapforTestingSystem.SapforConfigurationCommand.SapforConfigurationCommand; import SapforTestingSystem.SapforTasksPackage.SapforTasksPackage; import TestingSystem.Group.Group; import TestingSystem.TasksPackage.TasksPackageState; import TestingSystem.Test.Test; import Visual_DVM_2021.Passes.PassCode_2021; import Visual_DVM_2021.Passes.Server.TestingSystemPass; import java.io.File; import java.util.Date; import java.util.LinkedHashMap; import java.util.Vector; public class StartSapforTests extends TestingSystemPass { protected int allTasksCount = 0; //-- protected LinkedHashMap> groupsTests = null; //-- protected LinkedHashMap allTests = null; protected Vector testsNames_lower = null; //все тесты что участвуют здесь protected Vector groupsLanguages = null; protected File sapfor = null; //--- //--- @Override public String getIconPath() { return "/icons/Start.png"; } @Override public String getButtonText() { return ""; } @Override protected boolean needsAnimation() { return true; } //-- protected boolean checkTestName(Test test) { String name = test.description.toLowerCase(); if (testsNames_lower.contains(name)) { Log.Writeln_("В пакет не могут входить тесты с одинаковыми именами (без учета регистра):" + test.description.toLowerCase()); return false; } testsNames_lower.add(name); return true; } protected boolean getGroupTests(int groupId) { Vector groupTests = new Vector<>(); Vector selectedGroupTests = new Vector<>(); //--- for (Test test : Global.testingServer.db.tests.Data.values()) { if (test.group_id==groupId) { groupTests.add(test.id); if (test.isSelected()) selectedGroupTests.add(test.id); } } if (!groupTests.isEmpty() && !selectedGroupTests.isEmpty()) groupTests = selectedGroupTests; //--- if (groupTests.isEmpty()) { Log.Writeln_("Пустая группа тестов: " + groupId); return false; } //-- for (int testId : groupTests) { Test test = Global.testingServer.db.tests.get(testId); if (!checkTestName(test)) return false; else allTests.put(test.description, test); } //-- groupsTests.put(groupId, groupTests); //-- return true; } boolean checkTerminalCode(SapforConfiguration sapforConfiguration, PassCode_2021 code, int count, Vector codes) { if (count > 2) { Log.Writeln_("Неверная конфигурация:" + sapforConfiguration.id + ": " + code.getDescription() + " возможно только один раз."); return false; } //-- if ((count == 1) && codes.size() > 1) { if (!codes.lastElement().equals(code)) { Log.Writeln_("Неверная конфигурация:" + sapforConfiguration.id + ": " + code.getDescription() + " может быть только завершающей командой!"); return false; } } return true; } public boolean getConfigurationCommands(SapforConfiguration sapforConfiguration) { //1. получить список всех команд. Vector codes = new Vector<>(); //-- счетчик завершающих команд. LinkedHashMap terminalCodesCount = new LinkedHashMap<>(); for (PassCode_2021 code : Constants.terminalSapforTestingCodes) terminalCodesCount.put(code, new Index()); //-- for (SapforConfigurationCommand command : Global.testingServer.db.sapforConfigurationCommands.Data.values()) { if (command.sapforconfiguration_id.equals(sapforConfiguration.id)) { codes.add(command.passCode); //--- for (PassCode_2021 t_code : Constants.terminalSapforTestingCodes) { if (command.passCode.equals(t_code)) terminalCodesCount.get(t_code).Inc(); } //--- } } //-- if (codes.size() == 0) { Log.Writeln_("Пустая конфигурация:" + sapforConfiguration.id); return false; } for (PassCode_2021 t_code : Constants.terminalSapforTestingCodes) { if (!checkTerminalCode(sapforConfiguration, t_code, terminalCodesCount.get(t_code).getValue(), codes )) return false; } //-- return true; } //-- @Override protected boolean canStart(Object... args) throws Exception { //-- allTasksCount = 0; target = null; //-- groupsTests = new LinkedHashMap<>(); //--->> testsNames_lower = new Vector<>(); allTests = new LinkedHashMap<>(); groupsLanguages = new Vector<>(); //-->> if (!Current.getAccount().CheckRegistered(Log)) { return false; } //проверка стартовых условий. if (!Current.Check(Log, Current.ServerSapfor)) return false; //--->> if (Global.testingServer.db.sapforConfigurations.getCheckedCount() == 0) { Log.Writeln_("Не отмечено ни одной конфигурации SAPFOR."); return false; } //- for (SapforConfiguration configuration : Global.testingServer.db.sapforConfigurations.getCheckedItems()) { if (!getConfigurationCommands(configuration)) return false; } //-- if (Global.testingServer.db.groups.getCheckedCount() == 0) { Log.Writeln_("Не отмечено ни одной группы тестов"); return false; } //-- for (Group group : Global.testingServer.db.groups.getCheckedItems()) { //--- if (!groupsLanguages.contains(group.language)) groupsLanguages.add(group.language); //- if (groupsLanguages.get(0) != LanguageName.fortran) { Log.Writeln_("Поддерживается пакетный режим только для языка Fortran!"); return false; } if (groupsLanguages.size() > 1) { Log.Writeln_("Запуск тестов на разных языках в рамках одного пакета запрещен!"); return false; } //--- if (!getGroupTests(group.id)) return false; } //-- for (int i = 0; i < Global.testingServer.db.sapforConfigurations.getCheckedCount(); ++i) { for (Vector tests : groupsTests.values()) allTasksCount += tests.size(); } //-- return (UI.Question("Будет запущено:\n" + allTasksCount + " задач\n" + "Продолжить")); } //-- @Override protected void ServerAction() throws Exception { target = new SapforTasksPackage(); target.genName(); //-- Vector testsIds = new Vector<>(); Vector configurationsIds = new Vector<>(); for (Test test : allTests.values()) testsIds.add(String.valueOf(test.id)); //-- for (SapforConfiguration configuration : Global.testingServer.db.sapforConfigurations.getCheckedItems()) configurationsIds.add(configuration.id); //-- target.tasksCount = allTasksCount; target.testsIds = String.join("\n", testsIds); target.configurationsIds = String.join("\n", configurationsIds); //-- target.sapforId = Current.getServerSapfor().id; target.sapfor_drv = Current.getServerSapfor().call_command; target.sapfor_version = Current.getServerSapfor().version; target.sapfor_build_date = Current.getServerSapfor().buildDate; //-- target.testsNames = String.join(";", testsNames_lower); target.StartDate = new Date().getTime(); target.kernels = Global.properties.TestingKernels; target.state = TasksPackageState.Queued; target.needsEmail = Global.properties.EmailOnTestingProgress ? 1 : 0; //--- Vector packages = new Vector<>(); packages.add(target); Command(new ServerExchangeUnit_2021(ServerCode.PublishAccountObjects, Current.getAccount().email, packages)); } @Override protected void performDone() throws Exception { passes.get(PassCode_2021.SynchronizeTestsTasks).Do(); /* if (!TestingServer.checkTasks) TestingServer.TimerOn(); */ } @Override protected void showDone() throws Exception { server.account_db.sapforTasksPackages.ui_.Select(target.id); // UI.getMainWindow().getTestingWindow().ShowAutoActualizeTestsState(); } }