Skip to content
Snippets Groups Projects
Commit eccfd3e3 authored by Sergey Yakubov's avatar Sergey Yakubov
Browse files

continue with event monitor producer

parent ef85e2dc
No related branches found
No related tags found
No related merge requests found
Showing
with 180 additions and 19 deletions
set(TARGET_NAME event-monitor-producer)
set(SOURCE_FILES
src/event_detector.cpp
src/eventmon_config.cpp
src/eventmon_logger.cpp
src/event_detector_factory.cpp
src/inotify_event_detector.cpp)
src/folder_event_detector.cpp
)
IF(WIN32)
set(SOURCE_FILES ${SOURCE_FILES} src/system_folder_watch_windows.cpp)
ELSEIF(UNIX)
set(SOURCE_FILES ${SOURCE_FILES} src/system_folder_watch_linux.cpp)
ENDIF(WIN32)
################################
......@@ -43,6 +50,7 @@ set(TEST_SOURCE_FILES
unittests/test_eventmon_config.cpp
unittests/mock_eventmon_config.cpp
unittests/test_event_detector_factory.cpp
unittests/test_folder_event_detector.cpp
)
set(TEST_LIBRARIES "${TARGET_NAME}")
......
#include "event_detector_factory.h"
#include "eventmon_config.h"
#include "inotify_event_detector.h"
#include "folder_event_detector.h"
namespace asapo {
EventDetector EventDetectorFactory::CreateEventDetector() {
auto config = GetEventMonConfig();
return EventDetector{new InotifyEventDetector(config)};
return EventDetector{new FolderEventDetector(config)};
}
}
\ No newline at end of file
#include "folder_event_detector.h"
#include "io/io_factory.h"
#include "eventmon_logger.h"
namespace asapo {
Error FolderEventDetector::GetNextEvent(EventHeader* event_header) {
return nullptr;
}
FolderEventDetector::FolderEventDetector(const EventMonConfig* config) : system_folder_watch__{new SystemFolderWatch()},
log__{GetDefaultEventMonLogger()}, config_{config}{
}
}
\ No newline at end of file
......@@ -3,13 +3,19 @@
#include "event_detector.h"
#include "eventmon_config.h"
#include "io/io.h"
#include "logger/logger.h"
#include "system_folder_watch.h"
namespace asapo {
class InotifyEventDetector : public AbstractEventDetector {
class FolderEventDetector : public AbstractEventDetector {
public:
Error GetNextEvent(EventHeader* event_header) override;
InotifyEventDetector(const EventMonConfig* config);
FolderEventDetector(const EventMonConfig* config);
std::unique_ptr<SystemFolderWatch> system_folder_watch__;
const AbstractLogger* log__;
private:
const EventMonConfig* config_;
};
......
#include "inotify_event_detector.h"
namespace asapo {
Error InotifyEventDetector::GetNextEvent(EventHeader* event_header) {
return nullptr;
}
InotifyEventDetector::InotifyEventDetector(const EventMonConfig* config) : config_{config} {
}
}
\ No newline at end of file
#ifndef ASAPO_SYSTEM_FODLER_WATCH_H
#define ASAPO_SYSTEM_FODLER_WATCH_H
#ifdef _WIN32
#include "system_folder_watch_windows.h"
#endif
#if defined(__linux__) || defined (__APPLE__)
#include "system_folder_watch_linux.h"
#endif
#endif //ASAPO_SYSTEM_FODLER_WATCH_H
#include "event_detector.h"
#include "system_folder_watch_linux.h"
namespace asapo {
......
#ifndef ASAPO_SYSTEM_FOLDER_WATCH_LINUX_H
#define ASAPO_SYSTEM_FOLDER_WATCH_LINUX_H
namespace asapo {
class SystemFolderWatch {
};
}
#endif //ASAPO_SYSTEM_FOLDER_WATCH_LINUX_H
#include "system_folder_watch_linux.h"
namespace asapo {
}
\ No newline at end of file
#ifndef ASAPO_SYSTEM_FOLDER_WATCH_WINDOWS_H
#define ASAPO_SYSTEM_FOLDER_WATCH_WINDOWS_H
namespace asapo {
class SystemFolderWatch {
};
}
#endif //ASAPO_SYSTEM_FOLDER_WATCH_WINDOWS_H
#ifndef ASAPO_MOCKSYSTEMFOLDERWATCH_H
#define ASAPO_MOCKSYSTEMFOLDERWATCH_H
#include <gtest/gtest.h>
#include <gmock/gmock.h>
#include "../src/system_folder_watch.h"
namespace asapo {
class MockSystemFolderWatch : public SystemFolderWatch {
};
}
#endif //ASAPO_MOCKSYSTEMFOLDERWATCH_H
......@@ -4,7 +4,7 @@
#include "eventmon_mocking.h"
#include "mock_eventmon_config.h"
#include "../src/event_detector_factory.h"
#include "../src/inotify_event_detector.h"
#include "../src/folder_event_detector.h"
using ::testing::Test;
using ::testing::_;
......@@ -34,7 +34,7 @@ class FactoryTests : public Test {
TEST_F(FactoryTests, CreateDetector) {
auto event_detector = factory.CreateEventDetector();
ASSERT_THAT(dynamic_cast<asapo::InotifyEventDetector*>(event_detector.get()), Ne(nullptr));
ASSERT_THAT(dynamic_cast<asapo::FolderEventDetector*>(event_detector.get()), Ne(nullptr));
}
}
#include <gtest/gtest.h>
#include <gmock/gmock.h>
#include "../src/folder_event_detector.h"
#include "unittests/MockIO.h"
#include "unittests/MockLogger.h"
#include "MockSystemFolderWatch.h"
using ::testing::Return;
using ::testing::_;
using ::testing::DoAll;
using ::testing::SetArgReferee;
using ::testing::SetArgPointee;
using ::testing::Gt;
using ::testing::Eq;
using ::testing::Ne;
using ::testing::Mock;
using ::testing::InSequence;
using ::testing::HasSubstr;
using ::asapo::Error;
using ::asapo::FileDescriptor;
using ::asapo::ErrorInterface;
using asapo::FolderEventDetector;
namespace {
TEST(FolderEventDetector, Constructor) {
asapo::EventMonConfig test_config;
FolderEventDetector detector{&test_config};
ASSERT_THAT(dynamic_cast<asapo::SystemFolderWatch*>(detector.system_folder_watch__.get()), Ne(nullptr));
}
class FolderEventDetectorTests : public testing::Test {
public:
Error err;
::testing::NiceMock<asapo::MockLogger> mock_logger;
::testing::NiceMock<asapo::MockSystemFolderWatch> mock_system_folder_watch;
asapo::EventMonConfig test_config;
FolderEventDetector detector{&test_config};
std::vector<std::string> expected_folders{"test1","test2"};
void SetUp() override {
// test_config.expected_folders = expected_folders;
err = nullptr;
detector.system_folder_watch__ = std::unique_ptr<asapo::SystemFolderWatch> {&mock_system_folder_watch};
detector.log__ = &mock_logger;
}
void TearDown() override {
detector.system_folder_watch__.release();
}
};
TEST_F(FolderEventDetectorTests, GetNextEventCallsGetFolderEvents) {
// EXPECT_CALL(mock_system_folder_watch, StartFolderMonitor_t(expected_folders, receiver.kMaxUnacceptedConnectionsBacklog, _))
// .WillOnce(DoAll(
// SetArgPointee<2>(asapo::IOErrorTemplates::kUnknownIOError.Generate().release()),
// Return(0)
// ));
//EXPECT_CALL(mock_logger, Error(HasSubstr("prepare listener")));
// ASSERT_THAT(err, Eq(asapo::IOErrorTemplates::kUnknownIOError));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment