Skip to content

Commit 325f02c

Browse files
committed
refactoring
1 parent 66f5daf commit 325f02c

2,144 files changed

Lines changed: 40532 additions & 5362 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CMakePresets.json

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,101 @@
491491
}
492492
}
493493
},
494+
{
495+
"name": "windows-release-module-acceleration",
496+
"displayName": "Test: Windows x64 Release (Module: acceleration)",
497+
"configurePreset": "windows-release",
498+
"environment": {
499+
"PATH": "${sourceDir}/build-msvc-windows-release/bin${pathListSep}${sourceDir}/vcpkg_installed/x64-windows/bin${pathListSep}$penv{PATH}"
500+
},
501+
"output": {
502+
"outputOnFailure": true
503+
},
504+
"execution": {
505+
"noTestsAction": "error"
506+
},
507+
"filter": {
508+
"include": {
509+
"label": "^module:acceleration$"
510+
}
511+
}
512+
},
513+
{
514+
"name": "windows-release-module-query",
515+
"displayName": "Test: Windows x64 Release (Module: query)",
516+
"configurePreset": "windows-release",
517+
"environment": {
518+
"PATH": "${sourceDir}/build-msvc-windows-release/bin${pathListSep}${sourceDir}/vcpkg_installed/x64-windows/bin${pathListSep}$penv{PATH}"
519+
},
520+
"output": {
521+
"outputOnFailure": true
522+
},
523+
"execution": {
524+
"noTestsAction": "error"
525+
},
526+
"filter": {
527+
"include": {
528+
"label": "^module:query$"
529+
}
530+
}
531+
},
532+
{
533+
"name": "windows-release-module-transaction",
534+
"displayName": "Test: Windows x64 Release (Module: transaction)",
535+
"configurePreset": "windows-release",
536+
"environment": {
537+
"PATH": "${sourceDir}/build-msvc-windows-release/bin${pathListSep}${sourceDir}/vcpkg_installed/x64-windows/bin${pathListSep}$penv{PATH}"
538+
},
539+
"output": {
540+
"outputOnFailure": true
541+
},
542+
"execution": {
543+
"noTestsAction": "error"
544+
},
545+
"filter": {
546+
"include": {
547+
"label": "^module:transaction$"
548+
}
549+
}
550+
},
551+
{
552+
"name": "windows-release-module-utils",
553+
"displayName": "Test: Windows x64 Release (Module: utils)",
554+
"configurePreset": "windows-release",
555+
"environment": {
556+
"PATH": "${sourceDir}/build-msvc-windows-release/bin${pathListSep}${sourceDir}/vcpkg_installed/x64-windows/bin${pathListSep}$penv{PATH}"
557+
},
558+
"output": {
559+
"outputOnFailure": true
560+
},
561+
"execution": {
562+
"noTestsAction": "error"
563+
},
564+
"filter": {
565+
"include": {
566+
"label": "^module:utils$"
567+
}
568+
}
569+
},
570+
{
571+
"name": "windows-release-module-sharding",
572+
"displayName": "Test: Windows x64 Release (Module: sharding)",
573+
"configurePreset": "windows-release",
574+
"environment": {
575+
"PATH": "${sourceDir}/build-msvc-windows-release/bin${pathListSep}${sourceDir}/vcpkg_installed/x64-windows/bin${pathListSep}$penv{PATH}"
576+
},
577+
"output": {
578+
"outputOnFailure": true
579+
},
580+
"execution": {
581+
"noTestsAction": "error"
582+
},
583+
"filter": {
584+
"include": {
585+
"label": "^module:sharding$"
586+
}
587+
}
588+
},
494589
{
495590
"name": "windows-debug",
496591
"displayName": "Test: Windows x64 Debug",

scripts/migrate_tests_prefix.ps1

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
$ErrorActionPreference = 'Stop'
2+
3+
$testsRoot = 'C:/Projects/ThemisDB/tests'
4+
$rootFiles = Get-ChildItem $testsRoot -File -Filter 'test_*.cpp'
5+
6+
$createdDirs = New-Object System.Collections.Generic.HashSet[string]
7+
$createdCmake = New-Object System.Collections.Generic.HashSet[string]
8+
$patchedCmake = New-Object System.Collections.Generic.HashSet[string]
9+
$moved = 0
10+
11+
function New-ModuleCMake {
12+
param(
13+
[string]$Module,
14+
[string]$FilePath
15+
)
16+
17+
$upper = ($Module.ToUpper() -replace '[^A-Z0-9]', '_')
18+
$content = @"
19+
# Auto-generated module tests for prefix '$Module'
20+
21+
file(GLOB ${upper}_PREFIX_TEST_SOURCES
22+
"`$`{CMAKE_CURRENT_SOURCE_DIR}/test_${Module}_*.cpp"
23+
)
24+
25+
foreach(_src IN LISTS ${upper}_PREFIX_TEST_SOURCES)
26+
get_filename_component(_stem "`$`{_src}" NAME_WE)
27+
set(_target "module_${Module}_`$`{_stem}_focused")
28+
set(_ctest "`$`{_stem}_${Module}_FocusedTests")
29+
30+
if(TARGET `$`{_target})
31+
continue()
32+
endif()
33+
34+
add_executable(`$`{_target} "`$`{_src}")
35+
target_include_directories(`$`{_target} PRIVATE
36+
`$`{THEMIS_ROOT_DIR}/include
37+
`$`{THEMIS_ROOT_DIR}/src
38+
)
39+
target_link_libraries(`$`{_target} PRIVATE
40+
`$`{TEST_LIBS}
41+
themis_core
42+
spdlog::spdlog
43+
Threads::Threads
44+
)
45+
target_compile_definitions(`$`{_target} PRIVATE THEMIS_TEST_BUILD=1)
46+
47+
themis_register_module_focused_test(
48+
MODULE ${Module}
49+
NAME `$`{_ctest}
50+
TARGET `$`{_target}
51+
TIER unit
52+
TIMEOUT 120
53+
LABELS ${Module}
54+
)
55+
endforeach()
56+
"@
57+
58+
$enc = New-Object System.Text.UTF8Encoding($false)
59+
[System.IO.File]::WriteAllText($FilePath, $content, $enc)
60+
}
61+
62+
function Ensure-PrefixBlock {
63+
param(
64+
[string]$Module,
65+
[string]$FilePath
66+
)
67+
68+
$marker = "# AUTOGEN PREFIX BLOCK: $Module"
69+
$text = [System.IO.File]::ReadAllText($FilePath)
70+
if ($text.Contains($marker)) {
71+
return $false
72+
}
73+
74+
$upper = ($Module.ToUpper() -replace '[^A-Z0-9]', '_')
75+
$append = @"
76+
77+
$marker
78+
file(GLOB ${upper}_AUTOGEN_PREFIX_TEST_SOURCES
79+
"`$`{CMAKE_CURRENT_SOURCE_DIR}/test_${Module}_*.cpp"
80+
)
81+
82+
foreach(_src IN LISTS ${upper}_AUTOGEN_PREFIX_TEST_SOURCES)
83+
get_filename_component(_stem "`$`{_src}" NAME_WE)
84+
set(_target "module_${Module}_`$`{_stem}_autofocused")
85+
set(_ctest "`$`{_stem}_${Module}_AutoFocusedTests")
86+
87+
if(TARGET `$`{_target})
88+
continue()
89+
endif()
90+
91+
add_executable(`$`{_target} "`$`{_src}")
92+
target_include_directories(`$`{_target} PRIVATE
93+
`$`{THEMIS_ROOT_DIR}/include
94+
`$`{THEMIS_ROOT_DIR}/src
95+
)
96+
target_link_libraries(`$`{_target} PRIVATE
97+
`$`{TEST_LIBS}
98+
themis_core
99+
spdlog::spdlog
100+
Threads::Threads
101+
)
102+
target_compile_definitions(`$`{_target} PRIVATE THEMIS_TEST_BUILD=1)
103+
104+
themis_register_module_focused_test(
105+
MODULE ${Module}
106+
NAME `$`{_ctest}
107+
TARGET `$`{_target}
108+
TIER unit
109+
TIMEOUT 120
110+
LABELS ${Module} autogen
111+
)
112+
endforeach()
113+
"@
114+
115+
$enc = New-Object System.Text.UTF8Encoding($false)
116+
[System.IO.File]::WriteAllText($FilePath, ($text + $append), $enc)
117+
return $true
118+
}
119+
120+
foreach ($f in $rootFiles) {
121+
$base = $f.BaseName -replace '^test_', ''
122+
$prefix = ($base -split '_')[0].ToLower()
123+
if ([string]::IsNullOrWhiteSpace($prefix)) {
124+
continue
125+
}
126+
127+
$dir = Join-Path $testsRoot $prefix
128+
if (-not (Test-Path $dir)) {
129+
New-Item -ItemType Directory -Path $dir | Out-Null
130+
$createdDirs.Add($prefix) | Out-Null
131+
}
132+
133+
$cmake = Join-Path $dir 'CMakeLists.txt'
134+
if (-not (Test-Path $cmake)) {
135+
New-ModuleCMake -Module $prefix -FilePath $cmake
136+
$createdCmake.Add($prefix) | Out-Null
137+
}
138+
else {
139+
if (Ensure-PrefixBlock -Module $prefix -FilePath $cmake) {
140+
$patchedCmake.Add($prefix) | Out-Null
141+
}
142+
}
143+
144+
$destPath = Join-Path $dir $f.Name
145+
if (Test-Path $destPath) {
146+
$srcHash = (Get-FileHash -Algorithm SHA256 -LiteralPath $f.FullName).Hash
147+
$dstHash = (Get-FileHash -Algorithm SHA256 -LiteralPath $destPath).Hash
148+
if ($srcHash -eq $dstHash) {
149+
Remove-Item -LiteralPath $f.FullName
150+
}
151+
else {
152+
$nameNoExt = [System.IO.Path]::GetFileNameWithoutExtension($f.Name)
153+
$ext = [System.IO.Path]::GetExtension($f.Name)
154+
$candidate = Join-Path $dir ("${nameNoExt}_root${ext}")
155+
$i = 1
156+
while (Test-Path $candidate) {
157+
$candidate = Join-Path $dir ("${nameNoExt}_root${i}${ext}")
158+
$i++
159+
}
160+
Move-Item -LiteralPath $f.FullName -Destination $candidate
161+
}
162+
}
163+
else {
164+
Move-Item -LiteralPath $f.FullName -Destination $destPath
165+
}
166+
$moved++
167+
}
168+
169+
Write-Output ('MOVED=' + $moved)
170+
Write-Output ('CREATED_DIRS=' + $createdDirs.Count)
171+
Write-Output ('CREATED_CMAKES=' + $createdCmake.Count)
172+
Write-Output ('PATCHED_CMAKES=' + $patchedCmake.Count)
173+
Write-Output ('ROOT_TEST_CPP_AFTER=' + ((Get-ChildItem $testsRoot -File -Filter 'test_*.cpp' | Measure-Object).Count))
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
$ErrorActionPreference = 'Stop'
2+
3+
$testsRoot = 'C:/Projects/ThemisDB/tests'
4+
$cmakePath = 'C:/Projects/ThemisDB/tests/CMakeLists.txt'
5+
6+
# Build map: file name -> first-level folder containing that file.
7+
$fileMap = @{}
8+
Get-ChildItem $testsRoot -Directory | ForEach-Object {
9+
$module = $_.Name
10+
Get-ChildItem $_.FullName -File -Filter 'test_*.cpp' -ErrorAction SilentlyContinue | ForEach-Object {
11+
$name = $_.Name
12+
if (-not $fileMap.ContainsKey($name)) {
13+
$fileMap[$name] = $module
14+
}
15+
}
16+
}
17+
18+
$text = [System.IO.File]::ReadAllText($cmakePath)
19+
20+
foreach ($entry in $fileMap.GetEnumerator()) {
21+
$name = $entry.Key
22+
$module = $entry.Value
23+
$newRel = "$module/$name"
24+
25+
$text = $text.Replace("`${CMAKE_CURRENT_SOURCE_DIR}/$name", "`${CMAKE_CURRENT_SOURCE_DIR}/$newRel")
26+
$text = $text.Replace("`${THEMIS_ROOT_DIR}/tests/$name", "`${THEMIS_ROOT_DIR}/tests/$newRel")
27+
}
28+
29+
# Rewrite lines that contain only a bare test source token.
30+
$text = [regex]::Replace(
31+
$text,
32+
'(?m)^(\s+)(test_[A-Za-z0-9_]+\.cpp)(\s*)$',
33+
{
34+
param($m)
35+
$indent = $m.Groups[1].Value
36+
$name = $m.Groups[2].Value
37+
$trail = $m.Groups[3].Value
38+
if ($fileMap.ContainsKey($name)) {
39+
return "$indent$($fileMap[$name])/$name$trail"
40+
}
41+
return $m.Value
42+
}
43+
)
44+
45+
# Rewrite bare filename tokens (e.g. add_executable(foo test_bar.cpp))
46+
# while keeping already-qualified paths untouched.
47+
$text = [regex]::Replace(
48+
$text,
49+
'(?<![A-Za-z0-9_./-])(test_[A-Za-z0-9_]+\.cpp)(?![A-Za-z0-9_./-])',
50+
{
51+
param($m)
52+
$name = $m.Groups[1].Value
53+
if ($fileMap.ContainsKey($name)) {
54+
return "$($fileMap[$name])/$name"
55+
}
56+
return $name
57+
}
58+
)
59+
60+
$enc = New-Object System.Text.UTF8Encoding($false)
61+
[System.IO.File]::WriteAllText($cmakePath, $text, $enc)
62+
Write-Output 'Rewrote tests/CMakeLists.txt source paths to modular locations.'

src/metadata/distributed_catalog.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ bool DistributedMetadataCatalog::removeSchema(const std::string& table_name)
8282
return false;
8383
}
8484

85+
if (!router_.get(themisdb::sharding::MetadataPartitionKey::SCHEMA, table_name).has_value()) {
86+
return false;
87+
}
88+
8589
bool ok = router_.remove(
8690
themisdb::sharding::MetadataPartitionKey::SCHEMA,
8791
table_name);

0 commit comments

Comments
 (0)