Skip to content

Commit

Permalink
Add method to update app ID of BER (#349)
Browse files Browse the repository at this point in the history
* batch: update app id

* tests: add test to update batch app id
  • Loading branch information
csegarragonz authored Aug 7, 2023
1 parent c725c04 commit aeb972d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 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 updateBatchExecAppId(std::shared_ptr<faabric::BatchExecuteRequest> ber,
int newAppId);

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

Expand Down
16 changes: 14 additions & 2 deletions src/util/batch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,24 @@ bool isBatchExecRequestValid(std::shared_ptr<faabric::BatchExecuteRequest> ber)
return true;
}

void updateBatchExecAppId(std::shared_ptr<faabric::BatchExecuteRequest> ber,
int newAppId)
{
ber->set_appid(newAppId);
for (int i = 0; i < ber->messages_size(); i++) {
ber->mutable_messages(i)->set_appid(newAppId);
}

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

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

// Sanity-check in debug mode
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 app 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 newAppId = 1337;
updateBatchExecAppId(ber, newAppId);
REQUIRE(isBatchExecRequestValid(ber));
REQUIRE(ber->appid() == newAppId);
}

TEST_CASE("Test updating the group ID of a BER")
{
int nMessages = 4;
Expand Down

0 comments on commit aeb972d

Please sign in to comment.