Skip to content

Commit

Permalink
Add method to update Group ID of BER (#347)
Browse files Browse the repository at this point in the history
ber: add method to update group id
  • Loading branch information
csegarragonz authored Aug 4, 2023
1 parent ccf99e8 commit 957ae10
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
3 changes: 3 additions & 0 deletions include/faabric/util/batch.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ std::shared_ptr<faabric::BatchExecuteRequest> batchExecFactory(

bool isBatchExecRequestValid(std::shared_ptr<faabric::BatchExecuteRequest> ber);

void updateBatchExecGroupId(std::shared_ptr<faabric::BatchExecuteRequest> ber,
int newGroupId);

// ----------
// Batch Execute Requests' Status
// ----------
Expand Down
12 changes: 12 additions & 0 deletions src/util/batch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,18 @@ bool isBatchExecRequestValid(std::shared_ptr<faabric::BatchExecuteRequest> ber)
return true;
}

void updateBatchExecGroupId(std::shared_ptr<faabric::BatchExecuteRequest> ber,
int newGroupId)
{
ber->set_groupid(newGroupId);
for (auto msg : *ber->mutable_messages()) {
msg.set_groupid(newGroupId);
}

// Sanity-check in debug mode
assert(isBatchExecRequestValid(ber));
}

std::shared_ptr<faabric::BatchExecuteRequestStatus> batchExecStatusFactory(
int32_t appId)
{
Expand Down
15 changes: 15 additions & 0 deletions tests/test/util/test_batch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,21 @@ TEST_CASE("Test batch. exec request sanity checks")
REQUIRE(isBerValid == isBatchExecRequestValid(ber));
}

TEST_CASE("Test updating the group ID of a BER")
{
int nMessages = 4;
std::shared_ptr<faabric::BatchExecuteRequest> ber =
batchExecFactory("demo", "echo", nMessages);

// By default the BER is valid
REQUIRE(isBatchExecRequestValid(ber));

int newGroupId = 1337;
updateBatchExecGroupId(ber, newGroupId);
REQUIRE(isBatchExecRequestValid(ber));
REQUIRE(ber->groupid() == newGroupId);
}

TEST_CASE("Test BER status factory")
{
int appId;
Expand Down

0 comments on commit 957ae10

Please sign in to comment.