Skip to content

Commit

Permalink
fix: change to a correct use of clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
LucioDonda committed Jul 22, 2024
1 parent ef772ac commit 7f23e17
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 39 deletions.
5 changes: 3 additions & 2 deletions src/agent/queue/include/persistence.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#define PERSISTENCE_H

#include <nlohmann/json.hpp>
#include <vector>
#include <string>
#include <vector>

using json = nlohmann::json;

Expand All @@ -12,7 +12,8 @@ using json = nlohmann::json;
*
* This interface defines methods for storing, retrieving, and removing JSON messages.
*/
class Persistence {
class Persistence
{
public:
/**
* @brief Virtual destructor.
Expand Down
1 change: 0 additions & 1 deletion src/agent/queue/include/queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ class PersistedQueue
* @throws None
*/
void waitUntilNotFullOrStoped(std::stop_token stopToken);

};

/**
Expand Down
2 changes: 1 addition & 1 deletion src/agent/queue/include/shared.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <nlohmann/json.hpp>

//TODO: should be moved to Config
// TODO: should be moved to Config
constexpr char DEFAULT_FILE_PATH[] = "/home/vagrant/FILE_";
constexpr char DEFAULT_DB_PATH[] = "queue.db";

Expand Down
12 changes: 2 additions & 10 deletions src/agent/queue/src/queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,7 @@ bool PersistedQueue::isFull()
void PersistedQueue::waitUntilNotFull()
{
std::unique_lock<std::mutex> lock(m_mtx);
m_cv.wait_for(lock,
m_timeout,
[this]
{
std::cout << " waiting " << std::endl;
return m_persistenceDest->GetElementCount() < m_max_size;
});
m_cv.wait_for(lock, m_timeout, [this] { return m_persistenceDest->GetElementCount() < m_max_size; });
}

void PersistedQueue::waitUntilNotFullOrStoped(std::stop_token stopToken)
Expand All @@ -105,15 +99,13 @@ void PersistedQueue::waitUntilNotFullOrStoped(std::stop_token stopToken)
m_cv.wait(lock,
[this, stopToken]
{
std::cout << " waiting " << std::endl;
bool menor = (m_persistenceDest->GetElementCount() < m_max_size);
bool stopped = (stopToken.stop_possible() && stopToken.stop_requested());
std::cout << "menor" << menor << "stopped" << stopped << std::endl;
return menor || stopped;
});
}

bool MultiTypeQueue::timeoutPush(Message message, bool shouldWait )
bool MultiTypeQueue::timeoutPush(Message message, bool shouldWait)
{
bool result = false;
std::unique_lock<std::mutex> mapLock(m_mapMutex);
Expand Down
3 changes: 2 additions & 1 deletion src/agent/queue/tests/main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <gtest/gtest.h>

int main(int argc, char** argv) {
int main(int argc, char** argv)
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
20 changes: 9 additions & 11 deletions src/agent/queue/tests/queue_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ TEST_F(JsonTest, JSONArrays)
int i = 0;
for (auto& singleMessage : multipleDataContent.items())
{
EXPECT_EQ(singleMessage.value(),"content " + std::to_string(++i));
EXPECT_EQ(singleMessage.value(), "content " + std::to_string(++i));
}
}

Expand Down Expand Up @@ -205,7 +205,7 @@ TEST_F(QueueTest, SinglePushPopFullWithTimeout)

const json dataContent = R"({"Data" : "for COMMAND3"})";
Message exampleMessage {messageType, dataContent};
queue.timeoutPush({messageType, dataContent},true);
queue.timeoutPush({messageType, dataContent}, true);

auto items = queue.getItemsByType(MessageType::COMMAND);
EXPECT_EQ(items, SMALL_QUEUE_QTTY);
Expand Down Expand Up @@ -256,17 +256,16 @@ TEST_F(QueueTest, MultithreadDifferentType)
std::thread consumerThread1(consumerStateLess, std::ref(itemsToConsume));
std::thread consumerThread2(consumerStateFull, std::ref(itemsToConsume));

if(consumerThread1.joinable())
if (consumerThread1.joinable())
{
consumerThread1.join();
}

if(consumerThread2.joinable())
if (consumerThread2.joinable())
{
consumerThread2.join();
}


EXPECT_NE(0, queue.getItemsByType(MessageType::STATELESS));
EXPECT_NE(0, queue.getItemsByType(MessageType::STATEFUL));
EXPECT_FALSE(queue.isEmptyByType(MessageType::STATELESS));
Expand All @@ -276,17 +275,16 @@ TEST_F(QueueTest, MultithreadDifferentType)
std::thread consumerThread12(consumerStateLess, std::ref(itemsToConsume));
std::thread consumerThread22(consumerStateFull, std::ref(itemsToConsume));

if(consumerThread12.joinable())
if (consumerThread12.joinable())
{
consumerThread12.join();
}

if(consumerThread22.joinable())
if (consumerThread22.joinable())
{
consumerThread22.join();
}


// FIXME: this doesn't match
EXPECT_EQ(0, queue.getItemsByType(MessageType::STATELESS));
EXPECT_EQ(0, queue.getItemsByType(MessageType::STATEFUL));
Expand Down Expand Up @@ -334,12 +332,12 @@ TEST_F(QueueTest, MultithreadSameType)
std::thread consumerThread1(consumerCommand1, std::ref(itemsToConsume));
std::thread messageProducerThread1(consumerCommand2, std::ref(itemsToConsume));

if(messageProducerThread1.joinable())
if (messageProducerThread1.joinable())
{
messageProducerThread1.join();
}

if(consumerThread1.joinable())
if (consumerThread1.joinable())
{
consumerThread1.join();
}
Expand Down Expand Up @@ -383,5 +381,5 @@ TEST_F(QueueTest, MultiplePushSeveralMultiplePops)

EXPECT_TRUE(queue.popNMessages(MessageType::STATELESS, 3));
EXPECT_TRUE(queue.isEmptyByType(MessageType::STATELESS));
EXPECT_EQ(0,queue.getItemsByType(MessageType::STATELESS));
EXPECT_EQ(0, queue.getItemsByType(MessageType::STATELESS));
}
24 changes: 11 additions & 13 deletions src/agent/queue/tests/queue_test.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,27 @@
*/
#ifndef _QUEUE_TEST_H
#define _QUEUE_TEST_H
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"

class QueueTest : public ::testing::Test
{
protected:
protected:
QueueTest() = default;
virtual ~QueueTest() = default;

QueueTest() = default;
virtual ~QueueTest() = default;

void SetUp() override;
void TearDown() override;
void SetUp() override;
void TearDown() override;
};

class JsonTest : public ::testing::Test
{
protected:

JsonTest() = default;
virtual ~JsonTest() = default;
protected:
JsonTest() = default;
virtual ~JsonTest() = default;

void SetUp() override {};
void TearDown() override {};
void SetUp() override {};
void TearDown() override {};
};

#endif //_QUEUE_TEST_H

0 comments on commit 7f23e17

Please sign in to comment.