Skip to content

Commit

Permalink
adding prune exclude jobiids tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alaaeddineelamri committed Sep 12, 2022
1 parent b5a0325 commit 50c1fe3
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 2 deletions.
7 changes: 5 additions & 2 deletions core/src/dird/ua_prune.h
Expand Up @@ -23,6 +23,7 @@
#define BAREOS_DIRD_UA_PRUNE_H_

#include "dird/ua.h"
#include "cats/cats.h"

namespace directordaemon {

Expand All @@ -34,8 +35,10 @@ bool PruneVolume(UaContext* ua, MediaDbRecord* mr);
int JobDeleteHandler(void* ctx, int num_fields, char** row);
int DelCountHandler(void* ctx, int num_fields, char** row);
int FileDeleteHandler(void* ctx, int num_fields, char** row);
int GetPruneListForVolume(UaContext* ua, MediaDbRecord* mr, std::vector<JobId_t> &del);
int ExcludeRunningJobsFromList(std::vector<JobId_t> &prune_list);
int GetPruneListForVolume(UaContext* ua,
MediaDbRecord* mr,
std::vector<JobId_t>& del);
int ExcludeRunningJobsFromList(std::vector<JobId_t>& prune_list);

} /* namespace directordaemon */
#endif // BAREOS_DIRD_UA_PRUNE_H_
3 changes: 3 additions & 0 deletions core/src/tests/CMakeLists.txt
Expand Up @@ -213,6 +213,9 @@ if(NOT client-only)
LINK_LIBRARIES ${LINK_LIBRARIES}
)

bareos_add_test(
pruning LINK_LIBRARIES testing_common GTest::gtest_main
)
bareos_add_test(
runjob LINK_LIBRARIES dird_objects bareosfind bareossql GTest::gtest_main
)
Expand Down
@@ -0,0 +1,4 @@
Director {
Name = bareos-dir
Password = "bareos"
}
7 changes: 7 additions & 0 deletions core/src/tests/configs/pruning/bareos-dir.d/storage/File.conf
@@ -0,0 +1,7 @@
Storage {
Name = File
Address = localhost
Password = ""
Device = FileStorage
Media Type = File
}
49 changes: 49 additions & 0 deletions core/src/tests/pruning.cc
@@ -0,0 +1,49 @@
/*
BAREOS® - Backup Archiving REcovery Open Sourced
Copyright (C) 2022-2022 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
License as published by the Free Software Foundation and included
in the file LICENSE.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/

#include "testing_dir_common.h"

#include "include/jcr.h"
#include "dird/job.h"
#include "dird/ua_prune.h"

TEST(Pruning, ExcludeRunningJobsFromList)
{
std::string path_to_config
= std::string(RELATIVE_PROJECT_SOURCE_DIR "/configs/pruning/");
PConfigParser director_config(DirectorPrepareResources(path_to_config));
if (!director_config) { return; }

JobControlRecord* jcr1 = directordaemon::NewDirectorJcr();
jcr1->JobId = 1;
JobControlRecord* jcr2 = directordaemon::NewDirectorJcr();
jcr2->JobId = 2;
JobControlRecord* jcr3 = directordaemon::NewDirectorJcr();
jcr3->JobId = 3;

std::vector<JobId_t> pruninglist{1, 2, 3, 4, 5};
int NumJobsToBePruned
= directordaemon::ExcludeRunningJobsFromList(pruninglist);

EXPECT_EQ(NumJobsToBePruned, 2);
EXPECT_EQ(pruninglist[0], 4);
EXPECT_EQ(pruninglist[1], 5);
}

0 comments on commit 50c1fe3

Please sign in to comment.