Skip to content

Commit

Permalink
add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
a114j0y committed Oct 30, 2024
1 parent 8a610ff commit 1891c61
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions tests/redis_piped_state_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -730,3 +730,57 @@ TEST(ConsumerStateTable, async_multitable)

cout << endl << "Done." << endl;
}

TEST(ConsumerStateTable, flushPub)
{
clearDB();

/* Prepare producer */
int index = 0;
string tableName = "UT_REDIS_THREAD_" + to_string(index);
DBConnector db(TEST_DB, 0, true);
RedisPipeline pipeline(&db);
ProducerStateTable p(&pipeline, tableName, true, true);
string key = "TheKey";
int maxNumOfFields = 2;

/* Set operation */
{
vector<FieldValueTuple> fields;
for (int j = 0; j < maxNumOfFields; j++)
{
FieldValueTuple t(field(j), value(j));
fields.push_back(t);
}
p.set(key, fields);
}

/* Del operation */
p.del(key);
p.flush();

/* Prepare consumer */
ConsumerStateTable c(&db, tableName);
Select cs;
Selectable *selectcs;
cs.addSelectable(&c);

/* First pop operation */
{
int ret = cs.select(&selectcs);
EXPECT_EQ(ret, Select::OBJECT);
KeyOpFieldsValuesTuple kco;
c.pop(kco);
EXPECT_EQ(kfvKey(kco), key);
EXPECT_EQ(kfvOp(kco), "DEL");

auto fvs = kfvFieldsValues(kco);
EXPECT_EQ(fvs.size(), 0U);
}

/* Second select operation */
{
int ret = cs.select(&selectcs, 1000);
EXPECT_EQ(ret, Select::TIMEOUT);
}
}

0 comments on commit 1891c61

Please sign in to comment.